Skip to content

Commit a8dc37c

Browse files
committed
Merge branch 'release/0.5.0'
2 parents 4f00e0f + 32a051a commit a8dc37c

File tree

13 files changed

+347
-54
lines changed

13 files changed

+347
-54
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ target
1717

1818
pom.xml.releaseBackup
1919
release.properties
20+
build
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## How to debug
2+
3+
### Main class
4+
com.sun.tools.javac.Main
5+
6+
### Classpath
7+
/usr/lib/jvm/java-8-openjdk-amd64/lib/tools.jar
8+
9+
### Program argments
10+
-processor net.cattaka.util.cathandsgendroid.apt.CatHandsGendroidProcessor -s build/java -d build/classes -sourcepath src/test/java/ src/test/java/net/cattaka/util/cathandsgendroid/test/model/FullModel.java

cathandsgendroid-apt/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<parent>
1515
<groupId>net.cattaka</groupId>
1616
<artifactId>cathandsgendroid-parent</artifactId>
17-
<version>0.4.5-SNAPSHOT</version>
17+
<version>0.5.1-SNAPSHOT</version>
1818
<relativePath>../cathandsgendroid-parent</relativePath>
1919
</parent>
2020

cathandsgendroid-apt/src/main/java/net/cattaka/util/cathandsgendroid/apt/DataModelProcessor.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,7 @@ public InnerFieldType createInnerFieldType(VariableElement ve, TypeMirror tm, Da
450450
if (attr != null && !IAccessor.class.getName().equals(pickAccessor(attr))) {
451451
String accessorName = pickAccessor(attr);
452452
String dbDataType = pickDbDataType(accessorName);
453-
result = InnerFieldType.createCustomType(String.valueOf(tm), accessorName,
454-
dbDataType);
453+
result = InnerFieldType.createCustomType(tm, accessorName, dbDataType);
455454
} else if (tm.getKind() == TypeKind.DECLARED) {
456455
TypeElement te2 = (TypeElement)((DeclaredType)tm).asElement();
457456
//System.out.print(" : " + te2.getQualifiedName());
@@ -482,13 +481,13 @@ public InnerFieldType createInnerFieldType(VariableElement ve, TypeMirror tm, Da
482481
result = InnerFieldType.createListType(ift);
483482
}
484483
} else if (hasSuperclass((DeclaredType)tm, "java.lang.Enum")) {
485-
result = InnerFieldType.createCustomType(String.valueOf(te2.getQualifiedName()),
484+
result = InnerFieldType.createCustomType(tm,
486485
EnumNameAccessor.class.getName(), "TEXT");
487486
} else if (hasInterface((DeclaredType)tm, "java.io.Serializable")) {
488-
result = InnerFieldType.createCustomType(String.valueOf(te2.getQualifiedName()),
487+
result = InnerFieldType.createCustomType(tm,
489488
SerializableAccessor.class.getName(), "TEXT");
490489
} else if (hasInterface((DeclaredType)tm, "android.os.Parcelable")) {
491-
result = InnerFieldType.createCustomType(String.valueOf(te2.getQualifiedName()),
490+
result = InnerFieldType.createCustomType(tm,
492491
ParcelableAccessor.class.getName(), "TEXT");
493492
}
494493
} else if (tm.getKind() == TypeKind.ARRAY) {

cathandsgendroid-apt/src/main/java/net/cattaka/util/cathandsgendroid/apt/InnerFieldType.java

Lines changed: 93 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,55 @@
33

44
import java.util.Locale;
55

6+
import javax.lang.model.type.DeclaredType;
7+
import javax.lang.model.type.TypeMirror;
8+
9+
import net.cattaka.util.cathandsgendroid.apt.util.Functions;
10+
611
class InnerFieldType {
7-
public static final InnerFieldType BLOB = new InnerFieldType(false, false, "Accessors.BlobAccessor.createAccessor(byte[].class)", "BLOB", "byte[]", null);
8-
public static final InnerFieldType BOOLEAN = new InnerFieldType(false, false, "Accessors.BooleanAccessor.createAccessor(Boolean.class)", "INTEGER", "Boolean", null);
9-
public static final InnerFieldType BUNDLE = new InnerFieldType(false, false, "Accessors.BundleAccessor.createAccessor(Bundle.class)", "BLOB", "Bundle", null);
10-
public static final InnerFieldType BYTE = new InnerFieldType(false, true, "Accessors.ByteAccessor.createAccessor(Byte.class)", "INTEGER", "Byte", "byte");
11-
public static final InnerFieldType CHARACTER = new InnerFieldType(false, true, "Accessors.CharacterAccessor.createAccessor(Character.class)", "INTEGER", "Character", "char");
12-
public static final InnerFieldType DATE = new InnerFieldType(false, false, "Accessors.DateAccessor.createAccessor(java.util.Date.class)", "INTEGER", "java.util.Date", null);
13-
public static final InnerFieldType DOUBLE = new InnerFieldType(false, true, "Accessors.DoubleAccessor.createAccessor(Double.class)", "REAL", "Double", "double");
14-
public static final InnerFieldType FLOAT = new InnerFieldType(false, true, "Accessors.FloatAccessor.createAccessor(Float.class)", "REAL", "Float", "float");
15-
public static final InnerFieldType INTEGER = new InnerFieldType(false, true, "Accessors.IntegerAccessor.createAccessor(Integer.class)", "INTEGER", "Integer", "int");
16-
public static final InnerFieldType LONG = new InnerFieldType(false, true, "Accessors.LongAccessor.createAccessor(Long.class)", "INTEGER", "Long", "long");
17-
public static final InnerFieldType P_BOOLEAN = new InnerFieldType(true, false, "Accessors.PrimitiveBooleanAccessor.createAccessor(Boolean.class)", "INTEGER", "Boolean", null);
18-
public static final InnerFieldType P_BYTE = new InnerFieldType(true, true, "Accessors.PrimitiveByteAccessor.createAccessor(Byte.class)", "INTEGER", "Byte", "byte");
19-
public static final InnerFieldType P_CHARACTER = new InnerFieldType(true, true, "Accessors.PrimitiveCharacterAccessor.createAccessor(Character.class)", "INTEGER", "Character", "char");
20-
public static final InnerFieldType P_DOUBLE = new InnerFieldType(true, true, "Accessors.PrimitiveDoubleAccessor.createAccessor(Double.class)", "REAL", "Double", "double");
21-
public static final InnerFieldType P_FLOAT = new InnerFieldType(true, true, "Accessors.PrimitiveFloatAccessor.createAccessor(Float.class)", "REAL", "Float", "float");
22-
public static final InnerFieldType P_INTEGER = new InnerFieldType(true, true, "Accessors.PrimitiveIntegerAccessor.createAccessor(Integer.class)", "INTEGER", "Integer", "int");
23-
public static final InnerFieldType P_LONG = new InnerFieldType(true, true, "Accessors.PrimitiveLongAccessor.createAccessor(Long.class)", "INTEGER", "Long", "long");
24-
public static final InnerFieldType P_SHORT = new InnerFieldType(true, true, "Accessors.PrimitiveShortAccessor.createAccessor(Short.class)", "INTEGER", "Short", "short");
25-
public static final InnerFieldType PARCELABLE = new InnerFieldType(false, false, "Accessors.ParcelableAccessor.createAccessor(android.os.Parcelable.class)", "BLOB", "android.os.Parcelable", null);
26-
public static final InnerFieldType SHORT = new InnerFieldType(false, true, "Accessors.ShortAccessor.createAccessor(Short.class)", "INTEGER", "Short", "short");
27-
public static final InnerFieldType STRING = new InnerFieldType(false, false, "Accessors.StringAccessor.createAccessor(String.class)", "TEXT", "String", null);
12+
public static final InnerFieldType BLOB = new InnerFieldType(false, false,
13+
"Accessors.BlobAccessor.createAccessor(byte[].class)", "BLOB", "byte[]", null);
14+
public static final InnerFieldType BOOLEAN = new InnerFieldType(false, false,
15+
"Accessors.BooleanAccessor.createAccessor(Boolean.class)", "INTEGER", "Boolean", null);
16+
public static final InnerFieldType BUNDLE = new InnerFieldType(false, false,
17+
"Accessors.BundleAccessor.createAccessor(Bundle.class)", "BLOB", "Bundle", null);
18+
public static final InnerFieldType BYTE = new InnerFieldType(false, true,
19+
"Accessors.ByteAccessor.createAccessor(Byte.class)", "INTEGER", "Byte", "byte");
20+
public static final InnerFieldType CHARACTER = new InnerFieldType(false, true,
21+
"Accessors.CharacterAccessor.createAccessor(Character.class)", "INTEGER", "Character", "char");
22+
public static final InnerFieldType DATE = new InnerFieldType(false, false,
23+
"Accessors.DateAccessor.createAccessor(java.util.Date.class)", "INTEGER", "java.util.Date", null);
24+
public static final InnerFieldType DOUBLE = new InnerFieldType(false, true,
25+
"Accessors.DoubleAccessor.createAccessor(Double.class)", "REAL", "Double", "double");
26+
public static final InnerFieldType FLOAT = new InnerFieldType(false, true,
27+
"Accessors.FloatAccessor.createAccessor(Float.class)", "REAL", "Float", "float");
28+
public static final InnerFieldType INTEGER = new InnerFieldType(false, true,
29+
"Accessors.IntegerAccessor.createAccessor(Integer.class)", "INTEGER", "Integer", "int");
30+
public static final InnerFieldType LONG = new InnerFieldType(false, true,
31+
"Accessors.LongAccessor.createAccessor(Long.class)", "INTEGER", "Long", "long");
32+
public static final InnerFieldType P_BOOLEAN = new InnerFieldType(true, false,
33+
"Accessors.PrimitiveBooleanAccessor.createAccessor(Boolean.class)", "INTEGER", "Boolean", null);
34+
public static final InnerFieldType P_BYTE = new InnerFieldType(true, true,
35+
"Accessors.PrimitiveByteAccessor.createAccessor(Byte.class)", "INTEGER", "Byte", "byte");
36+
public static final InnerFieldType P_CHARACTER = new InnerFieldType(true, true,
37+
"Accessors.PrimitiveCharacterAccessor.createAccessor(Character.class)", "INTEGER", "Character", "char");
38+
public static final InnerFieldType P_DOUBLE = new InnerFieldType(true, true,
39+
"Accessors.PrimitiveDoubleAccessor.createAccessor(Double.class)", "REAL", "Double", "double");
40+
public static final InnerFieldType P_FLOAT = new InnerFieldType(true, true,
41+
"Accessors.PrimitiveFloatAccessor.createAccessor(Float.class)", "REAL", "Float", "float");
42+
public static final InnerFieldType P_INTEGER = new InnerFieldType(true, true,
43+
"Accessors.PrimitiveIntegerAccessor.createAccessor(Integer.class)", "INTEGER", "Integer", "int");
44+
public static final InnerFieldType P_LONG = new InnerFieldType(true, true,
45+
"Accessors.PrimitiveLongAccessor.createAccessor(Long.class)", "INTEGER", "Long", "long");
46+
public static final InnerFieldType P_SHORT = new InnerFieldType(true, true,
47+
"Accessors.PrimitiveShortAccessor.createAccessor(Short.class)", "INTEGER", "Short", "short");
48+
public static final InnerFieldType PARCELABLE = new InnerFieldType(false, false,
49+
"Accessors.ParcelableAccessor.createAccessor(android.os.Parcelable.class)", "BLOB", "android.os.Parcelable",
50+
null);
51+
public static final InnerFieldType SHORT = new InnerFieldType(false, true,
52+
"Accessors.ShortAccessor.createAccessor(Short.class)", "INTEGER", "Short", "short");
53+
public static final InnerFieldType STRING = new InnerFieldType(false, false,
54+
"Accessors.StringAccessor.createAccessor(String.class)", "TEXT", "String", null);
2855

2956
public final String accessor;
3057
public final String dbDataType;
@@ -34,31 +61,52 @@ class InnerFieldType {
3461
public final boolean primitiveType;
3562
public final boolean isNumber;
3663

37-
public InnerFieldType(boolean primitiveType, boolean isNumber, String accessor, String dbDataType, String javaDataType, String primitiveJavaDataType) {
38-
this(primitiveType, isNumber, accessor, dbDataType, javaDataType, javaDataType, primitiveJavaDataType);
39-
}
64+
public InnerFieldType(boolean primitiveType, boolean isNumber, String accessor, String dbDataType,
65+
String javaDataType, String primitiveJavaDataType) {
66+
this(primitiveType, isNumber, accessor, dbDataType, javaDataType, javaDataType, primitiveJavaDataType);
67+
}
68+
69+
private InnerFieldType(boolean primitiveType, boolean isNumber, String accessor, String dbDataType,
70+
String javaDataType, String origJavaDataType, String primitiveJavaDataType) {
71+
super();
72+
this.primitiveType = primitiveType;
73+
this.accessor = accessor;
74+
this.dbDataType = dbDataType;
75+
this.javaDataType = javaDataType;
76+
this.origJavaDataType = origJavaDataType;
77+
this.primitiveJavaDataType = (primitiveJavaDataType != null) ? primitiveJavaDataType : "(not supported)";
78+
this.isNumber = isNumber;
79+
}
80+
81+
public static InnerFieldType createCustomType(TypeMirror tm, String accessor, String dbDataType) {
82+
String javaDataType = String.valueOf(tm);
83+
String args;
84+
String typeParams;
85+
if (tm instanceof DeclaredType) {
86+
DeclaredType dt = (DeclaredType) tm;
87+
args = Functions.join(Functions.pullTypes(dt), ".class, ") + ".class";
88+
typeParams = "<" + String.valueOf(tm) + ">";
89+
} else {
90+
args = String.valueOf(tm) + ".class";
91+
typeParams = "";
92+
}
93+
94+
return new InnerFieldType(false, false,
95+
String.format(Locale.ROOT, accessor + ".%2$screateAccessor(%1$s)", args, typeParams), dbDataType,
96+
javaDataType, javaDataType, null);
97+
}
4098

41-
private InnerFieldType(boolean primitiveType, boolean isNumber,
42-
String accessor, String dbDataType, String javaDataType, String origJavaDataType, String primitiveJavaDataType) {
43-
super();
44-
this.primitiveType = primitiveType;
45-
this.accessor = accessor;
46-
this.dbDataType = dbDataType;
47-
this.javaDataType = javaDataType;
48-
this.origJavaDataType = origJavaDataType;
49-
this.primitiveJavaDataType = (primitiveJavaDataType != null) ? primitiveJavaDataType : "(not supported)";
50-
this.isNumber = isNumber;
51-
}
52-
53-
public static InnerFieldType createCustomType(String name, String accessor, String dbDataType) {
54-
return new InnerFieldType(false, false, String.format(Locale.ROOT, accessor + ".createAccessor(%1$s.class)", name), dbDataType, String.valueOf(name), String.valueOf(name), null);
99+
public static InnerFieldType createListType(InnerFieldType ift) {
100+
String javaDataType = String.format("java.util.List<%1$s>", ift.javaDataType);
101+
return new InnerFieldType(false, false,
102+
String.format(Locale.ROOT, "Accessors.createListAccessor(%1$s)", ift.accessor), "BLOB", javaDataType,
103+
null);
55104
}
56-
public static InnerFieldType createListType(InnerFieldType ift) {
57-
String javaDataType = String.format("java.util.List<%1$s>", ift.javaDataType);
58-
return new InnerFieldType(false, false, String.format(Locale.ROOT, "Accessors.createListAccessor(%1$s)", ift.accessor), "BLOB", javaDataType, null);
59-
}
60-
public static InnerFieldType createArrayType(InnerFieldType ift) {
105+
106+
public static InnerFieldType createArrayType(InnerFieldType ift) {
61107
String javaDataType = String.format("%1$s[]", ift.javaDataType);
62-
return new InnerFieldType(false, false, String.format(Locale.ROOT, "Accessors.createArrayAccessor(%1$s)", ift.accessor), "BLOB", javaDataType, null);
63-
}
108+
return new InnerFieldType(false, false,
109+
String.format(Locale.ROOT, "Accessors.createArrayAccessor(%1$s)", ift.accessor), "BLOB", javaDataType,
110+
null);
111+
}
64112
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package net.cattaka.util.cathandsgendroid.apt.util;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import javax.lang.model.type.DeclaredType;
7+
import javax.lang.model.type.TypeMirror;
8+
9+
public class Functions {
10+
public static String join(List<?> objects, String delim) {
11+
if (objects == null) {
12+
return "";
13+
}
14+
StringBuilder sb = new StringBuilder();
15+
int i = 0;
16+
for (Object object : objects) {
17+
if (i > 0) {
18+
sb.append(delim);
19+
}
20+
sb.append(String.valueOf(object));
21+
i++;
22+
}
23+
return sb.toString();
24+
}
25+
26+
public static List<String> pullTypes(DeclaredType tm) {
27+
List<String> results = new ArrayList<String>();
28+
results.add(String.valueOf(tm.asElement()));
29+
if (tm instanceof DeclaredType) {
30+
for (TypeMirror t : ((DeclaredType)tm).getTypeArguments()) {
31+
results.addAll(pullTypes((DeclaredType)t));
32+
}
33+
}
34+
return results;
35+
}
36+
}

cathandsgendroid-apt/src/test/java/net/cattaka/util/cathandsgendroid/test/FullModelTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.io.DataOutputStream;
1313
import java.io.IOException;
1414
import java.util.Date;
15+
import java.util.HashSet;
16+
import java.util.Set;
1517

1618
import net.cattaka.util.cathandsgendroid.test.model.FullModel;
1719
import net.cattaka.util.cathandsgendroid.test.model.FullModel.TinyEnum;
@@ -62,6 +64,7 @@ public void testDbFunc() {
6264
model.setShortValue((short)243);
6365
model.setStringValue("This is it");
6466
model.setTinyEnum(TinyEnum.A);
67+
model.setSetSetStringValue(generateTestData(4, 3));
6568
FullModelCatHands.insert(db, model);
6669
}
6770
{// compare
@@ -91,6 +94,7 @@ public void testDbFunc() {
9194
assertEquals(model.getShortValue(), t.getShortValue());
9295
assertEquals(model.getStringValue(), t.getStringValue());
9396
assertEquals(model.getTinyEnum(), t.getTinyEnum());
97+
assertEquals(model.getSetSetStringValue(), t.getSetSetStringValue());
9498
}
9599
{
96100
assertEquals(1, FullModelCatHands.findByBooleanValue(db, 0, model.getBooleanValue())
@@ -183,6 +187,7 @@ public void testDbFunc() {
183187
assertEquals(model2.getShortValue(), t.getShortValue());
184188
assertEquals(model2.getStringValue(), t.getStringValue());
185189
assertEquals(model2.getTinyEnum(), t.getTinyEnum());
190+
assertEquals(model2.getSetSetStringValue(), t.getSetSetStringValue());
186191
}
187192
{ // delete
188193
assertEquals(1, FullModelCatHands.delete(db, model.getKey()));
@@ -227,6 +232,7 @@ public void testDbFunc_null() {
227232
assertEquals(model.getShortValue(), t.getShortValue());
228233
assertEquals(model.getStringValue(), t.getStringValue());
229234
assertEquals(model.getTinyEnum(), t.getTinyEnum());
235+
assertEquals(model.getSetSetStringValue(), t.getSetSetStringValue());
230236
}
231237
}
232238

@@ -259,6 +265,7 @@ public void testParcelFunc() {
259265
model.setShortValue((short)243);
260266
model.setStringValue("This is it");
261267
model.setTinyEnum(TinyEnum.A);
268+
model.setSetSetStringValue(generateTestData(4, 3));
262269
}
263270

264271
Parcel parcel;
@@ -292,6 +299,7 @@ public void testParcelFunc() {
292299
assertEquals(model.getShortValue(), t.getShortValue());
293300
assertEquals(model.getStringValue(), t.getStringValue());
294301
assertEquals(model.getTinyEnum(), t.getTinyEnum());
302+
assertEquals(model.getSetSetStringValue(), t.getSetSetStringValue());
295303
}
296304
}
297305

@@ -332,6 +340,7 @@ public void testParcelFunc_null() {
332340
assertEquals(model.getShortValue(), t.getShortValue());
333341
assertEquals(model.getStringValue(), t.getStringValue());
334342
assertEquals(model.getTinyEnum(), t.getTinyEnum());
343+
assertEquals(model.getSetSetStringValue(), t.getSetSetStringValue());
335344
}
336345
}
337346

@@ -365,6 +374,7 @@ public void testDsFunc() throws IOException {
365374
model.setShortValue((short)243);
366375
model.setStringValue("This is it");
367376
model.setTinyEnum(TinyEnum.A);
377+
model.setSetSetStringValue(generateTestData(4, 3));
368378
}
369379

370380
byte[] data;
@@ -404,6 +414,7 @@ public void testDsFunc() throws IOException {
404414
assertEquals(model.getShortValue(), t.getShortValue());
405415
assertEquals(model.getStringValue(), t.getStringValue());
406416
assertEquals(model.getTinyEnum(), t.getTinyEnum());
417+
assertEquals(model.getSetSetStringValue(), t.getSetSetStringValue());
407418
assertEquals(-1, din.read());
408419
}
409420
}
@@ -448,6 +459,7 @@ public void testDsFunc_null() throws IOException {
448459
assertEquals(model.getShortValue(), t.getShortValue());
449460
assertEquals(model.getStringValue(), t.getStringValue());
450461
assertEquals(model.getTinyEnum(), t.getTinyEnum());
462+
assertEquals(model.getSetSetStringValue(), t.getSetSetStringValue());
451463
}
452464
}
453465

@@ -478,4 +490,17 @@ private void assertEqualsArray(byte[] b1, byte[] b2) {
478490
}
479491
}
480492
}
493+
494+
private Set<Set<String>> generateTestData(int m, int n) {
495+
int c = 0;
496+
Set<Set<String>> ss = new HashSet<Set<String>>();
497+
for (int i=0;i<m;i++) {
498+
Set<String> s = new HashSet<String>();
499+
for (int j=0;j<n;j++) {
500+
s.add(String.valueOf(c++));
501+
}
502+
ss.add(s);
503+
}
504+
return ss;
505+
}
481506
}

0 commit comments

Comments
 (0)