Skip to content

Commit 9970d1a

Browse files
committed
arrays
1 parent 7613fa8 commit 9970d1a

File tree

7 files changed

+342
-200
lines changed

7 files changed

+342
-200
lines changed

README.md

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,34 @@ The generated JSON-parser uses `org.json:json`.
2626
import io.github.danthe1st.json_compile.api.GenerateJSON;
2727
@GenerateJSON
2828
public class TestClass {
29-
private int privVal;
30-
public String pubVal;
31-
32-
public int getProp() {
33-
return privVal;
34-
}
35-
public void setProp(int i) {
36-
this.privVal=i;
37-
}
29+
public int someInt;
30+
private String someString;
31+
private int[][] someArray;
32+
33+
public String getSomeString() {
34+
return someString;
35+
}
36+
37+
public void setSomeString(String someString) {
38+
this.someString = someString;
39+
}
40+
41+
public int[][] getSomeArray() {
42+
return someArray;
43+
}
44+
45+
public void setSomeArray(int[][] someArray) {
46+
this.someArray = someArray;
47+
}
48+
49+
@Override
50+
public String toString() {
51+
return "TestClass{" +
52+
"someInt=" + someInt +
53+
", someString='" + someString + '\'' +
54+
", someArray=" + Arrays.deepToString(someArray) +
55+
'}';
56+
}
3857
}
3958
```
4059
* When compiling the class, a class suffixed with `JSONLoader` should be automatically generated.<br/>
@@ -46,6 +65,7 @@ System.out.println(obj);
4665
TestClass testObj=new TestClass();
4766
testObj.setSomeString("test");
4867
testObj.someInt=12345;
68+
testObj.someArray=new int[][]{{1,2,3},{},null,{1,2,3,4,5,6}};
4969
System.out.println(TestClassJSONLoader.toJSON(testObj));
5070
```
5171

@@ -62,6 +82,7 @@ An example project can be found in the directory `examples/maven-example`.
6282

6383
### Limitations
6484

65-
* Currently, the only supported data types are `int` and `String`.
85+
* Currently, the only supported data types `String`, `int`, objects and arrays.
86+
* Generics are not supported in any way
6687
* Eclipse may not detect the annotation processor
6788
* Compile-time JSON-parser is not yet published to maven central so you will have to build it by yourself.

examples/maven-example/src/main/java/io/github/danthe1st/json_compile/test/TestClass.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.nio.file.Files;
55
import java.nio.file.Path;
6+
import java.util.Arrays;
67

78
import org.json.JSONObject;
89

@@ -14,6 +15,8 @@ public class TestClass {
1415
public int someInt;
1516

1617
private String someString;
18+
19+
private int[][] someArray;
1720

1821
public String getSomeString() {
1922
return someString;
@@ -23,10 +26,21 @@ public void setSomeString(String someString) {
2326
this.someString = someString;
2427
}
2528

29+
public int[][] getSomeArray() {
30+
return someArray;
31+
}
32+
33+
public void setSomeArray(int[][] someArray) {
34+
this.someArray = someArray;
35+
}
2636

2737
@Override
2838
public String toString() {
29-
return "TestClass [someInt=" + someInt + ", someString=" + someString + "]";
39+
return "TestClass{" +
40+
"someInt=" + someInt +
41+
", someString='" + someString + '\'' +
42+
", someArray=" + Arrays.deepToString(someArray) +
43+
'}';
3044
}
3145

3246
public static void main(String[] args) throws IOException {
@@ -36,6 +50,7 @@ public static void main(String[] args) throws IOException {
3650
TestClass testObj=new TestClass();
3751
testObj.setSomeString("test");
3852
testObj.someInt=12345;
53+
testObj.someArray=new int[][]{{1,2,3},{},null,{1,2,3,4,5,6}};
3954
System.out.println(TestClassJSONLoader.toJSON(testObj));
4055
}
4156
}
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{
2-
"someInt":123,
3-
"someString":"Hello World"
4-
}
2+
"someInt": 123,
3+
"someString": "Hello World",
4+
"someArray": [
5+
[1,2,3,4,5],
6+
[-1,-1337],
7+
[],
8+
null
9+
]
10+
}

src/main/java/io/github/danthe1st/json_compile/impl/ClassWriter.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,34 @@ public void beginIf(String condition) throws IOException {
169169
public void endIf() throws IOException {
170170
endBlock();
171171
}
172+
173+
public void beginSimpleFor(String init,String condition,String advancement) throws IOException{
174+
writer.write("for (");
175+
writer.write(init);
176+
writer.write("; ");
177+
writer.write(condition);
178+
writer.write("; ");
179+
writer.write(advancement);
180+
writer.write(")");
181+
beginBlock();
182+
}
183+
184+
public void endFor() throws IOException{
185+
endBlock();
186+
}
172187

173188
private void endStatement() throws IOException {
174189
writer.write(";");
175190
nextLine();
176191
}
177192
//endregion
178193

179-
private void beginBlock() throws IOException {
194+
public void beginBlock() throws IOException {
180195
writer.write("{");
181196
indentation++;
182197
nextLine();
183198
}
184-
private void endBlock() throws IOException {
199+
public void endBlock() throws IOException {
185200
writer.write("}");
186201
indentation--;
187202
nextLine();

0 commit comments

Comments
 (0)