• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JClass类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.sun.codemodel.internal.JClass的典型用法代码示例。如果您正苦于以下问题:Java JClass类的具体用法?Java JClass怎么用?Java JClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JClass类属于com.sun.codemodel.internal包,在下文中一共展示了JClass类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:BeanGenerator.java


示例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();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:BeanGenerator.java


示例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"));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:ElementCollectionAdapter.java


示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:ElementCollectionAdapter.java


示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:BindInfo.java


示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:BindInfo.java


示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:TypeUtil.java


示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:CAdapter.java


示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:AsyncOperation.java


示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:AsyncOperation.java


示例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();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:DummyListField.java


示例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();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:UntypedListField.java


示例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();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:ContentListField.java


示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:BeanGenerator.java


示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:BeanGenerator.java


示例16: ElementOutlineImpl

import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
ElementOutlineImpl(BeanGenerator parent, CElementInfo ei) {
    super(ei,
          parent.getClassFactory().createClass(
                  parent.getContainer( ei.parent, Aspect.EXPOSED ), ei.shortName(), ei.getLocator() ));
    this.parent = parent;
    parent.elements.put(ei,this);

    JCodeModel cm = parent.getCodeModel();

    implClass._extends(
        cm.ref(JAXBElement.class).narrow(
            target.getContentInMemoryType().toType(parent,Aspect.EXPOSED).boxify()));

    if(ei.hasClass()) {
        JType implType = ei.getContentInMemoryType().toType(parent,Aspect.IMPLEMENTATION);
        JExpression declaredType = JExpr.cast(cm.ref(Class.class),implType.boxify().dotclass()); // why do we have to cast?
        JClass scope=null;
        if(ei.getScope()!=null)
            scope = parent.getClazz(ei.getScope()).implRef;
        JExpression scopeClass = scope==null?JExpr._null():scope.dotclass();
        JFieldVar valField = implClass.field(JMod.PROTECTED|JMod.FINAL|JMod.STATIC,QName.class,"NAME",createQName(cm,ei.getElementName()));

        // take this opportunity to generate a constructor in the element class
        JMethod cons = implClass.constructor(JMod.PUBLIC);
        cons.body().invoke("super")
            .arg(valField)
            .arg(declaredType)
            .arg(scopeClass)
            .arg(cons.param(implType,"value"));

        // generate no-arg constructor in the element class (bug #391; section 5.6.2 in JAXB spec 2.1)
        JMethod noArgCons = implClass.constructor(JMod.PUBLIC);
        noArgCons.body().invoke("super")
            .arg(valField)
            .arg(declaredType)
            .arg(scopeClass)
            .arg(JExpr._null());

    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:ElementOutlineImpl.java


示例17: PrivateObjectFactoryGenerator

import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
public PrivateObjectFactoryGenerator(BeanGenerator outline, Model model, JPackage targetPackage) {
    super(outline, model, targetPackage.subPackage("impl"));

    JPackage implPkg = targetPackage.subPackage("impl");

    // put JAXBContextFactory into the impl package
    JClass factory = outline.generateStaticClass(JAXBContextFactory.class,implPkg);

    // and then put jaxb.properties to point to it
    JPropertyFile jaxbProperties = new JPropertyFile("jaxb.properties");
    targetPackage.addResourceFile(jaxbProperties);
    jaxbProperties.add(
        JAXBContext.JAXB_CONTEXT_FACTORY,
        factory.fullName());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:PrivateObjectFactoryGenerator.java


示例18: dump

import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
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("}");
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:SignatureWriter.java


示例19: pickOne

import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
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();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:TypeUtil.java


示例20: createConstant

import com.sun.codemodel.internal.JClass; //导入依赖的package包/类
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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:CEnumLeafInfo.java



注:本文中的com.sun.codemodel.internal.JClass类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PasswordChangeRequiredException类代码示例发布时间:2022-05-23
下一篇:
Java PCollectionView类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap