@Override public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) { field.annotate(JsonProperty.class).param("value", propertyName); if (field.type().erasure().equals(field.type().owner().ref(Set.class))) { field.annotate(JsonDeserialize.class).param("as", LinkedHashSet.class); } if (propertyNode.has("javaJsonView")) { field.annotate(JsonView.class).param( "value", field.type().owner().ref(propertyNode.get("javaJsonView").asText())); } if (propertyNode.has("description")) { field.annotate(JsonPropertyDescription.class).param("value", propertyNode.get("description").asText()); } }
@Override public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) { field.annotate(JsonProperty.class).param("value", propertyName); if (field.type().erasure().equals(field.type().owner().ref(Set.class))) { field.annotate(JsonDeserialize.class).param("as", LinkedHashSet.class); } if (propertyNode.has("javaJsonView")) { field.annotate(JsonView.class).param( "value", field.type().owner().ref(propertyNode.get("javaJsonView").asText())); } }
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); } } }
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()")) ) ); } } }
/** * Generates {@code new T[size]}. * * @param type * The type of the array component. 'T' or {@code new T[size]}. */ public static JArray newArray(JType type, JExpression size) { // you cannot create an array whose component type is a generic return new JArray(type.erasure(), size); }
/** * Generates {@code new T[size]}. * * @param type * The type of the array component. 'T' or {@code new T[size]}. */ public static JArray newArray(JType type, JExpression size) { // you cannot create an array whose component type is a generic return new JArray(type.erasure(), size); }
/** * Generates {@code new T[size]}. * * @param type * The type of the array component. 'T' or {@code new T[size]}. */ public static JArray newArray(JType type, JExpression size) { // you cannot create an array whose component type is a generic return new JArray(type.erasure(), size); }
/** * @param type a java type abstraction * @return erasure type for given java type */ public static String getErasureType(final JType type) { return type.erasure().name(); }
/** * Generates {@code new T[size]}. * * @param type * The type of the array component. 'T' or {@code new T[size]}. */ public static JArray newArray(JType type, JExpression size) { // you cannot create an array whose component type is a generic return new JArray(type.erasure(), size); }
/** * Generates {@code new T[size]}. * * @param type * The type of the array component. 'T' or {@code new T[size]}. */ public static JArray newArray(JType type, JExpression size) { // you cannot create an array whose component type is a generic return new JArray(type.erasure(), size); }
private static boolean implementsInterface( @Nonnull JType type, @Nonnull Class<?> daClass ) { JType erasure = type.erasure(); if ( erasure.fullName().equals( daClass.getName() ) ) { return true; } Iterator<JClass> implementedIterator = ( ( JClass ) erasure )._implements(); while ( implementedIterator.hasNext() ) { JClass implemented = implementedIterator.next(); if ( implemented.fullName().equals( daClass.getName() ) ) { return true; } } return false; }
private void generateBuilderMethodJavadoc(final JMethod method, final String methodPrefix, final String propertyName) { final String endMethodClassName = method.type().erasure().fullName(); method.javadoc().append(MessageFormat.format(this.resources.getString("comment." + methodPrefix + "BuilderMethod"), propertyName, endMethodClassName)) .addReturn().append(MessageFormat.format(this.resources.getString("comment." + methodPrefix + "BuilderMethod.return"), propertyName, endMethodClassName)); }
public String generateName(JType definedClass) { return generateName(definedClass.erasure().fullName()); }
@Override public boolean isIndirect() { return this.jaxbElementClass.fullName().equals(getElementType().erasure().fullName()); }
@Nonnull public static String removeWildcard( @Nonnull JType classWithWildcard, boolean returnBinaryName ) { if ( classWithWildcard != classWithWildcard.erasure() ) { throw new IllegalArgumentException( "Invalid type - cannot remove wildcard. Call erasure() first: " + classWithWildcard.fullName() ); } if ( classWithWildcard.fullName().contains( "?" ) ) { String fullName = returnBinaryName ? classWithWildcard.binaryName() : classWithWildcard.fullName(); Iterable<String> parts = Splitter.on( " " ).split( fullName ); String last = null; for ( String part : parts ) { last = part; } assert last != null; return last; } return returnBinaryName ? classWithWildcard.binaryName() : classWithWildcard.fullName(); }
@Override public boolean isIndirect() { return getElementType().erasure().fullName().equals(this.codeModel.ref(JAXBElement.class).fullName()); }
@Nonnull public JExpression createCollectionInvocation( @Nonnull JType collectionParamType, @Nonnull String simpleName, boolean isSet ) { JExpression expression = create( collectionParamType.erasure(), simpleName ); JInvocation listInvocation = classRefSupport.ref( Arrays.class ).staticInvoke( METHOD_NAME_AS_LIST ).arg( expression ); if ( isSet ) { return JExpr._new( classRefSupport.ref( HashSet.class ) ).arg( listInvocation ); } else { return listInvocation; } }
private JExpression getUnmodifiableWrappedExpression(JCodeModel codeModel, JVar param) { if (param.type().erasure().equals(codeModel.ref(Collection.class))) { return codeModel.ref(Collections.class).staticInvoke("unmodifiableCollection").arg(param); } else if (param.type().erasure().equals(codeModel.ref(List.class))) { return codeModel.ref(Collections.class).staticInvoke("unmodifiableList").arg(param); } else if (param.type().erasure().equals(codeModel.ref(Map.class))) { return codeModel.ref(Collections.class).staticInvoke("unmodifiableMap").arg(param); } else if (param.type().erasure().equals(codeModel.ref(Set.class))) { return codeModel.ref(Collections.class).staticInvoke("unmodifiableSet").arg(param); } else if (param.type().erasure().equals(codeModel.ref(SortedMap.class))) { return codeModel.ref(Collections.class).staticInvoke("unmodifiableSortedMap").arg(param); } else if (param.type().erasure().equals(codeModel.ref(SortedSet.class))) { return codeModel.ref(Collections.class).staticInvoke("unmodifiableSortedSet").arg(param); } return param; }
@Override public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) { field.annotate(JsonProperty.class).param("value", propertyName); if (field.type().erasure().equals(field.type().owner().ref(Set.class))) { field.annotate(JsonDeserialize.class).param("as", LinkedHashSet.class); } if (propertyNode.has("javaJsonView")) { field.annotate(JsonView.class).param( "value", field.type().owner().ref(propertyNode.get("javaJsonView").asText())); } if (propertyNode.has("description")) { field.annotate(JsonPropertyDescription.class).param("value", propertyNode.get("description").asText()); } }
@Override public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) { field.annotate(JsonProperty.class).param("value", propertyName); if (field.type().erasure().equals(field.type().owner().ref(Set.class))) { field.annotate(JsonDeserialize.class).param("as", LinkedHashSet.class); } if (propertyNode.has("javaJsonView")) { field.annotate(JsonView.class).param( "value", field.type().owner().ref(propertyNode.get("javaJsonView").asText())); } }