Java Code Examples for com.sun.codemodel.JDefinedClass#generify()
The following examples show how to use
com.sun.codemodel.JDefinedClass#generify() .
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: CreateTraverserInterface.java From jaxb-visitor with Apache License 2.0 | 6 votes |
@Override protected void run(Set<ClassOutline> classes, Set<JClass> directClasses) { JDefinedClass scratch = getOutline().getClassFactory().createInterface(getPackage(), "_scratch", null); try { JDefinedClass _interface = getOutline().getClassFactory().createInterface(getPackage(), "Traverser", null); setOutput(_interface); final JTypeVar retType = scratch.generify("?"); final JTypeVar exceptionType = _interface.generify("E", Throwable.class); final JClass narrowedVisitor = visitor.narrow(retType).narrow(exceptionType); for (JClass jc : allConcreteClasses(classes, directClasses)) { implTraverse(exceptionType, narrowedVisitor, jc); } } finally { jpackage.remove(scratch); } }
Example 2
Source File: CreateVisitorInterface.java From jaxb-visitor with Apache License 2.0 | 5 votes |
@Override protected void run(Set<ClassOutline> classes, Set<JClass> directClasses) { final JDefinedClass _interface = outline.getClassFactory().createInterface(jpackage, "Visitor", null); final JTypeVar returnType = _interface.generify("R"); final JTypeVar exceptionType = _interface.generify("E", Throwable.class); setOutput( _interface ); for(JClass jc : allConcreteClasses(classes, directClasses)) { // System.out.println("seeing class:" + jc.name()); declareVisitMethod(returnType, exceptionType, jc); } }
Example 3
Source File: CreateBaseVisitorClass.java From jaxb-visitor with Apache License 2.0 | 5 votes |
@Override protected void run(Set<ClassOutline> classes, Set<JClass> directClasses) { JDefinedClass _class = getOutline().getClassFactory().createClass(getPackage(), "BaseVisitor", null); setOutput(_class); final JTypeVar returnType = _class.generify("R"); final JTypeVar exceptionType = _class.generify("E", Throwable.class); final JClass narrowedVisitor = visitor.narrow(returnType, exceptionType); getOutput()._implements(narrowedVisitor); for(JClass jc : allConcreteClasses(classes, directClasses)) { implementVisitMethod(returnType, exceptionType, jc); } }
Example 4
Source File: GenerifiedClass.java From jaxb2-rich-contract-plugin with MIT License | 4 votes |
public GenerifiedClass(final JDefinedClass definedClass, final String typeParameterName) { this.raw = definedClass; this.typeParam = definedClass.generify(typeParameterName); this.type = definedClass.narrow(this.typeParam); }
Example 5
Source File: SelectorGenerator.java From jaxb2-rich-contract-plugin with MIT License | 4 votes |
private MetaInfoOutline generateMetaClass(final ClassOutline classOutline) { try { final JDefinedClass definedClass = classOutline.implClass; final JDefinedClass selectorClass = definedClass._class(JMod.PUBLIC | JMod.STATIC, this.selectorClassName); final JTypeVar rootTypeParam = selectorClass.generify("TRoot"); final JTypeVar parentTypeParam = selectorClass.generify("TParent"); rootTypeParam.bound(this.pluginContext.codeModel.ref(this.selectorBaseClass).narrow(rootTypeParam, this.pluginContext.codeModel.wildcard())); //parentTypeParam.bound(this.apiConstructs.codeModel.ref(Selector.class).narrow(parentTypeParam, this.apiConstructs.codeModel.wildcard())); final JMethod constructor = selectorClass.constructor(JMod.PUBLIC); final JVar rootParam = constructor.param(JMod.FINAL, rootTypeParam, "root"); final JVar parentParam = constructor.param(JMod.FINAL, parentTypeParam, "parent"); final JVar propertyNameParam = constructor.param(JMod.FINAL, this.pluginContext.stringClass, "propertyName"); if(this.selectorParamName != null) { final JVar includeParam = constructor.param(JMod.FINAL, getSelectorParamType(this.pluginContext.codeModel.wildcard(), definedClass.wildcard()), this.selectorParamName); constructor.body().invoke("super").arg(rootParam).arg(parentParam).arg(propertyNameParam).arg(includeParam); } else { constructor.body().invoke("super").arg(rootParam).arg(parentParam).arg(propertyNameParam); } final JClass productMapType = this.pluginContext.codeModel.ref(Map.class).narrow(String.class).narrow(this.propertyPathClass); final JMethod buildChildrenMethod = selectorClass.method(JMod.PUBLIC, productMapType, "buildChildren"); buildChildrenMethod.annotate(Override.class); final JVar productMapVar = buildChildrenMethod.body().decl(JMod.FINAL, productMapType, "products", JExpr._new(this.pluginContext.codeModel.ref(HashMap.class).narrow(String.class).narrow(this.propertyPathClass))); if(classOutline.getSuperClass() == null ) { selectorClass._extends(this.pluginContext.codeModel.ref(this.selectorBaseClass).narrow(rootTypeParam).narrow(parentTypeParam)); } final JDefinedClass rootSelectorClass = definedClass._class(JMod.PUBLIC | JMod.STATIC, this.rootSelectorClassName); rootSelectorClass._extends(selectorClass.narrow(rootSelectorClass).narrow(Void.class)); final JMethod rootSelectorConstructor = rootSelectorClass.constructor(JMod.NONE); if(this.selectorParamName != null) { final JVar rootSelectorClassIncludeParam = rootSelectorConstructor.param(JMod.FINAL, getSelectorParamType(this.pluginContext.voidClass, definedClass), this.selectorParamName); rootSelectorConstructor.body().invoke("super").arg(JExpr._null()).arg(JExpr._null()).arg(JExpr._null()).arg(rootSelectorClassIncludeParam); } else { rootSelectorConstructor.body().invoke("super").arg(JExpr._null()).arg(JExpr._null()).arg(JExpr._null()); } final JMethod rootMethod = rootSelectorClass.method(JMod.STATIC | JMod.PUBLIC, rootSelectorClass, "_root"); if(this.selectorParamName != null) { final JVar rootIncludeParam = rootMethod.param(JMod.FINAL, getSelectorParamType(this.pluginContext.voidClass, definedClass), this.selectorParamName); rootMethod.body()._return(JExpr._new(rootSelectorClass).arg(rootIncludeParam)); } else { rootMethod.body()._return(JExpr._new(rootSelectorClass)); } return new MetaInfoOutline(this, classOutline, selectorClass, rootTypeParam, parentTypeParam, buildChildrenMethod, productMapVar); } catch (final JClassAlreadyExistsException e) { SelectorGenerator.LOGGER.warning("Attempt to generate already existing class"); return null; } }