类 com.sun.codemodel.internal.JType 源码实例Demo

下面列出了怎么用 com.sun.codemodel.internal.JType 的API类实例代码及写法,或者点击链接到github查看源代码。


private void writeMember(JDefinedClass cls, TypeMirror paramType,
                         String paramName) {

    if (cls == null)
        return;

    String accessorName =BindingHelper.mangleNameToPropertyName(paramName);
    String getterPrefix = paramType.toString().equals("boolean")? "is" : "get";
    JType propType = getType(paramType);
    JMethod m = cls.method(JMod.PUBLIC, propType, getterPrefix+ accessorName);
    JDocComment methodDoc = m.javadoc();
    JCommentPart ret = methodDoc.addReturn();
    ret.add("returns "+propType.name());
    JBlock body = m.body();
    body._return( JExpr._this().ref(paramName) );

    m = cls.method(JMod.PUBLIC, cm.VOID, "set"+accessorName);
    JVar param = m.param(propType, paramName);
    methodDoc = m.javadoc();
    JCommentPart part = methodDoc.addParam(paramName);
    part.add("the value for the "+ paramName+" property");
    body = m.body();
    body.assign( JExpr._this().ref(paramName), param );
}
 
源代码2 项目: openjdk-8   文件: TypeAndAnnotationImpl.java

public JType getTypeClass() {
    CAdapter a = typeUse.getAdapterUse();
    NType nt;
    if(a!=null)
        nt = a.customType;
    else
        nt = typeUse.getInfo().getType();

    JType jt = nt.toType(outline,EXPOSED);

    JPrimitiveType prim = jt.boxify().getPrimitiveType();
    if(!typeUse.isCollection() && prim!=null)
        jt = prim;

    if(typeUse.isCollection())
        jt = jt.array();

    return jt;
}
 

private void writeMember(JDefinedClass cls, TypeMirror paramType,
                         String paramName) {

    if (cls == null)
        return;

    String accessorName =BindingHelper.mangleNameToPropertyName(paramName);
    String getterPrefix = paramType.toString().equals("boolean")? "is" : "get";
    JType propType = getType(paramType);
    JMethod m = cls.method(JMod.PUBLIC, propType, getterPrefix+ accessorName);
    JDocComment methodDoc = m.javadoc();
    JCommentPart ret = methodDoc.addReturn();
    ret.add("returns "+propType.name());
    JBlock body = m.body();
    body._return( JExpr._this().ref(paramName) );

    m = cls.method(JMod.PUBLIC, cm.VOID, "set"+accessorName);
    JVar param = m.param(propType, paramName);
    methodDoc = m.javadoc();
    JCommentPart part = methodDoc.addParam(paramName);
    part.add("the value for the "+ paramName+" property");
    body = m.body();
    body.assign( JExpr._this().ref(paramName), param );
}
 

public JType getTypeClass() {
    CAdapter a = typeUse.getAdapterUse();
    NType nt;
    if(a!=null)
        nt = a.customType;
    else
        nt = typeUse.getInfo().getType();

    JType jt = nt.toType(outline,EXPOSED);

    JPrimitiveType prim = jt.boxify().getPrimitiveType();
    if(!typeUse.isCollection() && prim!=null)
        jt = prim;

    if(typeUse.isCollection())
        jt = jt.array();

    return jt;
}
 

private void writeMember(JDefinedClass cls, TypeMirror paramType,
                         String paramName) {

    if (cls == null)
        return;

    String accessorName =BindingHelper.mangleNameToPropertyName(paramName);
    String getterPrefix = paramType.toString().equals("boolean")? "is" : "get";
    JType propType = getType(paramType);
    JMethod m = cls.method(JMod.PUBLIC, propType, getterPrefix+ accessorName);
    JDocComment methodDoc = m.javadoc();
    JCommentPart ret = methodDoc.addReturn();
    ret.add("returns "+propType.name());
    JBlock body = m.body();
    body._return( JExpr._this().ref(paramName) );

    m = cls.method(JMod.PUBLIC, cm.VOID, "set"+accessorName);
    JVar param = m.param(propType, paramName);
    methodDoc = m.javadoc();
    JCommentPart part = methodDoc.addParam(paramName);
    part.add("the value for the "+ paramName+" property");
    body = m.body();
    body.assign( JExpr._this().ref(paramName), param );
}
 
源代码6 项目: jdk8u60   文件: ServiceGenerator.java

private void writeGetPort(Port port, JType retType, JDefinedClass cls) {
    JMethod m = cls.method(JMod.PUBLIC, retType, port.getPortGetter());
    JDocComment methodDoc = m.javadoc();
    if (port.getJavaDoc() != null) {
        methodDoc.add(port.getJavaDoc());
    }
    JCommentPart ret = methodDoc.addReturn();
    JCommentPart paramDoc = methodDoc.addParam("features");
    paramDoc.append("A list of ");
    paramDoc.append("{@link " + WebServiceFeature.class.getName() + "}");
    paramDoc.append("to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.");
    ret.add("returns " + retType.name());
    m.varParam(WebServiceFeature.class, "features");
    JBlock body = m.body();
    StringBuilder statement = new StringBuilder("return ");
    statement.append("super.getPort(new QName(\"").append(port.getName().getNamespaceURI()).append("\", \"").append(port.getName().getLocalPart()).append("\"), ");
    statement.append(retType.name());
    statement.append(".class, features);");
    body.directStatement(statement.toString());
    writeWebEndpoint(port, m);
}
 

private void writeGetPort(Port port, JType retType, JDefinedClass cls) {
    JMethod m = cls.method(JMod.PUBLIC, retType, port.getPortGetter());
    JDocComment methodDoc = m.javadoc();
    if (port.getJavaDoc() != null) {
        methodDoc.add(port.getJavaDoc());
    }
    JCommentPart ret = methodDoc.addReturn();
    JCommentPart paramDoc = methodDoc.addParam("features");
    paramDoc.append("A list of ");
    paramDoc.append("{@link " + WebServiceFeature.class.getName() + "}");
    paramDoc.append("to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.");
    ret.add("returns " + retType.name());
    m.varParam(WebServiceFeature.class, "features");
    JBlock body = m.body();
    StringBuilder statement = new StringBuilder("return ");
    statement.append("super.getPort(new QName(\"").append(port.getName().getNamespaceURI()).append("\", \"").append(port.getName().getLocalPart()).append("\"), ");
    statement.append(retType.name());
    statement.append(".class, features);");
    body.directStatement(statement.toString());
    writeWebEndpoint(port, m);
}
 
源代码8 项目: openjdk-8-source   文件: AbstractField.java

/**
 * Returns contents to be added to javadoc.
 */
protected final List<Object> listPossibleTypes( CPropertyInfo prop ) {
    List<Object> r = new ArrayList<Object>();
    for( CTypeInfo tt : prop.ref() ) {
        JType t = tt.getType().toType(outline.parent(),Aspect.EXPOSED);
        if( t.isPrimitive() || t.isArray() )
            r.add(t.fullName());
        else {
            r.add(t);
            r.add("\n");
        }
    }

    return r;
}
 
源代码9 项目: jdk8u60   文件: ContentListField.java

@Override
protected JType getType(final Aspect aspect) {
    if (Aspect.IMPLEMENTATION.equals(aspect)) {
        return super.getType(aspect);
    }
    return codeModel.ref(Serializable.class);
}
 
源代码10 项目: jdk8u60   文件: EagerNType.java

public JType toType(Outline o, Aspect aspect) {
    try {
        return o.getCodeModel().parseType(t.toString());
    } catch (ClassNotFoundException e) {
        throw new NoClassDefFoundError(e.getMessage());
    }
}
 
源代码11 项目: TencentKona-8   文件: AbstractField.java

/**
 * Returns contents to be added to javadoc.
 */
protected final List<Object> listPossibleTypes( CPropertyInfo prop ) {
    List<Object> r = new ArrayList<Object>();
    for( CTypeInfo tt : prop.ref() ) {
        JType t = tt.getType().toType(outline.parent(),Aspect.EXPOSED);
        if( t.isPrimitive() || t.isArray() )
            r.add(t.fullName());
        else {
            r.add(t);
            r.add("\n");
        }
    }

    return r;
}
 

@Override
protected JType getType(final Aspect aspect) {
    if (Aspect.IMPLEMENTATION.equals(aspect)) {
        return super.getType(aspect);
    }

    if (prop instanceof CReferencePropertyInfo) {
        Set<CElement> elements = ((CReferencePropertyInfo)prop).getElements();
        if ((elements != null) && (elements.size() > 0)) {
            return codeModel.ref(Serializable.class);
        }
    }

    return codeModel.ref(String.class);
}
 
源代码13 项目: openjdk-jdk8u   文件: ContentListField.java

@Override
protected JType getType(final Aspect aspect) {
    if (Aspect.IMPLEMENTATION.equals(aspect)) {
        return super.getType(aspect);
    }
    return codeModel.ref(Serializable.class);
}
 
源代码14 项目: TencentKona-8   文件: BIProperty.java

public JType getBaseType() {
    if(baseType!=null && baseType.name!=null) {
        return TypeUtil.getType(getCodeModel(),
                baseType.name,
                Ring.get(ErrorReceiver.class),getLocation());
    }
    BIProperty next = getDefault();
    if(next!=null)  return next.getBaseType();
    else            return null;
}
 
源代码15 项目: openjdk-jdk8u   文件: BIProperty.java

public JType getBaseType() {
    if(baseType!=null && baseType.name!=null) {
        return TypeUtil.getType(getCodeModel(),
                baseType.name,
                Ring.get(ErrorReceiver.class),getLocation());
    }
    BIProperty next = getDefault();
    if(next!=null)  return next.getBaseType();
    else            return null;
}
 
源代码16 项目: TencentKona-8   文件: EagerNType.java

public JType toType(Outline o, Aspect aspect) {
    try {
        return o.getCodeModel().parseType(t.toString());
    } catch (ClassNotFoundException e) {
        throw new NoClassDefFoundError(e.getMessage());
    }
}
 
源代码17 项目: jdk8u60   文件: NoExtendedContentField.java

@Override
protected JType getType(final Aspect aspect) {
    if (Aspect.IMPLEMENTATION.equals(aspect)) {
        return super.getType(aspect);
    }

    if (prop instanceof CReferencePropertyInfo) {
        Set<CElement> elements = ((CReferencePropertyInfo)prop).getElements();
        if ((elements != null) && (elements.size() > 0)) {
            return codeModel.ref(Serializable.class);
        }
    }

    return codeModel.ref(String.class);
}
 
源代码18 项目: openjdk-8-source   文件: BIProperty.java

public JType getBaseType() {
    if(baseType!=null && baseType.name!=null) {
        return TypeUtil.getType(getCodeModel(),
                baseType.name,
                Ring.get(ErrorReceiver.class),getLocation());
    }
    BIProperty next = getDefault();
    if(next!=null)  return next.getBaseType();
    else            return null;
}
 

private JType getType(TypeMirror typeMirror) {
        String type = typeMirror.toString();
        try {
//            System.out.println("typeName: "+typeName);
            return cm.parseType(type);
//            System.out.println("type: "+type);
        } catch (ClassNotFoundException e) {
            return cm.ref(type);
        }
    }
 
源代码20 项目: openjdk-jdk9   文件: EagerNType.java

public JType toType(Outline o, Aspect aspect) {
    try {
        return o.getCodeModel().parseType(t.toString());
    } catch (ClassNotFoundException e) {
        throw new NoClassDefFoundError(e.getMessage());
    }
}
 

private void write(Fault fault) throws JClassAlreadyExistsException {
    String className = Names.customExceptionClassName(fault);

    JDefinedClass cls = cm._class(className, ClassType.CLASS);
    JDocComment comment = cls.javadoc();
    if(fault.getJavaDoc() != null){
        comment.add(fault.getJavaDoc());
        comment.add("\n\n");
    }

    for (String doc : getJAXWSClassComment()) {
        comment.add(doc);
    }

    cls._extends(java.lang.Exception.class);

    //@WebFault
    JAnnotationUse faultAnn = cls.annotate(WebFault.class);
    faultAnn.param("name", fault.getBlock().getName().getLocalPart());
    faultAnn.param("targetNamespace", fault.getBlock().getName().getNamespaceURI());

    JType faultBean = fault.getBlock().getType().getJavaType().getType().getType();

    //faultInfo filed
    JFieldVar fi = cls.field(JMod.PRIVATE, faultBean, "faultInfo");

    //add jaxb annotations
    fault.getBlock().getType().getJavaType().getType().annotate(fi);

    fi.javadoc().add("Java type that goes as soapenv:Fault detail element.");
    JFieldRef fr = JExpr.ref(JExpr._this(), fi);

    //Constructor
    JMethod constrc1 = cls.constructor(JMod.PUBLIC);
    JVar var1 = constrc1.param(String.class, "message");
    JVar var2 = constrc1.param(faultBean, "faultInfo");
    constrc1.javadoc().addParam(var1);
    constrc1.javadoc().addParam(var2);
    JBlock cb1 = constrc1.body();
    cb1.invoke("super").arg(var1);

    cb1.assign(fr, var2);

    //constructor with Throwable
    JMethod constrc2 = cls.constructor(JMod.PUBLIC);
    var1 = constrc2.param(String.class, "message");
    var2 = constrc2.param(faultBean, "faultInfo");
    JVar var3 = constrc2.param(Throwable.class, "cause");
    constrc2.javadoc().addParam(var1);
    constrc2.javadoc().addParam(var2);
    constrc2.javadoc().addParam(var3);
    JBlock cb2 = constrc2.body();
    cb2.invoke("super").arg(var1).arg(var3);
    cb2.assign(fr, var2);


    //getFaultInfo() method
    JMethod fim = cls.method(JMod.PUBLIC, faultBean, "getFaultInfo");
    fim.javadoc().addReturn().add("returns fault bean: "+faultBean.fullName());
    JBlock fib = fim.body();
    fib._return(fi);
    fault.setExceptionClass(cls);

}
 
源代码22 项目: openjdk-jdk8u   文件: SingleField.java

public final JType getFieldType() {
    return implType;
}
 
源代码23 项目: hottub   文件: CElementInfo.java

public JType toType(Outline o, Aspect aspect) {
    if(className==null)
        return type.toType(o,aspect);
    else
        return o.getElement(this).implClass;
}
 
源代码24 项目: openjdk-8   文件: PropertyImpl.java

public final JType type() {
    return fr.getRawType();
}
 

public JType getRawType() {
    return codeModel().ref(List.class).narrow(itemType().boxify());
}
 
源代码26 项目: openjdk-8   文件: CArrayInfo.java

public JType toType(Outline o, Aspect aspect) {
    return itemType.toType(o,aspect).array();
}
 
源代码27 项目: hottub   文件: ElementCollectionAdapter.java

private JType itemType() {
    return ei.getContentInMemoryType().toType(outline(), EXPOSED);
}
 
源代码28 项目: hottub   文件: ArrayField.java

@Override
public JType getRawType() {
    return exposedType.array();
}
 
源代码29 项目: openjdk-jdk8u   文件: AbstractField.java

/**
 * Generates the field declaration.
 */
protected final JFieldVar generateField( JType type ) {
    return outline.implClass.field( JMod.PROTECTED, type, prop.getName(false) );
}
 
源代码30 项目: openjdk-jdk9   文件: ArrayField.java

@Override
public JType getRawType() {
    return exposedType.array();
}
 
 类所在包
 类方法
 同包方法