/** * Creates the getter and setter methods on the supplied class for the supplied name. * * @param clazz to put getter and setter methods on * @param name of the property * @param syntaxType of the property * @param multivalue whether this property is a collection */ protected void createMutators( final JDefinedClass clazz, final String name, final Class<?> syntaxType, final boolean multivalue) { final String upperName = name.substring(0, 1).toUpperCase() + name.substring(1, name.length()); if (multivalue) { final JClass detailClass = codeModel.ref(syntaxType); final JClass collectionClass = codeModel.ref(Collection.class); final JClass genericClass = collectionClass.narrow(detailClass); final JFieldVar field = clazz.field(JMod.PRIVATE, genericClass, name); final JMethod getterMethod = clazz.method(JMod.PUBLIC, genericClass, "get" + upperName); getterMethod.body()._return(field); final JMethod setterMethod = clazz.method(JMod.PUBLIC, Void.TYPE, "set" + upperName); setterMethod.param(genericClass, "c"); setterMethod.body().assign(JExpr._this().ref(name), JExpr.ref("c")); } else { final JFieldVar field = clazz.field(JMod.PRIVATE, syntaxType, name); final JMethod getterMethod = clazz.method(JMod.PUBLIC, syntaxType, "get" + upperName); getterMethod.body()._return(field); final JMethod setterMethod = clazz.method(JMod.PUBLIC, Void.TYPE, "set" + upperName); setterMethod.param(syntaxType, "s"); setterMethod.body().assign(JExpr._this().ref(name), JExpr.ref("s")); } }
private static void generateEnum() throws JClassAlreadyExistsException, IOException { JCodeModel codeModel = new JCodeModel(); JDefinedClass enumClass = codeModel._class("com.foo.Bar", ClassType.ENUM); // This code creates field within the enum class JFieldVar columnField = enumClass.field(JMod.PRIVATE | JMod.FINAL, String.class, "column"); JFieldVar filterableField = enumClass.field(JMod.PRIVATE | JMod.FINAL, codeModel.BOOLEAN, "filterable"); // Define the enum constructor JMethod enumConstructor = enumClass.constructor(JMod.PRIVATE); enumConstructor.param(String.class, "column"); enumConstructor.param(codeModel.BOOLEAN, "filterable"); enumConstructor.body().assign(JExpr._this().ref("column"), JExpr.ref("column")); enumConstructor.body().assign(JExpr._this().ref("filterable"), JExpr.ref("filterable")); JMethod getterColumnMethod = enumClass.method(JMod.PUBLIC, String.class, "getColumn"); getterColumnMethod.body()._return(columnField); JMethod getterFilterMethod = enumClass.method(JMod.PUBLIC, codeModel.BOOLEAN, "isFilterable"); getterFilterMethod.body()._return(filterableField); JEnumConstant enumConst = enumClass.enumConstant("FOO_BAR"); enumConst.arg(JExpr.lit("fooBar")); enumConst.arg(JExpr.lit(true)); codeModel.build(new File("src")); /* * //creating an enum class within our main class JDefinedClass enumClass = * codeModel._class(JMod.PUBLIC, "REPORT_COLUMNS"); //This code creates * field within the enum class JFieldVar columnField = * enumClass.field(JMod.PRIVATE|JMod.FINAL, String.class, "column"); * JFieldVar filterableField = enumClass.field(JMod.PRIVATE|JMod.FINAL, * codeModel.BOOLEAN, "filterable"); */ }
private void createConstructorAndBuilder() { List<ExecutableElement> constructors = new ArrayList<ExecutableElement>(); for (Element e : annotatedElement.getEnclosedElements()) { if (e.getKind() == CONSTRUCTOR) { constructors.add((ExecutableElement) e); } } for (ExecutableElement userConstructor : constructors) { JMethod copyConstructor = generatedClass.constructor(PUBLIC); JMethod staticHelper = generatedClass.method(PUBLIC | STATIC, generatedClass._extends(), "build"); codeModelHelper.generifyStaticHelper(this, staticHelper, getAnnotatedElement()); JBlock body = copyConstructor.body(); JInvocation superCall = body.invoke("super"); JInvocation newInvocation = JExpr._new(generatedClass); for (VariableElement param : userConstructor.getParameters()) { String paramName = param.getSimpleName().toString(); JClass paramType = codeModelHelper.typeMirrorToJClass(param.asType(), this); copyConstructor.param(paramType, paramName); staticHelper.param(paramType, paramName); superCall.arg(JExpr.ref(paramName)); newInvocation.arg(JExpr.ref(paramName)); } JVar newCall = staticHelper.body().decl(generatedClass, "instance", newInvocation); staticHelper.body().invoke(newCall, getOnFinishInflate()); staticHelper.body()._return(newCall); body.invoke(getInit()); } }
private void declareMethod() { method = invoker.method(JMod.PUBLIC | JMod.STATIC, SEXP.class, "doApply"); context = method.param(Context.class, "context"); environment = method.param(Environment.class, "environment"); call = method.param(FunctionCall.class, "call"); argNames = method.param(String[].class, "argNames"); args = method.param(SEXP[].class, "args"); }
public static void addFunctionAsStringGetterSetterDeclaration(JDefinedClass jDefinedClass) { jDefinedClass .method(JMod.NONE, String.class, "getFunctionAsString") .param(String.class, "fieldName"); JMethod setter = jDefinedClass.method(JMod.NONE, jDefinedClass, "setFunctionAsString"); setter.param(String.class, "fieldName"); setter.param(String.class, "functionAsString"); }
public static void addJsonObjectGetterSetterDeclaration(JDefinedClass jDefinedClass) { // getFieldAsJsonObject(String fieldName); jDefinedClass .method(JMod.NONE, String.class, "getFieldAsJsonObject") .param(String.class, "fieldName"); // setFieldAsJsonObject(String fieldName, String fieldValueAsJonObject); JMethod setter = jDefinedClass.method(JMod.NONE, jDefinedClass, "setFieldAsJsonObject"); setter.param(String.class, "fieldName"); setter.param(String.class, "fieldValueAsJonObject"); }
public void addWriteToParcel(JDefinedClass jclass) { JMethod method = jclass.method(JMod.PUBLIC, void.class, "writeToParcel"); JVar dest = method.param(Parcel.class, "dest"); method.param(int.class, "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 static void addSetterDeclaration( Names names, JDefinedClass paramType, JDefinedClass setterReturnType) { JMethod method = setterReturnType.method(JMod.NONE, setterReturnType, names.getSetterName()); method.param(paramType, names.getParamName()); JDocComment javadoc = method.javadoc(); javadoc.append(names.getJavadoc()); }
private void addCreateFromParcel(JDefinedClass jclass, JDefinedClass creatorClass) { JMethod createFromParcel = creatorClass.method(JMod.PUBLIC, jclass, "createFromParcel"); JVar in = createFromParcel.param(Parcel.class, "in"); JVar instance = createFromParcel.body().decl(jclass, "instance", JExpr._new(jclass)); suppressWarnings(createFromParcel, "unchecked"); for (JFieldVar f : jclass.fields().values()) { if ((f.mods().getValue() & JMod.STATIC) == JMod.STATIC) { continue; } if (f.type().erasure().name().equals("List")) { createFromParcel .body() .invoke(in, "readList") .arg(instance.ref(f)) .arg(JExpr.direct(getGenericType(f.type()) + ".class.getClassLoader()")); } else { createFromParcel .body() .assign( instance.ref(f), JExpr.cast( f.type(), in.invoke("readValue") .arg(JExpr.direct(f.type().erasure().name() + ".class.getClassLoader()")))); } } createFromParcel.body()._return(instance); }
private void addParameter( final String name, final AbstractParam parameter, final Class<? extends Annotation> annotationClass, final JMethod method, final JDocComment javadoc) throws Exception { final String argumentName = Names.buildVariableName(name); final JVar argumentVariable = method.param(types.buildParameterType(parameter, argumentName), argumentName); argumentVariable.annotate(annotationClass).param(DEFAULT_ANNOTATION_PARAMETER, name); if (parameter.getDefaultValue() != null) { argumentVariable .annotate(DefaultValue.class) .param(DEFAULT_ANNOTATION_PARAMETER, parameter.getDefaultValue()); } if (context.getConfiguration().isUseJsr303Annotations()) { addJsr303Annotations(parameter, argumentVariable); } addParameterJavaDoc(parameter, argumentVariable.name(), javadoc); }
public void generateQuery(Feed feed) { try { JClass transformedType = getTransformedType(feed); if (transformedType == null) { return; } JDefinedClass cls = pkg._class(JMod.PUBLIC | JMod.FINAL, String.format("%sQuery", feed.getName())); cls._extends(parent.narrow(transformedType)); if (feed.getTitle() != null) { cls.javadoc().add(String.format("<p>%s</p>", feed.getTitle())); } addResourcePath(cls, feed); addResultTypeMethod(model, cls, transformedType); addConstructor(cls); JDefinedClass bldrCls = addBuilderCls(feed, cls); cls.method(JMod.PUBLIC | JMod.STATIC | JMod.FINAL, bldrCls, "builder") .body() ._return(JExpr._new(bldrCls)); JMethod cpyMthd = cls.method(JMod.PROTECTED | JMod.FINAL, cls, "copy"); JVar cpyParam = cpyMthd.param(immutableMap.narrow(String.class, Object.class), "params"); cpyMthd.body()._return(JExpr._new(cls).arg(cpyParam)); } catch (Exception e) { throw new IllegalStateException(e); } }
private void addActionToIntentBuilder( EIntentServiceHolder holder, ExecutableElement executableElement, String methodName, JFieldVar actionKeyField) { JMethod method = holder.getIntentBuilderClass().method(PUBLIC, holder.getIntentBuilderClass(), methodName); JBlock body = method.body(); // setAction body.invoke("action").arg(actionKeyField); // For each method params, we get put value into extras List<? extends VariableElement> methodParameters = executableElement.getParameters(); if (methodParameters.size() > 0) { // Extras params for (VariableElement param : methodParameters) { String paramName = param.getSimpleName().toString(); JClass parameterClass = codeModelHelper.typeMirrorToJClass(param.asType(), holder); JFieldVar paramVar = getStaticExtraField(holder, paramName); JVar methodParam = method.param(parameterClass, paramName); JMethod putExtraMethod = holder.getIntentBuilder().getPutExtraMethod(param.asType(), paramName, paramVar); body.invoke(putExtraMethod).arg(methodParam); } } body._return(JExpr._this()); }
private void addConstructors(JDefinedClass jclass, List<String> properties) { // no properties to put in the constructor => default constructor is good enough. if (properties.isEmpty()) { return; } // add a no-args constructor for serialization purposes JMethod noargsConstructor = jclass.constructor(JMod.PUBLIC); noargsConstructor.javadoc().add("No args constructor for use in serialization"); // add the public constructor with property parameters JMethod fieldsConstructor = jclass.constructor(JMod.PUBLIC); JBlock constructorBody = fieldsConstructor.body(); Map<String, JFieldVar> fields = jclass.fields(); for (String property : properties) { JFieldVar field = fields.get(property); if (field == null) { throw new IllegalStateException( "Property " + property + " hasn't been added to JDefinedClass before calling addConstructors"); } fieldsConstructor.javadoc().addParam(property); JVar param = fieldsConstructor.param(field.type(), field.name()); constructorBody.assign(JExpr._this().ref(field), param); } }
private void genSetListener( Refs r, JDefinedClass clazz, JClass listenerInterface, JFieldVar holdrListener) { if (listenerInterface == null) return; JMethod method = clazz.method(PUBLIC, r.m.VOID, "setListener"); JVar listener = method.param(listenerInterface, "listener"); method.body().assign(holdrListener, listener); }
private void genConstructor( Refs r, JDefinedClass clazz, Collection<Ref> refs, Map<Ref, JFieldVar> fieldVarMap, JFieldVar holderListener, Map<Listener.Type, ListenerType> listenerTypeMap) { // private MyLayoutViewModel(View view) { JMethod constructor = clazz.constructor(PUBLIC); JVar viewVar = constructor.param(r.viewClass, "view"); JBlock body = constructor.body(); // super(view); body.invoke("super").arg(viewVar); // myLinearLayout = (LinearLayout) view.findViewById(R.id.my_linear_layout); // myTextView = (TextView) myLinearLayout.findViewById(R.id.my_text_view); genInitFields(r, fieldVarMap, viewVar, refs, body); // myButton.setOnClickListener((view) -> { if (_holderListener != null) // _holderListener.onMyButtonClick(myButton); }); genListeners(r, fieldVarMap, holderListener, refs, body, listenerTypeMap); JDocComment doc = constructor.javadoc(); doc.append( "Constructs a new {@link me.tatarka.holdr.Holdr} for {@link " + r.packageName + ".R.layout#" + r.layoutName + "}."); doc.addParam(viewVar).append("The root view to search for the holdr's views."); }
public JMethod createOnCreate() { JMethod onCreate = activity.method(JMod.PROTECTED, void.class, "onCreate"); onCreate.annotate(Override.class); JVar sis = onCreate.param(factory.ref(Const.BUNDLE), "savedInstanceState"); onCreate.body().invoke(JExpr._super(), "onCreate").arg(sis); return onCreate; }
/** * Creates the equals method on the supplied class. Leverages {@link * org.ldaptive.LdapUtils#areEqual(Object, Object)}. * * @param clazz to put equals method on */ private void createEquals(final JDefinedClass clazz) { final JClass ldapUtilsClass = codeModel.ref(org.ldaptive.LdapUtils.class); final JInvocation areEqual = ldapUtilsClass.staticInvoke("areEqual"); final JMethod equals = clazz.method(JMod.PUBLIC, boolean.class, "equals"); equals.annotate(java.lang.Override.class); areEqual.arg(JExpr._this()); areEqual.arg(equals.param(Object.class, "o")); equals.body()._return(areEqual); }
private void addPlainBodyArgument( final MimeType bodyMimeType, final JMethod method, final JDocComment javadoc) throws IOException { method.param(types.getRequestEntityClass(bodyMimeType), GENERIC_PAYLOAD_ARGUMENT_NAME); javadoc .addParam(GENERIC_PAYLOAD_ARGUMENT_NAME) .add(getPrefixedExampleOrBlank(bodyMimeType.getExample())); }
public static void addGetterSetterDeclaration( Names names, JClass type, JDefinedClass jDefinedClass) { addGetterDeclaration(names, type, jDefinedClass); JMethod method = jDefinedClass.method(JMod.NONE, jDefinedClass, names.getSetterName()); method.param(type, names.getParamName()); JDocComment javadoc = method.javadoc(); javadoc.append(names.getJavadoc()); }
private void genListeners( Refs r, Map<Ref, JFieldVar> fieldVarMap, JFieldVar holdrListener, Collection<Ref> refs, JBlock body, Map<Listener.Type, ListenerType> listenerTypeMap) { if (holdrListener == null) return; for (Ref ref : refs) { if (ref instanceof View) { JFieldVar fieldVar = fieldVarMap.get(ref); View view = (View) ref; if (view.isNullable) { body = body._if(fieldVar.ne(_null()))._then(); } for (Listener listener : view.listeners) { ListenerType listenerType = listenerTypeMap.get(listener.type); JDefinedClass listenerClass = r.m.anonymousClass(listenerType.classType); JMethod method = listenerClass.method(PUBLIC, listenerType.methodReturn, listenerType.methodName); List<JVar> params = new ArrayList<JVar>(); for (Pair<JType, String> arg : listenerType.methodParams) { JVar param = method.param(arg.first, arg.second); params.add(arg.second.equals("view") ? fieldVar : param); } method.annotate(r.overrideAnnotation); JBlock innerBody = method.body(); JBlock innerIf = innerBody._if(holdrListener.ne(_null()))._then(); JInvocation invokeHoldrListener; if (listenerType.defaultReturn == null) { invokeHoldrListener = innerIf.invoke(holdrListener, listener.name); } else { invokeHoldrListener = holdrListener.invoke(listener.name); innerIf._return(invokeHoldrListener); innerBody._return(listenerType.defaultReturn); } for (JVar param : params) { invokeHoldrListener.arg(param); } body.invoke(fieldVar, listenerType.setter).arg(_new(listenerClass)); } } } }
private static void processAccessors( JFieldVar fieldVar, JDefinedClass packetClass, boolean fromClient) { String name = WordUtils.capitalize(fieldVar.name()); if (fromClient) { String methodName = "get" + name; JMethod getter = packetClass.method(JMod.PUBLIC, fieldVar.type(), methodName); getter.body()._return(fieldVar); } else { String methodName = "set" + name; JMethod setter = packetClass.method(JMod.PUBLIC, Void.TYPE, methodName); setter.param(fieldVar.type(), fieldVar.name()); setter.body().assign(JExpr._this().ref(fieldVar.name()), JExpr.ref(fieldVar.name())); } }
private JClass genListenerInterface( Refs r, JDefinedClass clazz, Collection<Ref> refs, Map<Listener.Type, ListenerType> listenerTypeMap) throws JClassAlreadyExistsException { JDefinedClass listenerInterface = null; for (Ref ref : refs) { if (ref instanceof View) { View view = (View) ref; if (!view.listeners.isEmpty()) { if (listenerInterface == null) { listenerInterface = clazz._interface(PUBLIC, "Listener"); } for (Listener listener : view.listeners) { ListenerType listenerType = listenerTypeMap.get(listener.type); JMethod method = listenerInterface.method(PUBLIC, listenerType.methodReturn, listener.name); for (Pair<JType, String> param : listenerType.methodParams) { if (param.second.equals("view")) { // Replace view with reference to the field. method.param(r.ref(view.type), ref.fieldName); } else { method.param(param.first, param.second); } } } } } } return listenerInterface; }
public void run(Set<ClassOutline> sorted, JDefinedClass transformer) { for (ClassOutline classOutline : sorted) { // skip over abstract classes if (!classOutline.target.isAbstract()) { // add the accept method to the bean JDefinedClass beanImpl = classOutline.implClass; JMethod acceptMethod = beanImpl.method(JMod.PUBLIC, Object.class, "accept"); JTypeVar genericType = acceptMethod.generify("T"); acceptMethod.type(genericType); JVar vizParam = acceptMethod.param(transformer.narrow(genericType), "aTransformer"); JBlock block = acceptMethod.body(); block._return(vizParam.invoke("transform").arg(JExpr._this())); } } }
@SuppressWarnings("deprecation") protected void generateOperationMethod( JDefinedClass serviceCls, String operationName, List<ElementType> inputTypes, Integer overloadCount) throws GenerationException { ElementType outputType1 = this.serviceDefinition.getOutputType(operationName); ElementType outputType = getAdjustedOutputType(outputType1); JType outputJType = getAdjustedJType(outputType); Map<String, JType> inputJTypeMap = new LinkedHashMap<String, JType>(); JMethod method = serviceCls.method(JMod.PUBLIC, outputJType, operationName); for (ElementType inputType : inputTypes) { JType paramJType = getJType(inputType); String paramName = inputType.getName(); method.param(paramJType, paramName); inputJTypeMap.put(paramName, paramJType); } addAdditionalInputParams(method, operationName); JBlock body = method.body(); JTryBlock tryBlock = null; if (this.useNDCLogging) { tryBlock = body._try(); body = tryBlock.body(); body.staticInvoke(this.codeModel.ref(NDC.class), NDC_PUSH) .arg(getClassName() + "." + operationName); } generateOperationMethodBody( method, body, operationName, inputJTypeMap, outputType, outputJType, overloadCount); // salesforce if (this.useNDCLogging) { tryBlock._finally().block().staticInvoke(this.codeModel.ref(NDC.class), NDC_POP); } }
private void setter( JCodeModel codeModel, JDefinedClass clazz, JFieldVar field, String fieldName, String remarks) { // setter JMethod setter = clazz.method(JMod.PUBLIC, codeModel.VOID, "set" + fieldName); JVar param = setter.param(field.type(), toFirstCharLower(fieldName)); // メソッド引数 /* Addign java doc for method */ addMethodDoc(setter, remarks + "設定", param); JBlock block2 = setter.body(); block2.assign(JExpr._this().ref(field), param); // ローカル変数からインスタンス変数へセット }
public static void main(String[] args) throws JClassAlreadyExistsException, IOException { JCodeModel codeModel = new JCodeModel(); Class template = AbstractBaseWrapper.class; String packageName = template.getPackage().getName(); String className = template.getSimpleName().replace("Abstract", "") + "Impl"; JPackage generatedPackage = codeModel._package(packageName); JDefinedClass generatedClass = generatedPackage._class(JMod.FINAL, className); // Creates // a // new // class generatedClass._extends(template); for (Method method : template.getMethods()) { if (Modifier.isAbstract(method.getModifiers())) { System.out.println( "Found abstract method " + Modifier.toString(method.getModifiers()) + " " + method.getName()); JMethod generatedMethod = generatedClass.method(JMod.PUBLIC, method.getReturnType(), method.getName()); for (Parameter parameter : method.getParameters()) { generatedMethod.param(parameter.getModifiers(), parameter.getType(), parameter.getName()); } if (method.getReturnType().equals(Void.TYPE)) { generatedMethod.body().add(generateInvocation(method)); } else { generatedMethod.body()._return(generateInvocation(method)); } } } ByteArrayOutputStream out = new ByteArrayOutputStream(); codeModel.build(new SingleStreamCodeWriter(out)); System.out.println(out); }
private JDefinedClass getMixinEnum(Feed feed) throws JClassAlreadyExistsException { String enumName = camel(feed.getName(), true) + "Mixin"; if (pkg.isDefined(enumName)) { return pkg._getClass(enumName); } JDefinedClass valueEnum = pkg._enum(enumName); JFieldVar valField = valueEnum.field(JMod.PRIVATE | JMod.FINAL, String.class, "value"); JMethod ctor = valueEnum.constructor(JMod.PRIVATE); JVar param = ctor.param(String.class, "val"); ctor.body().assign(valField, param); JMethod toString = valueEnum.method(JMod.PUBLIC, String.class, "toString"); toString.annotate(Override.class); toString.body()._return(valField); return valueEnum; }
private JDefinedClass addBuilderCls(Feed feed, JDefinedClass cls) throws JClassAlreadyExistsException, ClassNotFoundException { JDefinedClass bldrCls = cls._class(JMod.PUBLIC | JMod.STATIC | JMod.FINAL, "Builder"); JVar paramBuilder = bldrCls .field(JMod.PRIVATE | JMod.FINAL, immutableMapBldr, "params") .init(immutableMap.staticInvoke("builder")); for (Filter filter : feed.getFilters().getFilter()) { if (!Boolean.TRUE.equals(filter.isDeprecated())) { addWithersFor(filter, bldrCls, paramBuilder); } } if (feed.getMixins() != null && feed.getMixins().getMixin() != null) { JDefinedClass mixinEnum = getMixinEnum(feed); for (Mixin mixin : feed.getMixins().getMixin()) { String mixinName = mixin.getName().toUpperCase().replace(' ', '_'); JEnumConstant mixinCnst = mixinEnum.enumConstant(mixinName); mixinCnst.arg(JExpr.lit(mixin.getName().replace(' ', '+'))); } JFieldVar field = cls.field(privateStaticFinal, String.class, "MIXIN"); field.init(JExpr.lit("mixin")); JMethod iterWither = bldrCls.method(JMod.PUBLIC, bldrCls, "withMixins"); JVar param = iterWither.param(iterable(mixinEnum), "mixins"); JBlock mthdBody = iterWither.body(); mthdBody.add( paramBuilder .invoke("put") .arg(field) .arg(immutableList.staticInvoke("copyOf").arg(param))); mthdBody._return(JExpr._this()); JMethod varArgWither = bldrCls.method(JMod.PUBLIC, bldrCls, "withMixins"); param = varArgWither.varParam(mixinEnum, "mixins"); varArgWither .body() ._return(JExpr.invoke(iterWither).arg(immutableList.staticInvoke("copyOf").arg(param))); } JMethod bldMthd = bldrCls.method(JMod.PUBLIC, cls, "build"); bldMthd.body()._return(JExpr._new(cls).arg(paramBuilder.invoke("build"))); // TODO: add sorts return bldrCls; }
public XjcGuavaPluginTest() throws Exception { aPackage = aModel._package("test"); aClass = aPackage._class("AClass"); aSetter = aClass.method(JMod.PUBLIC, aModel.VOID, "setField"); aField = aClass.field(JMod.PRIVATE, aModel.INT, "field"); anotherField = aClass.field(JMod.PRIVATE, aModel.BOOLEAN, "anotherField"); aStaticField = aClass.field(JMod.STATIC | JMod.PUBLIC, aModel.SHORT, "staticField"); aGetter = aClass.method(JMod.PUBLIC, aModel.INT, "getField"); aGetter.body()._return(aField); final JVar setterParam = aSetter.param(aModel.INT, "field"); aSetter.body().assign(aField, setterParam); aSuperClass = aPackage._class("ASuperClass"); aClass._extends(aSuperClass); aSuperClassField = aSuperClass.field(JMod.PRIVATE, aModel.DOUBLE, "superClassField"); }
private JDefinedClass createResourceMethodReturnType( final String methodName, final Action action, final JDefinedClass resourceInterface) throws Exception { final JDefinedClass responseClass = resourceInterface ._class(capitalize(methodName) + "Response") ._extends(context.getResponseWrapperType()); final JMethod responseClassConstructor = responseClass.constructor(JMod.PRIVATE); responseClassConstructor.param(javax.ws.rs.core.Response.class, "delegate"); responseClassConstructor.body().invoke("super").arg(JExpr.ref("delegate")); for (final Entry<String, Response> statusCodeAndResponse : action.getResponses().entrySet()) { createResponseBuilderInResourceMethodReturnType(action, responseClass, statusCodeAndResponse); } return responseClass; }