Java Code Examples for com.sun.codemodel.JMethod#type()
The following examples show how to use
com.sun.codemodel.JMethod#type() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuilderGenerator.java From jaxb2-rich-contract-plugin with MIT License | 6 votes |
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; }
Example 2
Source File: CreateVisitableInterface.java From jaxb-visitor with Apache License 2.0 | 6 votes |
@Override protected void run(Set<ClassOutline> classes, Set<JClass> directClasses) { final JDefinedClass _interface = outline.getClassFactory().createInterface(jpackage, "Visitable", null); setOutput( _interface ); final JMethod _method = getOutput().method(JMod.NONE, void.class, "accept"); final JTypeVar returnType = _method.generify("R"); final JTypeVar exceptionType = _method.generify("E", Throwable.class); _method.type(returnType); _method._throws(exceptionType); final JClass narrowedVisitor = visitor.narrow(returnType, exceptionType); _method.param(narrowedVisitor, "aVisitor"); for(ClassOutline classOutline : classes) { classOutline.implClass._implements(getOutput()); } }
Example 3
Source File: OperationProcessor.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 6 votes |
static private JInvocation createSuperInvocation(JDefinedClass clazz, JMethod method){ JInvocation invocation; if(method.type() != null){ invocation = JExpr._super().invoke(method.name()); } else { invocation = JExpr.invoke("super"); } List<JVar> parameters = method.params(); for(JVar parameter : parameters){ invocation.arg(parameter); } return invocation; }
Example 4
Source File: FieldAccessorUtils.java From jaxb2-basics with BSD 2-Clause "Simplified" License | 5 votes |
/** * Returns the <code>setProperty(...)</code> method for the given field * outline or <code>null</code> if no such method exists. * * @param fieldOutline * field outline. * @return The <code>setProperty(...)</code> method for the given field * outline or <code>null</code> if no such method exists. */ public static JMethod setter(FieldOutline fieldOutline) { final JMethod getter = getter(fieldOutline); final JType type = getter != null ? getter.type() : fieldOutline .getRawType(); 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 }); }
Example 5
Source File: SettersPlugin.java From jaxb2-basics with BSD 2-Clause "Simplified" License | 5 votes |
private void generateSetters(ClassOutline classOutline, JDefinedClass theClass) { final FieldOutline[] declaredFields = FieldOutlineUtils.filter( classOutline.getDeclaredFields(), getIgnoring()); for (final FieldOutline fieldOutline : declaredFields) { final String publicName = fieldOutline.getPropertyInfo().getName( true); final String getterName = "get" + publicName; final JMethod getter = theClass.getMethod(getterName, ABSENT); if (getter != null) { final JType type = getter.type(); final JType rawType = fieldOutline.getRawType(); final String setterName = "set" + publicName; final JMethod boxifiedSetter = theClass.getMethod(setterName, new JType[] { rawType.boxify() }); final JMethod unboxifiedSetter = theClass.getMethod(setterName, new JType[] { rawType.unboxify() }); final JMethod setter = boxifiedSetter != null ? boxifiedSetter : unboxifiedSetter; if (setter == null) { final JMethod generatedSetter = theClass.method( JMod.PUBLIC, theClass.owner().VOID, setterName); final JVar value = generatedSetter.param(type, "value"); mode.generateSetter(fieldOutline, theClass, generatedSetter, value); } } } }
Example 6
Source File: BuilderGenerator.java From jaxb2-rich-contract-plugin with MIT License | 5 votes |
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; }
Example 7
Source File: EmbeddableAttributesMapping.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 4 votes |
public boolean isFieldOutlineCore(Mapping context, FieldOutline fieldOutline) { final JMethod getter = FieldAccessorUtils.getter(fieldOutline); final JType type = getter.type(); return JTypeUtils.isBasicType(type); }
Example 8
Source File: AttributesMapping.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 4 votes |
public boolean isFieldOutlineCore(Mapping context, FieldOutline fieldOutline) { final JMethod getter = FieldAccessorUtils.getter(fieldOutline); final JType type = getter.type(); return JTypeUtils.isBasicType(type); }
Example 9
Source File: DefaultAttributeMapping.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 4 votes |
public boolean isTemporal(Mapping context, FieldOutline fieldOutline) { final JMethod getter = FieldAccessorUtils.getter(fieldOutline); final JType type = getter.type(); return JTypeUtils.isTemporalType(type); }
Example 10
Source File: DefaultAttributeMapping.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 4 votes |
public String createTemporalType(Mapping context, FieldOutline fieldOutline) { final JMethod getter = FieldAccessorUtils.getter(fieldOutline); final JType type = getter.type(); final JCodeModel codeModel = type.owner(); // Detect SQL types if (codeModel.ref(java.sql.Time.class).equals(type)) { return "TIME"; } else if (codeModel.ref(java.sql.Date.class).equals(type)) { return "DATE"; } else if (codeModel.ref(java.sql.Timestamp.class).equals(type)) { return "TIMESTAMP"; } else if (codeModel.ref(java.util.Calendar.class).equals(type)) { return "TIMESTAMP"; } else { final List<QName> typeNames; final XSComponent schemaComponent = fieldOutline.getPropertyInfo() .getSchemaComponent(); if (schemaComponent != null) { typeNames = TypeUtils.getTypeNames(schemaComponent); } else { typeNames = Collections.emptyList(); } if (typeNames.contains(XMLSchemaConstrants.DATE_QNAME) || // typeNames.contains(XMLSchemaConstrants.G_YEAR_MONTH_QNAME) || // typeNames.contains(XMLSchemaConstrants.G_YEAR_QNAME) || // typeNames.contains(XMLSchemaConstrants.G_MONTH_QNAME) || // typeNames.contains(XMLSchemaConstrants.G_MONTH_DAY_QNAME) || // typeNames.contains(XMLSchemaConstrants.G_DAY_QNAME)) { return "DATE"; } else if (typeNames.contains(XMLSchemaConstrants.TIME_QNAME)) { return "TIME"; } else if (typeNames.contains(XMLSchemaConstrants.DATE_TIME_QNAME)) { return "TIMESTAMP"; } else { return "TIMESTAMP"; } } }
Example 11
Source File: BuilderGenerator.java From jaxb2-rich-contract-plugin with MIT License | 4 votes |
public void buildProperties() throws SAXException { final TypeOutline superClass = this.typeOutline.getSuperClass(); final JMethod initMethod; final JVar productParam; final JBlock initBody; 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); initBody = initMethod.body(); } else { initMethod = null; initBody = null; productParam = null; } generateDefinedClassJavadoc(); if (this.typeOutline.getDeclaredFields() != null) { for (final PropertyOutline fieldOutline : this.typeOutline.getDeclaredFields()) { if (fieldOutline.hasGetter()) { generateBuilderMember(fieldOutline, initBody, productParam); } } } if (superClass != null) { generateExtendsClause(getBuilderDeclaration(superClass.getImplClass())); if (this.implement) initBody._return(JExpr._super().invoke(initMethod).arg(productParam)); generateBuilderMemberOverrides(superClass); } else if (this.implement) { initBody._return(productParam); } generateImplementsClause(); generateBuildMethod(initMethod); generateCopyToMethod(false); generateNewCopyBuilderMethod(false); if (this.implement && !this.definedClass.isAbstract()) { generateNewBuilderMethod(); generateCopyOfMethod(this.typeOutline, false); } if (this.settings.isGeneratingPartialCopy()) { generateCopyToMethod(true); generateNewCopyBuilderMethod(true); if (this.implement && !this.definedClass.isAbstract()) { final JMethod partialCopyOfMethod = generateCopyOfMethod(this.typeOutline, true); generateConveniencePartialCopyMethod(this.typeOutline, partialCopyOfMethod, this.pluginContext.copyExceptMethodName, this.pluginContext.excludeConst); generateConveniencePartialCopyMethod(this.typeOutline, partialCopyOfMethod, this.pluginContext.copyOnlyMethodName, this.pluginContext.includeConst); } } generateCopyOfBuilderMethods(); }
Example 12
Source File: CreateJAXBElementNameCallback.java From jaxb-visitor with Apache License 2.0 | 4 votes |
private Set<JDefinedClass> identifyCandidates(Outline outline) { // phase one: identify all of the candidates and update the ObjectFactories with the setter call // phase two: only include instances that don't have a JDefinedClass as their super // phase three: add all of the markings JClass qNameClass = outline.getCodeModel().ref(QName.class); Set<JDefinedClass> candidates = new LinkedHashSet<>(); for(PackageOutline po : outline.getAllPackageContexts()) { // locate the object factory JDefinedClass of = outline.getPackageContext(po._package()).objectFactory(); for(JMethod method : of.methods()) { JType retType = method.type(); if (retType.binaryName().startsWith(JAXBElement.class.getName())) { JClass clazz = (JClass) retType; List<JClass> typeParameters = clazz.getTypeParameters(); if (typeParameters.size()==1) { if (typeParameters.get(0) instanceof JDefinedClass && !typeParameters.get(0).isAbstract()) { String namespace = null; String localPart = null; for(JAnnotationUse au : method.annotations()) { if (au.getAnnotationClass().fullName().equals(XmlElementDecl.class.getName())) { namespace = annotationValueToString(au.getAnnotationMembers().get("namespace")); localPart = annotationValueToString(au.getAnnotationMembers().get("name")); break; } } if (namespace != null) { method.body().pos(0); method.body().invoke(method.params().get(0), SETTER) .arg(JExpr._new(qNameClass).arg(namespace).arg(localPart)); } JDefinedClass dc = (JDefinedClass) typeParameters.get(0); candidates.add(dc); } } } } } return candidates; }