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 JMethod addPublicSetMethod(JDefinedClass jclass, JMethod internalSetMethod) { JMethod method = jclass.method(PUBLIC, jclass.owner().VOID, SETTER_NAME); JVar nameParam = method.param(String.class, "name"); JVar valueParam = method.param(Object.class, "value"); JBlock body = method.body(); JBlock notFound = body._if(JOp.not(invoke(internalSetMethod).arg(nameParam).arg(valueParam)))._then(); // if we have additional properties, then put value. JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {}); if (getAdditionalProperties != null) { JType additionalPropertiesType = ((JClass) (getAdditionalProperties.type())).getTypeParameters().get(1); notFound.add(invoke(getAdditionalProperties).invoke("put").arg(nameParam) .arg(cast(additionalPropertiesType, valueParam))); } // else throw exception. else { notFound._throw(illegalArgumentInvocation(jclass, nameParam)); } return method; }
private JMethod addPublicWithMethod(JDefinedClass jclass, JMethod internalSetMethod) { JMethod method = jclass.method(PUBLIC, jclass, BUILDER_NAME); JVar nameParam = method.param(String.class, "name"); JVar valueParam = method.param(Object.class, "value"); JBlock body = method.body(); JBlock notFound = body._if(JOp.not(invoke(internalSetMethod).arg(nameParam).arg(valueParam)))._then(); // if we have additional properties, then put value. JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {}); if (getAdditionalProperties != null) { JType additionalPropertiesType = ((JClass) (getAdditionalProperties.type())).getTypeParameters().get(1); notFound.add(invoke(getAdditionalProperties).invoke("put").arg(nameParam) .arg(cast(additionalPropertiesType, valueParam))); } // else throw exception. else { notFound._throw(illegalArgumentInvocation(jclass, nameParam)); } body._return(_this()); return method; }
private JMethod addPublicGetMethod(JDefinedClass jclass, JMethod internalGetMethod, JFieldRef notFoundValue) { JMethod method = jclass.method(PUBLIC, jclass.owner()._ref(Object.class), GETTER_NAME); JTypeVar returnType = method.generify("T"); method.type(returnType); Models.suppressWarnings(method, "unchecked"); JVar nameParam = method.param(String.class, "name"); JBlock body = method.body(); JVar valueVar = body.decl(jclass.owner()._ref(Object.class), "value", invoke(internalGetMethod).arg(nameParam).arg(notFoundValue)); JConditional found = method.body()._if(notFoundValue.ne(valueVar)); found._then()._return(cast(returnType, valueVar)); JBlock notFound = found._else(); JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {}); if (getAdditionalProperties != null) { notFound._return(cast(returnType, invoke(getAdditionalProperties).invoke("get").arg(nameParam))); } else { notFound._throw(illegalArgumentInvocation(jclass, nameParam)); } return method; }
final JDefinedClass exampleClass = codeModel._class( "com.example.ExampleClass" ); final JMethod method = exampleClass.method( JMod.PUBLIC, Object.class, "getValue" ); final JTypeVar t = method.generify( "T" ); method.type( t ); method.param( codeModel.ref( Class.class ).narrow( t ), "type" ); method.body()._return(JExpr._null());
private void setReturnType(JType type, JMethod jMethod) { if (jMethod != null) { jMethod.type(type); } }
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 boolean isFieldOutlineCore(Mapping context, FieldOutline fieldOutline) { final JMethod getter = FieldAccessorUtils.getter(fieldOutline); final JType type = getter.type(); return JTypeUtils.isBasicType(type); }
public boolean isFieldOutlineCore(Mapping context, FieldOutline fieldOutline) { final JMethod getter = FieldAccessorUtils.getter(fieldOutline); final JType type = getter.type(); return JTypeUtils.isBasicType(type); }
public boolean isFieldOutlineCore(Mapping context, FieldOutline fieldOutline) { final JMethod getter = FieldAccessorUtils.getter(fieldOutline); final JType type = getter.type(); return JTypeUtils.isBasicType(type); }
public boolean isTemporal(Mapping context, FieldOutline fieldOutline) { final JMethod getter = FieldAccessorUtils.getter(fieldOutline); final JType type = getter.type(); return JTypeUtils.isTemporalType(type); }
private JMethod createReferenceFluentEnd(ClassOutline classOutline) { String methodName = "end"; JMethod method = classOutline.implClass.method(JMod.PUBLIC, (JType) null, methodName); method.type(method.generify("X")); JBlock body = method.body(); body._return(JExpr.cast(method.type(), JExpr.invoke(JExpr.cast(CLASS_MAP.get(PrismContainerValue.class), JExpr.invoke(JExpr.cast(CLASS_MAP.get(PrismReference.class), JExpr.invoke(JExpr.invoke("asReferenceValue"),"getParent")), "getParent")), "asContainerable"))); return method; }
private JMethod createContainerFluentEnd(ClassOutline classOutline) { String methodName = "end"; JMethod method = classOutline.implClass.method(JMod.PUBLIC, (JType) null, methodName); method.type(method.generify("X")); JBlock body = method.body(); body._return(JExpr.cast(method.type(), JExpr.invoke(JExpr.cast(CLASS_MAP.get(PrismContainerValue.class), JExpr.invoke(JExpr.cast(CLASS_MAP.get(PrismContainer.class), JExpr.invoke(JExpr.invoke("asPrismContainerValue"),"getParent")), "getParent")), "asContainerable"))); return method; }
public static JMethod setter(FieldOutline fieldOutline) { final JMethod getter = getter(fieldOutline); assert getter != null : "Getter is required."; final JType type = getter.type(); final JDefinedClass theClass = fieldOutline.parent().implClass; final String publicName = fieldOutline.getPropertyInfo().getName(true); final String name = "set" + publicName; return theClass.getMethod(name, new JType[] { type }); }
public static JMethod setter(FieldOutline fieldOutline) { final JMethod getter = getter(fieldOutline); assert getter != null : "Getter is required."; final JType type = getter.type(); final JDefinedClass theClass = fieldOutline.parent().implClass; final String publicName = fieldOutline.getPropertyInfo().getName(true); final String name = "set" + publicName; return theClass.getMethod(name, new JType[] { type }); }
public static JMethod setter(FieldOutline fieldOutline) { final JMethod getter = getter(fieldOutline); assert getter != null : "Getter is required."; final JType type = getter.type(); final JDefinedClass theClass = fieldOutline.parent().implClass; final String publicName = fieldOutline.getPropertyInfo().getName(true); final String name = "set" + publicName; return theClass.getMethod(name, new JType[] { type }); }
public void callSuperMethod(JMethod superMethod, EBeanHolder holder, JBlock callBlock) { JExpression activitySuper = holder.generatedClass.staticRef("super"); JInvocation superCall = JExpr.invoke(activitySuper, superMethod); for (JVar param : superMethod.params()) { superCall.arg(param); } JType returnType = superMethod.type(); if (returnType.fullName().equals("void")) { callBlock.add(superCall); } else { callBlock._return(superCall); } }
private JMethod makeHeadersWrapper( String endPointName, List<BasicNameValuePair> headersList ) { JClass headerClass = codeModel.ref( headersList.getClass() ).narrow( BasicNameValuePair.class ); JMethod wrapperMethod = definedClass.method( JMod.PUBLIC | JMod.STATIC, headerClass, ( "make" + endPointName + "Header") ); JVar headersListVar = wrapperMethod.body().decl( wrapperMethod.type(), "headersList", JExpr._new(headerClass) ); for(BasicNameValuePair nameValuePair : headersList) { wrapperMethod.body().add(headersListVar.invoke("add").arg(JExpr._new(nameValuePairClass).arg(nameValuePair.getName()).arg(nameValuePair.getValue()))); } wrapperMethod.body()._return( headersListVar ); return wrapperMethod; }
private void createReferenceStringVersionOidType(JFieldVar field, ClassOutline classOutline, JMethod originalMethod, JType objectReferenceType) { JMethod newMethod = classOutline.implClass.method(JMod.PUBLIC, originalMethod.type(), originalMethod.name()); JVar oid = newMethod.param(String.class, "oid"); JVar type = newMethod.param(QName.class, "type"); JBlock body = newMethod.body(); JVar refVal = body.decl(CLASS_MAP.get(PrismReferenceValue.class), "refVal", JExpr._new(CLASS_MAP.get(PrismReferenceValueImpl.class)) .arg(oid).arg(type)); JVar ort = body.decl(objectReferenceType, "ort", JExpr._new(objectReferenceType)); body.invoke(ort, METHOD_SETUP_REFERENCE_VALUE).arg(refVal); body._return(JExpr.invoke(originalMethod).arg(ort)); }
private void generateCastMethod(JCodeModel codeModel, EBeanHolder holder) { JType objectType = codeModel._ref(Object.class); JMethod method = holder.generatedClass.method(JMod.PRIVATE, objectType, "cast_"); JTypeVar genericType = method.generify("T"); method.type(genericType); JVar objectParam = method.param(objectType, "object"); method.annotate(SuppressWarnings.class).param("value", "unchecked"); method.body()._return(JExpr.cast(genericType, objectParam)); holder.cast = method; }