private static void processFieldVarForSerializableSupport(JFieldVar fieldVar, DataOutputStream dataOutputStream) throws IOException { dataOutputStream.writeUTF(fieldVar.name()); dataOutputStream.writeInt(fieldVar.mods().getValue()); JType type = fieldVar.type(); dataOutputStream.writeUTF(type.fullName()); }
private static void processMethodCollectionForSerializableSupport(Iterator<JMethod> methods, DataOutputStream dataOutputStream) throws IOException { TreeMap<String, JMethod> sortedMethods = new TreeMap<>(); while (methods.hasNext()) { JMethod method = methods.next(); //Collect non-private methods if ((method.mods().getValue() & JMod.PRIVATE) != JMod.PRIVATE) { sortedMethods.put(method.name(), method); } } for (JMethod method : sortedMethods.values()) { dataOutputStream.writeUTF(method.name()); dataOutputStream.writeInt(method.mods().getValue()); if (method.type() != null) { dataOutputStream.writeUTF(method.type().fullName()); } for (JVar param : method.params()) { dataOutputStream.writeUTF(param.type().fullName()); } } }
private static void processDefinedClassForSerializableSupport(JDefinedClass jclass, DataOutputStream dataOutputStream) throws IOException { dataOutputStream.writeUTF(jclass.fullName()); dataOutputStream.writeInt(jclass.mods().getValue()); JFieldVar fieldVar = jclass.fields().get(fieldName); if ((fieldVar.mods().getValue() & JMod.PRIVATE) != JMod.PRIVATE) { processFieldVarForSerializableSupport(jclass.fields().get(fieldName), dataOutputStream);
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); } } }
private void addOverrideBuilder(JDefinedClass thisJDefinedClass, JMethod parentBuilder, JVar parentParam) { if (thisJDefinedClass.getMethod(parentBuilder.name(), new JType[] {parentParam.type()}) == null) { JMethod builder = thisJDefinedClass.method(parentBuilder.mods().getValue(), thisJDefinedClass, parentBuilder.name()); builder.annotate(Override.class); JVar param = builder.param(parentParam.type(), parentParam.name()); JBlock body = builder.body(); body.invoke(JExpr._super(), parentBuilder).arg(param); body._return(JExpr._this()); } } }
public void addConstructorFromParcel(JDefinedClass jclass) { JMethod ctorFromParcel = jclass.constructor(JMod.PROTECTED); JVar in = ctorFromParcel.param(jclass.owner().directClass("android.os.Parcel"), "in"); 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()")) ) ); } } }
if ((fieldVar.mods().getValue() & JMod.STATIC) == JMod.STATIC) { continue;
if ((fieldVar.mods().getValue() & JMod.STATIC) == JMod.STATIC) { continue;
if (excludes.contains(fieldVar.name()) || (fieldVar.mods().getValue() & JMod.STATIC) == JMod.STATIC) { continue;
/** * Returns the Java language modifiers for this <code>JavaField</code>, encoded in an integer. * * @return the <code>int</code> representing the modifiers for this field. * * @see java.lang.reflect.Modifier */ public int getModifiers() { return xjcField.mods().getValue(); }
/** * Returns the Java language modifiers for this <code>JavaConstructor</code>, encoded in an integer. * * @return the <code>int</code> representing the modifiers for this constructor. * * @see java.lang.reflect.Modifier */ public int getModifiers() { return xjcConstructor.mods().getValue(); }
/** * Returns the Java language modifiers for this <code>JavaMethod</code>, encoded in an integer. * * @return the <code>int</code> representing the modifiers for this method. * * @see java.lang.reflect.Modifier */ public int getModifiers() { return xjcMethod.mods().getValue(); }
/** * Whether or not to generate a constructor parameter for the given field. */ protected boolean generateConstructorParameter(final JFieldVar field) { final boolean isStaticField = (field.mods().getValue() & JMod.STATIC) > 0; return !isStaticField; }
/** * Takes a collection of fields, and returns a new collection containing only the instance * (i.e. non-static) fields. */ protected Collection<JFieldVar> getInstanceFields(final Collection<JFieldVar> fields) { final List<JFieldVar> instanceFields = new ArrayList<JFieldVar>(); for (final JFieldVar fieldVar : fields) { final boolean isStaticField = (fieldVar.mods().getValue() & JMod.STATIC) != 0; if (!isStaticField) { instanceFields.add(fieldVar); } } return instanceFields; }
private Map<String, JFieldVar> getNonTransientAndNonStaticFields() { Map<String, JFieldVar> nonStaticNonTransientFields = new LinkedHashMap<>(); if (pojo instanceof JDefinedClass) { Map<String, JFieldVar> fields = ((JDefinedClass) pojo).fields(); Iterator<Map.Entry<String, JFieldVar>> iterator = fields.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, JFieldVar> pair = iterator.next(); // If a field is not static or transient if ((pair.getValue().mods().getValue() & (JMod.STATIC | JMod.TRANSIENT)) == 0) { nonStaticNonTransientFields.put(pair.getKey(), pair.getValue()); } } } return nonStaticNonTransientFields; }
private boolean isFField(JFieldVar fieldVar) { boolean isPublicStaticFinal = (fieldVar.mods().getValue() & (JMod.STATIC | JMod.FINAL)) != 0; if (fieldVar.name().startsWith("F_") && isPublicStaticFinal) { //our QName constant fields return true; } return false; }
private void removePrivateStaticCopyMethods(ClassOutline classOutline) { JDefinedClass impl = classOutline.implClass; Iterator<JMethod> methods = impl.methods().iterator(); while (methods.hasNext()) { JMethod method = methods.next(); if ((method.mods().getValue() & (JMod.PRIVATE | JMod.STATIC)) == 0) { continue; } if (method.name().startsWith("copy")) { methods.remove(); } } }
private static void processFieldVarForSerializableSupport(JFieldVar fieldVar, DataOutputStream dataOutputStream) throws IOException { dataOutputStream.writeUTF(fieldVar.name()); dataOutputStream.writeInt(fieldVar.mods().getValue()); JType type = fieldVar.type(); dataOutputStream.writeUTF(type.fullName()); }
private void generateFieldCopyExpressions(final CopyGenerator cloneGenerator, final JBlock body, final JExpression targetObject, final JExpression sourceObject) { for (final FieldOutline fieldOutline : this.classOutline.getDeclaredFields()) { final JFieldVar field = PluginUtil.getDeclaredField(fieldOutline); if (field != null) { if ((field.mods().getValue() & (JMod.FINAL | JMod.STATIC)) == 0) { generateFieldCopyExpression(cloneGenerator, body, targetObject, field, targetObject.ref(field.name()), sourceObject.ref(field.name())); } } } }
private void addOverrideBuilder(JDefinedClass thisJDefinedClass, JMethod parentBuilder, JVar parentParam) { if (thisJDefinedClass.getMethod(parentBuilder.name(), new JType[] {parentParam.type()}) == null) { JMethod builder = thisJDefinedClass.method(parentBuilder.mods().getValue(), thisJDefinedClass, parentBuilder.name()); builder.annotate(Override.class); JVar param = builder.param(parentParam.type(), parentParam.name()); JBlock body = builder.body(); body.invoke(JExpr._super(), parentBuilder).arg(param); body._return(JExpr._this()); } } }