com.sun.codemodel.internal.JClass Java Examples
The following examples show how to use
com.sun.codemodel.internal.JClass.
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: CAdapter.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
static NClass getRef( final Class<? extends XmlAdapter> adapter, boolean copy ) { if(copy) { // TODO: this is a hack. the code generation should be defered until // the backend. (right now constant generation happens in the front-end) return new EagerNClass(adapter) { @Override public JClass toType(Outline o, Aspect aspect) { return o.addRuntime(adapter); } public String fullName() { // TODO: implement this method later throw new UnsupportedOperationException(); } }; } else { return NavigatorImpl.theInstance.ref(adapter); } }
Example #2
Source File: ElementCollectionAdapter.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) { JCodeModel cm = outline().getCodeModel(); JClass elementType = ei.toType(outline(),EXPOSED).boxify(); // [RESULT] // $t = new ArrayList(); // for( Type e : $var ) { // $var.add(new JAXBElement(e)); // } // [core.fromRawValue] JClass col = cm.ref(ArrayList.class).narrow(elementType); JVar $t = block.decl(col,uniqueName+"_col",JExpr._new(col)); JForEach loop = block.forEach(itemType(), uniqueName+"_i", $t); loop.body().invoke($var,"add").arg(createJAXBElement(loop.var())); acc.fromRawValue(block, uniqueName, $t); }
Example #3
Source File: BeanGenerator.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Generates the minimum {@link JDefinedClass} skeleton * without filling in its body. */ private ClassOutlineImpl generateClassDef(CClassInfo bean) { ImplStructureStrategy.Result r = model.strategy.createClasses(this, bean); JClass implRef; if (bean.getUserSpecifiedImplClass() != null) { // create a place holder for a user-specified class. JDefinedClass usr; try { usr = codeModel._class(bean.getUserSpecifiedImplClass()); // but hide that file so that it won't be generated. usr.hide(); } catch (JClassAlreadyExistsException e) { // it's OK for this to collide. usr = e.getExistingClass(); } usr._extends(r.implementation); implRef = usr; } else { implRef = r.implementation; } return new ClassOutlineImpl(this, bean, r.exposed, r.implementation, implRef); }
Example #4
Source File: ElementCollectionAdapter.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) { JCodeModel cm = outline().getCodeModel(); JClass elementType = ei.toType(outline(),EXPOSED).boxify(); // [RESULT] // $t = new ArrayList(); // for( Type e : $var ) { // $var.add(new JAXBElement(e)); // } // [core.fromRawValue] JClass col = cm.ref(ArrayList.class).narrow(elementType); JVar $t = block.decl(col,uniqueName+"_col",JExpr._new(col)); JForEach loop = block.forEach(itemType(), uniqueName+"_i", $t); loop.body().invoke($var,"add").arg(createJAXBElement(loop.var())); acc.fromRawValue(block, uniqueName, $t); }
Example #5
Source File: BindInfo.java From hottub with GNU General Public License v2.0 | 6 votes |
/** Gets the xjc:superClass customization if it's turned on. */ public JClass getSuperClass() { Element sc = DOMUtil.getElement(dom,XJC_NS,"superClass"); if (sc == null) return null; JDefinedClass c; try { String v = DOMUtil.getAttribute(sc,"name"); if(v==null) return null; c = codeModel._class(v); c.hide(); } catch (JClassAlreadyExistsException e) { c = e.getExistingClass(); } return c; }
Example #6
Source File: BeanGenerator.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public JClass generateStaticClass(Class src, JPackage out) { String shortName = getShortName(src.getName()); // some people didn't like our jars to contain files with .java extension, // so when we build jars, we'' use ".java_". But when we run from the workspace, // we want the original source code to be used, so we check both here. // see bug 6211503. URL res = src.getResource(shortName + ".java"); if (res == null) { res = src.getResource(shortName + ".java_"); } if (res == null) { throw new InternalError("Unable to load source code of " + src.getName() + " as a resource"); } JStaticJavaFile sjf = new JStaticJavaFile(out, shortName, res, null); out.addResourceFile(sjf); return sjf.getJClass(); }
Example #7
Source File: BindInfo.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** Gets the xjc:superClass customization if it's turned on. */ public JClass getSuperClass() { Element sc = DOMUtil.getElement(dom,XJC_NS,"superClass"); if (sc == null) return null; JDefinedClass c; try { String v = DOMUtil.getAttribute(sc,"name"); if(v==null) return null; c = codeModel._class(v); c.hide(); } catch (JClassAlreadyExistsException e) { c = e.getExistingClass(); } return c; }
Example #8
Source File: BeanGenerator.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public JClass generateStaticClass(Class src, JPackage out) { String shortName = getShortName(src.getName()); // some people didn't like our jars to contain files with .java extension, // so when we build jars, we'' use ".java_". But when we run from the workspace, // we want the original source code to be used, so we check both here. // see bug 6211503. URL res = src.getResource(shortName + ".java"); if (res == null) { res = src.getResource(shortName + ".java_"); } if (res == null) { throw new InternalError("Unable to load source code of " + src.getName() + " as a resource"); } JStaticJavaFile sjf = new JStaticJavaFile(out, shortName, res, null); out.addResourceFile(sjf); return sjf.getJClass(); }
Example #9
Source File: ElementCollectionAdapter.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public void toRawValue(JBlock block, JVar $var) { JCodeModel cm = outline().getCodeModel(); JClass elementType = ei.toType(outline(),EXPOSED).boxify(); // [RESULT] // $var = new ArrayList(); // for( JAXBElement e : [core.toRawValue] ) { // if(e==null) // $var.add(null); // else // $var.add(e.getValue()); // } block.assign($var,JExpr._new(cm.ref(ArrayList.class).narrow(itemType().boxify()))); JVar $col = block.decl(core.getRawType(), "col" + hashCode()); acc.toRawValue(block,$col); JForEach loop = block.forEach(elementType, "v" + hashCode()/*unique string handling*/, $col); JConditional cond = loop.body()._if(loop.var().eq(JExpr._null())); cond._then().invoke($var,"add").arg(JExpr._null()); cond._else().invoke($var,"add").arg(loop.var().invoke("getValue")); }
Example #10
Source File: BeanGenerator.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Generates an attribute wildcard property on a class. */ private void generateAttributeWildcard(ClassOutlineImpl cc) { String FIELD_NAME = "otherAttributes"; String METHOD_SEED = model.getNameConverter().toClassName(FIELD_NAME); JClass mapType = codeModel.ref(Map.class).narrow(QName.class, String.class); JClass mapImpl = codeModel.ref(HashMap.class).narrow(QName.class, String.class); // [RESULT] // Map<QName,String> m = new HashMap<QName,String>(); JFieldVar $ref = cc.implClass.field(JMod.PRIVATE, mapType, FIELD_NAME, JExpr._new(mapImpl)); $ref.annotate2(XmlAnyAttributeWriter.class); MethodWriter writer = cc.createMethodWriter(); JMethod $get = writer.declareMethod(mapType, "get" + METHOD_SEED); $get.javadoc().append( "Gets a map that contains attributes that aren't bound to any typed property on this class.\n\n" + "<p>\n" + "the map is keyed by the name of the attribute and \n" + "the value is the string value of the attribute.\n" + "\n" + "the map returned by this method is live, and you can add new attribute\n" + "by updating the map directly. Because of this design, there's no setter.\n"); $get.javadoc().addReturn().append("always non-null"); $get.body()._return($ref); }
Example #11
Source File: NParameterizedType.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public JClass toType(Outline o, Aspect aspect) { JClass r = rawType.toType(o,aspect); for( NType arg : args ) r = r.narrow(arg.toType(o,aspect).boxify()); return r; }
Example #12
Source File: BeanGenerator.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Generates an attribute wildcard property on a class. */ private void generateAttributeWildcard(ClassOutlineImpl cc) { String FIELD_NAME = "otherAttributes"; String METHOD_SEED = model.getNameConverter().toClassName(FIELD_NAME); JClass mapType = codeModel.ref(Map.class).narrow(QName.class, String.class); JClass mapImpl = codeModel.ref(HashMap.class).narrow(QName.class, String.class); // [RESULT] // Map<QName,String> m = new HashMap<QName,String>(); JFieldVar $ref = cc.implClass.field(JMod.PRIVATE, mapType, FIELD_NAME, JExpr._new(mapImpl)); $ref.annotate2(XmlAnyAttributeWriter.class); MethodWriter writer = cc.createMethodWriter(); JMethod $get = writer.declareMethod(mapType, "get" + METHOD_SEED); $get.javadoc().append( "Gets a map that contains attributes that aren't bound to any typed property on this class.\n\n" + "<p>\n" + "the map is keyed by the name of the attribute and \n" + "the value is the string value of the attribute.\n" + "\n" + "the map returned by this method is live, and you can add new attribute\n" + "by updating the map directly. Because of this design, there's no setter.\n"); $get.javadoc().addReturn().append("always non-null"); $get.body()._return($ref); }
Example #13
Source File: SignatureWriter.java From hottub with GNU General Public License v2.0 | 5 votes |
private void dump( ClassOutline ci ) throws IOException { JDefinedClass cls = ci.implClass; StringBuilder buf = new StringBuilder(); buf.append("interface "); buf.append(cls.name()); boolean first=true; Iterator itr = cls._implements(); while(itr.hasNext()) { if(first) { buf.append(" extends "); first=false; } else { buf.append(", "); } buf.append( printName((JClass)itr.next()) ); } buf.append(" {"); println(buf.toString()); indent++; // dump the field for( FieldOutline fo : ci.getDeclaredFields() ) { String type = printName(fo.getRawType()); println(type+' '+fo.getPropertyInfo().getName(true)+';'); } dumpChildren(cls); indent--; println("}"); }
Example #14
Source File: NoExtendedContentField.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * @param coreList * A concrete class that implements the List interface. * An instance of this class will be used to store data * for this field. */ protected NoExtendedContentField(ClassOutlineImpl context, CPropertyInfo prop, JClass coreList) { // the JAXB runtime picks ArrayList if the signature is List, // so don't do eager allocation if it's ArrayList. // otherwise we need to do eager allocation so that the collection type specified by the user // will be used. super(context, prop, false); this.coreList = coreList; generate(); }
Example #15
Source File: CClassInfo.java From hottub with GNU General Public License v2.0 | 5 votes |
public final JClass toType(Outline o, Aspect aspect) { switch(aspect) { case IMPLEMENTATION: return o.getClazz(this).implRef; case EXPOSED: return o.getClazz(this).ref; default: throw new IllegalStateException(); } }
Example #16
Source File: SignatureWriter.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private void dump( ClassOutline ci ) throws IOException { JDefinedClass cls = ci.implClass; StringBuilder buf = new StringBuilder(); buf.append("interface "); buf.append(cls.name()); boolean first=true; Iterator itr = cls._implements(); while(itr.hasNext()) { if(first) { buf.append(" extends "); first=false; } else { buf.append(", "); } buf.append( printName((JClass)itr.next()) ); } buf.append(" {"); println(buf.toString()); indent++; // dump the field for( FieldOutline fo : ci.getDeclaredFields() ) { String type = printName(fo.getRawType()); println(type+' '+fo.getPropertyInfo().getName(true)+';'); } dumpChildren(cls); indent--; println("}"); }
Example #17
Source File: SignatureWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void dump( ClassOutline ci ) throws IOException { JDefinedClass cls = ci.implClass; StringBuilder buf = new StringBuilder(); buf.append("interface "); buf.append(cls.name()); boolean first=true; Iterator itr = cls._implements(); while(itr.hasNext()) { if(first) { buf.append(" extends "); first=false; } else { buf.append(", "); } buf.append( printName((JClass)itr.next()) ); } buf.append(" {"); println(buf.toString()); indent++; // dump the field for( FieldOutline fo : ci.getDeclaredFields() ) { String type = printName(fo.getRawType()); println(type+' '+fo.getPropertyInfo().getName(true)+';'); } dumpChildren(cls); indent--; println("}"); }
Example #18
Source File: UntypedListField.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * @param coreList * A concrete class that implements the List interface. * An instance of this class will be used to store data * for this field. */ protected UntypedListField(ClassOutlineImpl context, CPropertyInfo prop, JClass coreList) { // the JAXB runtime picks ArrayList if the signature is List, // so don't do eager allocation if it's ArrayList. // otherwise we need to do eager allocation so that the collection type specified by the user // will be used. super(context, prop, !coreList.fullName().equals("java.util.ArrayList")); this.coreList = coreList.narrow(exposedType.boxify()); generate(); }
Example #19
Source File: BIContent.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Gets the type of this property, if any. * <p> * <element-ref> particle doesn't have the type. * * @return * null if none is specified. */ public final JClass getType() { try { String type = DOMUtil.getAttribute(element,"supertype"); if(type==null) return null; // TODO: does this attribute defaults to the current package? int idx = type.lastIndexOf('.'); if(idx<0) return parent.parent.codeModel.ref(type); else return parent.parent.getTargetPackage().ref(type); } catch( ClassNotFoundException e ) { // TODO: better error handling throw new NoClassDefFoundError(e.getMessage()); } }
Example #20
Source File: AsyncOperation.java From hottub with GNU General Public License v2.0 | 5 votes |
public JavaType getResponseBeanJavaType(){ JCodeModel cm = _responseBean.getJavaType().getType().getType().owner(); if(_asyncOpType.equals(AsyncOperationType.CALLBACK)){ JClass future = cm.ref(java.util.concurrent.Future.class).narrow(cm.ref(Object.class).wildcard()); return new JavaSimpleType(new JAXBTypeAndAnnotation(future)); }else if(_asyncOpType.equals(AsyncOperationType.POLLING)){ JClass polling = cm.ref(javax.xml.ws.Response.class).narrow(_responseBean.getJavaType().getType().getType().boxify()); return new JavaSimpleType(new JAXBTypeAndAnnotation(polling)); } return null; }
Example #21
Source File: BeanGenerator.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public final JClass addRuntime(Class clazz) { JClass g = generatedRuntime.get(clazz); if (g == null) { // put code into a separate package to avoid name conflicts. JPackage implPkg = getUsedPackages(Aspect.IMPLEMENTATION)[0].subPackage("runtime"); g = generateStaticClass(clazz, implPkg); generatedRuntime.put(clazz, g); } return g; }
Example #22
Source File: JAXBModelImpl.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public List<JClass> getAllObjectFactories() { List<JClass> r = new ArrayList<JClass>(); for (PackageOutline pkg : outline.getAllPackageContexts()) { r.add(pkg.objectFactory()); } return r; }
Example #23
Source File: CEnumLeafInfo.java From hottub with GNU General Public License v2.0 | 5 votes |
public JExpression createConstant(Outline outline, XmlString literal) { // correctly identifying which constant it maps to is hard, so // here I'm cheating JClass type = toType(outline,Aspect.EXPOSED); for (CEnumConstant mem : members) { if(mem.getLexicalValue().equals(literal.value)) return type.staticRef(mem.getName()); } return null; }
Example #24
Source File: TypeUtil.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private static JClass pickOne(Set<JClass> s) { // we may have more than one candidates at this point. // any user-defined generated types should have // precedence over system-defined existing types. // // so try to return such a type if any. for (JClass c : s) if (c instanceof JDefinedClass) return c; // we can do more if we like. for example, // we can avoid types in the RI runtime. // but for now, just return the first one. return s.iterator().next(); }
Example #25
Source File: AsyncOperation.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public JavaType getResponseBeanJavaType(){ JCodeModel cm = _responseBean.getJavaType().getType().getType().owner(); if(_asyncOpType.equals(AsyncOperationType.CALLBACK)){ JClass future = cm.ref(java.util.concurrent.Future.class).narrow(cm.ref(Object.class).wildcard()); return new JavaSimpleType(new JAXBTypeAndAnnotation(future)); }else if(_asyncOpType.equals(AsyncOperationType.POLLING)){ JClass polling = cm.ref(javax.xml.ws.Response.class).narrow(_responseBean.getJavaType().getType().getType().boxify()); return new JavaSimpleType(new JAXBTypeAndAnnotation(polling)); } return null; }
Example #26
Source File: CEnumLeafInfo.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public JExpression createConstant(Outline outline, XmlString literal) { // correctly identifying which constant it maps to is hard, so // here I'm cheating JClass type = toType(outline,Aspect.EXPOSED); for (CEnumConstant mem : members) { if(mem.getLexicalValue().equals(literal.value)) return type.staticRef(mem.getName()); } return null; }
Example #27
Source File: UntypedListField.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * @param coreList * A concrete class that implements the List interface. * An instance of this class will be used to store data * for this field. */ protected UntypedListField(ClassOutlineImpl context, CPropertyInfo prop, JClass coreList) { // the JAXB runtime picks ArrayList if the signature is List, // so don't do eager allocation if it's ArrayList. // otherwise we need to do eager allocation so that the collection type specified by the user // will be used. super(context, prop, !coreList.fullName().equals("java.util.ArrayList")); this.coreList = coreList.narrow(exposedType.boxify()); generate(); }
Example #28
Source File: AsyncOperation.java From hottub with GNU General Public License v2.0 | 5 votes |
public JavaType getCallBackType(){ if(_asyncOpType.equals(AsyncOperationType.CALLBACK)){ JCodeModel cm = _responseBean.getJavaType().getType().getType().owner(); JClass cb = cm.ref(javax.xml.ws.AsyncHandler.class).narrow(_responseBean.getJavaType().getType().getType().boxify()); return new JavaSimpleType(new JAXBTypeAndAnnotation(cb)); } return null; }
Example #29
Source File: DummyListField.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * @param coreList * A concrete class that implements the List interface. * An instance of this class will be used to store data * for this field. */ protected DummyListField(ClassOutlineImpl context, CPropertyInfo prop, JClass coreList) { // the JAXB runtime picks ArrayList if the signature is List, // so don't do eager allocation if it's ArrayList. // otherwise we need to do eager allocation so that the collection type specified by the user // will be used. super(context, prop, !coreList.fullName().equals("java.util.ArrayList")); this.coreList = coreList.narrow(exposedType.boxify()); generate(); }
Example #30
Source File: SignatureWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private void dump( ClassOutline ci ) throws IOException { JDefinedClass cls = ci.implClass; StringBuilder buf = new StringBuilder(); buf.append("interface "); buf.append(cls.name()); boolean first=true; Iterator itr = cls._implements(); while(itr.hasNext()) { if(first) { buf.append(" extends "); first=false; } else { buf.append(", "); } buf.append( printName((JClass)itr.next()) ); } buf.append(" {"); println(buf.toString()); indent++; // dump the field for( FieldOutline fo : ci.getDeclaredFields() ) { String type = printName(fo.getRawType()); println(type+' '+fo.getPropertyInfo().getName(true)+';'); } dumpChildren(cls); indent--; println("}"); }