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 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; }
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 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; }
JTypeVar retType = asMeth.generify( "T" ); asMeth.type( retType );
JMethod generateCopyOfMethod(final TypeOutline paramType, final boolean partial) { if (paramType.getSuperClass() != null) { generateCopyOfMethod(paramType.getSuperClass(), partial); } final JMethod copyOfMethod = this.definedClass.method(JMod.PUBLIC | JMod.STATIC, this.builderClass.raw.narrow(Void.class), this.pluginContext.buildCopyMethodName); final JTypeVar copyOfMethodTypeParam = copyOfMethod.generify(BuilderGenerator.PARENT_BUILDER_TYPE_PARAMETER_NAME); copyOfMethod.type(this.builderClass.raw.narrow(copyOfMethodTypeParam)); final JVar otherParam = copyOfMethod.param(JMod.FINAL, paramType.getImplClass(), BuilderGenerator.OTHER_PARAM_NAME); final CopyGenerator copyGenerator = this.pluginContext.createCopyGenerator(copyOfMethod, partial); final JVar newBuilderVar = copyOfMethod.body().decl(JMod.FINAL, copyOfMethod.type(), BuilderGenerator.NEW_BUILDER_VAR_NAME, JExpr._new(copyOfMethod.type()).arg(JExpr._null()).arg(JExpr._null()).arg(JExpr.FALSE)); copyOfMethod.body().add(copyGenerator.generatePartialArgs(this.pluginContext.invoke(otherParam, this.settings.getCopyToMethodName()).arg(newBuilderVar))); copyOfMethod.body()._return(newBuilderVar); return copyOfMethod; }
final void generateCopyToMethod(final boolean partial) { if (this.implement) { final JDefinedClass typeDefinition = this.typeOutline.isInterface() && ((DefinedInterfaceOutline)this.typeOutline).getSupportInterface() != null ? ((DefinedInterfaceOutline)this.typeOutline).getSupportInterface() : this.definedClass; final JMethod copyToMethod = typeDefinition.method(JMod.PUBLIC, this.pluginContext.voidType, this.settings.getCopyToMethodName()); final JTypeVar typeVar = copyToMethod.generify(BuilderGenerator.PARENT_BUILDER_TYPE_PARAMETER_NAME); final JVar otherParam = copyToMethod.param(JMod.FINAL, this.builderClass.raw.narrow(typeVar), BuilderGenerator.OTHER_PARAM_NAME); final CopyGenerator cloneGenerator = this.pluginContext.createCopyGenerator(copyToMethod, partial); final JBlock body = copyToMethod.body(); final JVar otherRef; if (this.typeOutline.getSuperClass() != null) { body.add(cloneGenerator.generatePartialArgs(this.pluginContext.invoke(JExpr._super(), copyToMethod.name()).arg(otherParam))); } otherRef = otherParam; generateFieldCopyExpressions(cloneGenerator, body, otherRef, JExpr._this()); copyToMethod.javadoc().append(getMessage("javadoc.method.copyTo")); copyToMethod.javadoc().addParam(otherParam).append(getMessage("javadoc.method.copyTo.param.other")); } }
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; }
JMethod generateNewCopyBuilderMethod(final boolean partial) { final JDefinedClass typeDefinition = this.typeOutline.isInterface() && ((DefinedInterfaceOutline)this.typeOutline).getSupportInterface() != null ? ((DefinedInterfaceOutline)this.typeOutline).getSupportInterface() : this.definedClass; final int mods = this.implement ? this.definedClass.isAbstract() ? JMod.PUBLIC | JMod.ABSTRACT : JMod.PUBLIC : JMod.NONE; final JMethod copyBuilderMethod = typeDefinition.method(mods, this.builderClass.raw, this.settings.getNewCopyBuilderMethodName()); final JTypeVar copyBuilderMethodTypeParam = copyBuilderMethod.generify(BuilderGenerator.PARENT_BUILDER_TYPE_PARAMETER_NAME); final JVar parentBuilderParam = copyBuilderMethod.param(JMod.FINAL, copyBuilderMethodTypeParam, BuilderGenerator.PARENT_BUILDER_PARAM_NAME); final CopyGenerator copyGenerator = this.pluginContext.createCopyGenerator(copyBuilderMethod, partial); copyBuilderMethod.type(this.builderClass.raw.narrow(copyBuilderMethodTypeParam)); final JMethod copyBuilderConvenienceMethod = typeDefinition.method(mods, this.builderClass.raw.narrow(this.pluginContext.voidClass), this.settings.getNewCopyBuilderMethodName()); final CopyGenerator copyConvenienceGenerator = this.pluginContext.createCopyGenerator(copyBuilderConvenienceMethod, partial); if (this.implement && !this.definedClass.isAbstract()) { copyBuilderMethod.body()._return(copyGenerator.generatePartialArgs(this.pluginContext._new((JClass)copyBuilderMethod.type()).arg(parentBuilderParam).arg(JExpr._this()).arg(JExpr.TRUE))); copyBuilderConvenienceMethod.body()._return(copyConvenienceGenerator.generatePartialArgs(this.pluginContext.invoke(this.settings.getNewCopyBuilderMethodName()).arg(JExpr._null()))); } if (this.typeOutline.getSuperClass() != null) { copyBuilderMethod.annotate(Override.class); copyBuilderConvenienceMethod.annotate(Override.class); } return copyBuilderMethod; }
JTypeVar $genericParameter = $genMethod.generify("T"); $genMethod.type($genericParameter); JClass baseParameter = methodType == MethodType.CLASS ? codeModel.ref(Class.class)
if (this.implement) { initMethod = this.builderClass.raw.method(JMod.PROTECTED, this.definedClass, PluginContext.INIT_METHOD_NAME); final JTypeVar typeVar = initMethod.generify(BuilderGenerator.PRODUCT_TYPE_PARAMETER_NAME, this.definedClass); initMethod.type(typeVar); productParam = initMethod.param(JMod.FINAL, typeVar, BuilderGenerator.PRODUCT_VAR_NAME);