use of com.sun.codemodel.JFieldVar in project jsonschema2pojo by joelittlejohn.
the class MinimumMaximumRuleTest method jsrDisable.
@Test
public void jsrDisable() {
when(config.isIncludeJsr303Annotations()).thenReturn(false);
JFieldVar result = rule.apply("node", node, null, fieldVar, null);
assertSame(fieldVar, result);
verify(fieldVar, never()).annotate(decimalMinClass);
verify(annotationMin, never()).param(anyString(), anyString());
verify(fieldVar, never()).annotate(decimalMaxClass);
verify(annotationMax, never()).param(anyString(), anyString());
}
use of com.sun.codemodel.JFieldVar in project jsonschema2pojo by joelittlejohn.
the class MinimumMaximumRuleTest method testMinimum.
@Test
public void testMinimum() {
when(config.isIncludeJsr303Annotations()).thenReturn(true);
final String minValue = Integer.toString(new Random().nextInt());
when(subNode.asText()).thenReturn(minValue);
when(node.get("minimum")).thenReturn(subNode);
when(fieldVar.annotate(decimalMinClass)).thenReturn(annotationMin);
when(node.has("minimum")).thenReturn(true);
when(fieldVar.type().boxify().fullName()).thenReturn(fieldClass.getTypeName());
JFieldVar result = rule.apply("node", node, null, fieldVar, null);
assertSame(fieldVar, result);
verify(fieldVar, times(isApplicable ? 1 : 0)).annotate(decimalMinClass);
verify(annotationMin, times(isApplicable ? 1 : 0)).param("value", minValue);
verify(fieldVar, never()).annotate(decimalMaxClass);
verify(annotationMax, never()).param(eq("value"), anyString());
}
use of com.sun.codemodel.JFieldVar in project jsonschema2pojo by joelittlejohn.
the class ParcelableHelper method addWriteToParcel.
public void addWriteToParcel(JDefinedClass jclass) {
JMethod method = jclass.method(JMod.PUBLIC, void.class, "writeToParcel");
JVar dest = method.param(jclass.owner().directClass("android.os.Parcel"), "dest");
method.param(int.class, "flags");
// Call super.writeToParcel
if (extendsParcelable(jclass)) {
method.body().directStatement("super.writeToParcel(dest, flags);");
}
for (JFieldVar f : jclass.fields().values()) {
if ((f.mods().getValue() & JMod.STATIC) == JMod.STATIC) {
continue;
}
if (f.type().erasure().name().equals("List")) {
method.body().invoke(dest, "writeList").arg(f);
} else {
method.body().invoke(dest, "writeValue").arg(f);
}
}
}
use of com.sun.codemodel.JFieldVar in project jsonschema2pojo by joelittlejohn.
the class ParcelableHelper method addConstructorFromParcel.
public void addConstructorFromParcel(JDefinedClass jclass) {
JMethod ctorFromParcel = jclass.constructor(JMod.PROTECTED);
JVar in = ctorFromParcel.param(jclass.owner().directClass("android.os.Parcel"), "in");
suppressWarnings(ctorFromParcel, "unchecked");
if (extendsParcelable(jclass)) {
ctorFromParcel.body().directStatement("super(in);");
}
for (JFieldVar f : jclass.fields().values()) {
if ((f.mods().getValue() & JMod.STATIC) == JMod.STATIC) {
continue;
}
if (f.type().erasure().name().equals("List")) {
ctorFromParcel.body().invoke(in, "readList").arg(JExpr._this().ref(f)).arg(JExpr.direct(getListType(f.type()) + ".class.getClassLoader()"));
} else {
ctorFromParcel.body().assign(JExpr._this().ref(f), JExpr.cast(f.type(), in.invoke("readValue").arg(JExpr.direct(f.type().erasure().name() + ".class.getClassLoader()"))));
}
}
}
use of com.sun.codemodel.JFieldVar in project jsonschema2pojo by joelittlejohn.
the class SerializableHelper method processDefinedClassForSerializableSupport.
private static void processDefinedClassForSerializableSupport(JDefinedClass jclass, DataOutputStream dataOutputStream) throws IOException {
dataOutputStream.writeUTF(jclass.fullName());
dataOutputStream.writeInt(jclass.mods().getValue());
for (JTypeVar typeParam : jclass.typeParams()) {
dataOutputStream.writeUTF(typeParam.fullName());
}
// sorted
TreeMap<String, JDefinedClass> sortedClasses = new TreeMap<>();
Iterator<JDefinedClass> classes = jclass.classes();
while (classes.hasNext()) {
JDefinedClass nestedClass = classes.next();
sortedClasses.put(nestedClass.fullName(), nestedClass);
}
for (JDefinedClass nestedClass : sortedClasses.values()) {
processDefinedClassForSerializableSupport(nestedClass, dataOutputStream);
}
// sorted
TreeSet<String> fieldNames = new TreeSet<>(jclass.fields().keySet());
for (String fieldName : fieldNames) {
JFieldVar fieldVar = jclass.fields().get(fieldName);
// non private members
if ((fieldVar.mods().getValue() & JMod.PRIVATE) != JMod.PRIVATE) {
processFieldVarForSerializableSupport(jclass.fields().get(fieldName), dataOutputStream);
}
}
Iterator<JClass> interfaces = jclass._implements();
List<JClass> interfacesList = new ArrayList<>();
while (interfaces.hasNext()) {
JClass aInterface = interfaces.next();
interfacesList.add(aInterface);
}
Collections.sort(interfacesList, INTERFACE_COMPARATOR);
for (JClass aInterface : interfacesList) {
dataOutputStream.writeUTF(aInterface.fullName());
}
// we should probably serialize the parent class too! (but what if it has serialversionUID on it? that would be a field and would affect the serialversionUID!)
if (jclass._extends() != null) {
dataOutputStream.writeUTF(jclass._extends().fullName());
}
processMethodCollectionForSerializableSupport(jclass.methods().iterator(), dataOutputStream);
processMethodCollectionForSerializableSupport(jclass.constructors(), dataOutputStream);
}
Aggregations