本文整理汇总了Java中com.sun.codemodel.internal.JClass类的典型用法代码示例。如果您正苦于以下问题:Java JClass类的具体用法?Java JClass怎么用?Java JClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JClass类属于com.sun.codemodel.internal包,在下文中一共展示了JClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateClassDef
import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
/**
* 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);
}
示例2: generateStaticClass
import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
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();
}
示例3: toRawValue
import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
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"));
}
示例4: fromRawValue
import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
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);
}
示例5: getSuperClass
import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
/** 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;
}
示例6: getSuperInterface
import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
/** Gets the xjc:superInterface customization if it's turned on. */
public JClass getSuperInterface() {
Element sc = DOMUtil.getElement(dom,XJC_NS,"superInterface");
if (sc == null) return null;
String name = DOMUtil.getAttribute(sc,"name");
if (name == null) return null;
JDefinedClass c;
try {
c = codeModel._class(name, ClassType.INTERFACE);
c.hide();
} catch (JClassAlreadyExistsException e) {
c = e.getExistingClass();
}
return c;
}
示例7: getAssignableTypes
import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
/**
* Returns the set of all classes/interfaces that a given type
* implements/extends, including itself.
*
* For example, if you pass java.io.FilterInputStream, then the returned
* set will contain java.lang.Object, java.lang.InputStream, and
* java.lang.FilterInputStream.
*/
private static void getAssignableTypes( JClass t, Set<JClass> s ) {
if(!s.add(t))
return;
// add its raw type
s.add(t.erasure());
// if this type is added for the first time,
// recursively process the super class.
JClass _super = t._extends();
if(_super!=null)
getAssignableTypes(_super,s);
// recursively process all implemented interfaces
Iterator<JClass> itr = t._implements();
while(itr.hasNext())
getAssignableTypes(itr.next(),s);
}
示例8: getRef
import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
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);
}
}
示例9: getResponseBeanJavaType
import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
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;
}
示例10: getCallBackType
import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
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;
}
示例11: DummyListField
import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
/**
* @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();
}
示例12: UntypedListField
import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
/**
* @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();
}
示例13: ContentListField
import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
/**
* @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 ContentListField(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();
}
示例14: generateAttributeWildcard
import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
/**
* 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);
}
示例15: addRuntime
import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
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;
}