Refine search
JMethod noargsConstructor = jclass.constructor(JMod.PUBLIC); noargsConstructor.javadoc().add("No args constructor for use in serialization"); JMethod fieldsConstructor = jclass.constructor(JMod.PUBLIC); JBlock constructorBody = fieldsConstructor.body(); JInvocation superInvocation = constructorBody.invoke("super"); Map<String, JFieldVar> fields = jclass.fields(); Map<String, JVar> classFieldParams = new HashMap<>(); fieldsConstructor.javadoc().addParam(property); JVar param = fieldsConstructor.param(field.type(), field.name()); constructorBody.assign(JExpr._this().ref(field), param); classFieldParams.put(property, param); fieldsConstructor.javadoc().addParam(property); superConstructorParams.add(param);
@Override public JDocComment apply(String nodeName, JsonNode node, JsonNode parent, JDocCommentable generatableType, Schema currentSchema) { JDocComment javaDoc = generatableType.javadoc(); javaDoc.append(String.format("%nCorresponds to the \"%s\" property.", nodeName)); return javaDoc; }
JDocComment comment = cls.javadoc(); if(fault.getJavaDoc() != null){ comment.add(fault.getJavaDoc()); comment.add("\n\n"); comment.add(doc); cls._extends(java.lang.Exception.class); fi.javadoc().add("Java type that goes as soapenv:Fault detail element."); JFieldRef fr = JExpr.ref(JExpr._this(), fi); JVar var1 = constrc1.param(String.class, "message"); JVar var2 = constrc1.param(faultBean, "faultInfo"); constrc1.javadoc().addParam(var1); constrc1.javadoc().addParam(var2); JBlock cb1 = constrc1.body(); cb1.invoke("super").arg(var1); cb1.assign(fr, var2); constrc2.javadoc().addParam(var1); constrc2.javadoc().addParam(var2); constrc2.javadoc().addParam(var3); JBlock cb2 = constrc2.body(); cb2.invoke("super").arg(var1).arg(var3); fim.javadoc().addReturn().add("returns fault bean: "+faultBean.fullName());
JMethod m = objectFactory.method( JMod.PUBLIC, sigType, "create" + cc.target.getSqueezedName() ); m.body()._return( JExpr._new(cc.implRef) ); m.javadoc() .append("Create an instance of ") .append(cc.ref); cc.implClass.constructor(JMod.PUBLIC); JMethod m = objectFactory.method( JMod.PUBLIC, cc.ref, "create" + cc.target.getSqueezedName() ); JInvocation inv = JExpr._new(cc.implRef); m.body()._return(inv); m.javadoc() .append( "Create an instance of " ) .append( cc.ref ) .addThrows(JAXBException.class).append("if an error occurs"); FieldAccessor accessor = fo.create(JExpr._this());
private JMethod addConstructorFromStringWithCustomClient(final JDefinedClass builder, final String baseUriInputParam, final String clientInputParam) { final JMethod constructor = builder.constructor(JMod.PUBLIC); constructor.param(JMod.FINAL, String.class, baseUriInputParam); constructor.param(JMod.FINAL, Client.class, clientInputParam); constructor .body() .invoke(THIS_KEYWORD) .arg(JExpr.ref(baseUriInputParam)) .arg(JExpr.ref(clientInputParam)) .arg(JExpr._new(builder.owner().ref(RequestParams.class))); // attach the Javadoc constructor.javadoc().append(JavaDocs.DOCS_CONSTRUCTOR_2.fillTemplate(builder.name())); return constructor; }
private JMethod generateCopyConstructor( final ClassOutline clazz ) ctor.javadoc().add( "Creates a new {@code " + clazz.implClass.name() + "} instance by deeply copying a given {@code " + paramClass.name() + "} instance.\n" ); ctor.javadoc().addParam( o ).add( "The instance to copy." ); ctor.javadoc().addThrows( NullPointerException.class ).append( "if {@code o} is {@code null}." ); ctor.javadoc().addParam( o ).add( "The instance to copy or {@code null}." ); ctor.body().directStatement( "// " + getMessage( "title" ) ); ctor.body().directStatement( "// " + WARNING_PREFIX + ": A super-class of this class was not part of the compilation unit." ); || ( clazz.implClass._extends() != null && !clazz.implClass._extends().binaryName().equals( "java.lang.Object" ) ) ) final JBlock copyBlock = new JBlock( false, false ); final JExpression source = superTypeParam ? JExpr.cast( clazz.implClass, o ) : o; if ( fieldOutline == null ) if ( field.type().isPrimitive() ) copyBlock.directStatement( "// Unknown primitive field '" + field.name() + "'." );
private void writeMember(JDefinedClass cls, TypeMirror paramType, String paramName) { if (cls == null) return; String accessorName =BindingHelper.mangleNameToPropertyName(paramName); String getterPrefix = paramType.toString().equals("boolean")? "is" : "get"; JType propType = getType(paramType); JMethod m = cls.method(JMod.PUBLIC, propType, getterPrefix+ accessorName); JDocComment methodDoc = m.javadoc(); JCommentPart ret = methodDoc.addReturn(); ret.add("returns "+propType.name()); JBlock body = m.body(); body._return( JExpr._this().ref(paramName) ); m = cls.method(JMod.PUBLIC, cm.VOID, "set"+accessorName); JVar param = m.param(propType, paramName); methodDoc = m.javadoc(); JCommentPart part = methodDoc.addParam(paramName); part.add("the value for the "+ paramName+" property"); body = m.body(); body.assign( JExpr._this().ref(paramName), param ); } }
return; cls._implements(portCls); cls.constructor(JMod.PUBLIC); JDocComment comment = cls.javadoc(); comment.add(service.getJavaDoc()); comment.add("\n\n"); comment.add(doc); methodDoc = m.javadoc(); } else { methodDoc = m.javadoc(); JCommentPart ret = methodDoc.addReturn(); ret.add("returns " + retType.getName()); methodDoc.add(methodJavaDoc); methodDoc.addParam(var); methodDoc.addThrows(fault.getExceptionClass()); wsdlOp.putFault(fault.getWsdlFaultName(), fault.getExceptionClass());
private void writeGetPort(Port port, JType retType, JDefinedClass cls) { JMethod m = cls.method(JMod.PUBLIC, retType, port.getPortGetter()); JDocComment methodDoc = m.javadoc(); if (port.getJavaDoc() != null) { methodDoc.add(port.getJavaDoc()); } JCommentPart ret = methodDoc.addReturn(); JCommentPart paramDoc = methodDoc.addParam("features"); paramDoc.append("A list of "); paramDoc.append("{@link " + WebServiceFeature.class.getName() + "}"); paramDoc.append("to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values."); ret.add("returns " + retType.name()); m.varParam(WebServiceFeature.class, "features"); JBlock body = m.body(); StringBuilder statement = new StringBuilder("return "); statement.append("super.getPort(new QName(\"").append(port.getName().getNamespaceURI()).append("\", \"").append(port.getName().getLocalPart()).append("\"), "); statement.append(retType.name()); statement.append(".class, features);"); body.directStatement(statement.toString()); writeWebEndpoint(port, m); }
private void replaceCollectionGetter(FieldOutline field, final JMethod getter) { JDefinedClass clazz = field.parent().implClass; // remove the old getter clazz.methods().remove(getter); // and create a new one JMethod newGetter = field.parent().implClass.method(getter.mods().getValue(), getter.type(), getter.name()); JBlock block = newGetter.body(); JVar ret = block.decl(getJavaType(field), "ret"); JCodeModel codeModel = field.parent().implClass.owner(); JVar param = generateMethodParameter(getter, field); JConditional conditional = block._if(param.eq(JExpr._null())); conditional._then().assign(ret, getEmptyCollectionExpression(codeModel, param)); conditional._else().assign(ret, getUnmodifiableWrappedExpression(codeModel, param)); block._return(ret); getter.javadoc().append("Returns unmodifiable collection."); }
private void writeDefaultGetPort(Port port, JType retType, JDefinedClass cls) { String portGetter = port.getPortGetter(); JMethod m = cls.method(JMod.PUBLIC, retType, portGetter); JDocComment methodDoc = m.javadoc(); if (port.getJavaDoc() != null) { methodDoc.add(port.getJavaDoc()); } JCommentPart ret = methodDoc.addReturn(); ret.add("returns " + retType.name()); JBlock body = m.body(); StringBuilder statement = new StringBuilder("return "); statement.append("super.getPort(new QName(\"").append(port.getName().getNamespaceURI()).append("\", \"").append(port.getName().getLocalPart()).append("\"), "); statement.append(retType.name()); statement.append(".class);"); body.directStatement(statement.toString()); writeWebEndpoint(port, m); }
String typeName = type.fullName(); JMethod method = dc.getMethod(getterName, new JType[0]); JType mtype = method.type(); String setterName = "set" + fo.getPropertyInfo().getName(true); method = dc.getMethod(setterName, new JType[] {mtype}); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Updating setter: " + setterName); JDocComment doc = method.javadoc(); dc.methods().remove(method); int mods = method.mods().getValue(); mtype = mtype.unboxify(); method = dc.method(mods, method.type(), setterName); method.javadoc().append(doc); method.param(mtype, "value"); JFieldRef fr = JExpr.ref(fieldName); method.body().assign(fr, JExpr.ref("value")); method = dc.method(mods, method.type(), "unset" + fo.getPropertyInfo().getName(true)); method.body().assign(fr, JExpr._null()); method = dc.getMethod("isSet" + fo.getPropertyInfo().getName(true), new JType[0]);
String typeName = type.fullName(); JMethod method = dc.getMethod(getterName, new JType[0]); JDocComment doc = method.javadoc(); int mods = method.mods().getValue(); JType mtype = method.type(); if (remapRet) { mtype = mtype.unboxify(); dc.methods().remove(method); method = dc.method(mods, mtype, getterName); method.javadoc().append(doc); JFieldRef fr = JExpr.ref(fieldName); if (dvExpr != null) { JExpression test = JOp.eq(JExpr._null(), fr); JConditional jc = method.body()._if(test); jc._then()._return(dvExpr); jc._else()._return(fr); } else { method.body()._return(fr);
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 createCallbackMethod(final Status responseStatus, final JDefinedClass builder) { final String methodName = JavaNameUtils.buildErrorCallbackMethodName(responseStatus); final JMethod callbackMethod = builder.method(JMod.PUBLIC, builder, methodName); final JVar callbackVar = callbackMethod.param(ResponseCallback.class, "callback"); // Generates this kind of code: "return this.withCallbackForCode(responseStatus.getStatusCode(), callback);" final JInvocation withCallbackForCodeInvocation = JExpr._this() .invoke("withCallbackForCode") .arg(JExpr.lit(responseStatus.getStatusCode())) .arg(callbackVar); callbackMethod.body()._return(withCallbackForCodeInvocation); // attach the Javadoc callbackMethod.javadoc().append( JavaDocs.METHOD_ERROR_CALLBACK.fillTemplate(responseStatus.getStatusCode(), responseStatus.getReasonPhrase())); return callbackMethod; }
JClass nameClazz = (clazz.implClass).owner().ref(name); JMethod getter = (clazz.implClass).method(JMod.PUBLIC, nameClazz, "get" + propertyName); getter.javadoc().append("Gets the value of the " + property + " property.").addThrows(exceptionClazz).append("Always."); getter.annotate(Override.class); getter.body()._throw(JExpr._new(exceptionClazz)); JMethod setter = (clazz.implClass).method(JMod.PUBLIC, void.class, "set" + propertyName); setter.javadoc().append("Sets the value of the " + property + " property.").addThrows(exceptionClazz).append("Always."); setter.annotate(Override.class); setter.param(nameClazz, property); setter.body()._throw(JExpr._new(exceptionClazz));
/** * {@inheritDoc} * <p/> * This implementation adds accessor methods to the {@code builderForParent} class. These accessor methods create a * new instane of the procreated {@code builder} based on the state of the {@code builderForParent}. The name of the * accessor method will be based on the HTTP method that is declared in the {@code ramlAction}. */ @Override protected void createHooksInParentBuilder( final Action ramlAction, final JDefinedClass builderForParent, final JDefinedClass builder, final Context<Object, JDeclaration> context ) { final String hookMethodName = JavaNameUtils.buildActionBuilderMethodName(ramlAction); final JMethod hookMethod = builderForParent.method(JMod.PUBLIC, builder, hookMethodName); final JBlock hookMethodBody = hookMethod.body(); hookMethodBody._return(JExpr._new(builder).arg(JExpr.invoke("getTarget")).arg(JExpr.invoke("getRequestParams"))); // attach the Javadoc hookMethod.javadoc().append(JavaDocs.METHOD_PREPARE_ACTION.fillTemplate(ActionBuilder.class.getCanonicalName(), ramlAction.getType() != null ? ramlAction.getType() : "any", builder.name())); }
void generateCopyConstructor(final boolean partial) { final JDefinedClass definedClass = this.classOutline.implClass; final JMethod constructor = definedClass.constructor(definedClass.isAbstract() ? JMod.PROTECTED : JMod.PUBLIC); final JVar otherParam = constructor.param(JMod.FINAL, this.classOutline.implClass, DeepCopyGenerator.OTHER_PARAM_NAME); final CopyGenerator cloneGenerator = this.pluginContext.createCopyGenerator(constructor, partial); final JDocComment docComment = constructor.javadoc(); docComment.append(getMessage("copyConstructor.javadoc.desc", definedClass.name())); docComment.addParam(otherParam).append(getMessage("copyConstructor.javadoc.param.other", definedClass.name())); if(partial) { docComment.addParam(cloneGenerator.getPropertyTreeParam()).append(getMessage("copyConstructor.javadoc.param.propertyPath", definedClass.name())); docComment.addParam(cloneGenerator.getPropertyTreeUseParam()).append(getMessage("copyConstructor.javadoc.param.propertyPathUse", definedClass.name())); } if (this.classOutline.getSuperClass() != null) { constructor.body().add(cloneGenerator.generatePartialArgs(this.pluginContext._super().arg(otherParam))); } final JBlock body = constructor.body(); generateFieldCopyExpressions(cloneGenerator, body, JExpr._this(), otherParam); }
private JMethod generateGetterMethod(JFieldVar field, String fieldName, JExpression defaultValue) { String javaName = NamingHelper.convertToClassName(fieldName); // Add get method JMethod getter = this.pojo.method(JMod.PUBLIC, field.type(), "get" + javaName); if (defaultValue != null) { JBlock body = getter.body(); body._if(field.eq(JExpr._null()))._then()._return(defaultValue); } getter.body()._return(field); getter.javadoc().add("Returns the " + fieldName + "."); getter.javadoc().addReturn().add(field.name()); return getter; }
private void addToStringMethod(ClassOutline co, JClass delegateImpl, JFieldRef toStringDelegateStyleParam) { final JDefinedClass implementation = co.implClass; final JMethod toStringMethod = implementation.method(JMod.PUBLIC, String.class, "toString"); final JInvocation invoke = delegateImpl.staticInvoke("reflectionToString"); invoke.arg(JExpr._this()); invoke.arg(toStringDelegateStyleParam); toStringMethod.body()._return(invoke); JDocComment doc = toStringMethod.javadoc(); doc.add("Generates a String representation of the contents of this type."); doc.add("\nThis is an extension method, produced by the 'ts' xjc plugin"); toStringMethod.annotate(Override.class); }