Java Code Examples for com.sun.codemodel.internal.JBlock#assign()

The following examples show how to use com.sun.codemodel.internal.JBlock#assign() . 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: WebServiceWrapperGenerator.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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 );
}
 
Example 2
Source File: ElementCollectionAdapter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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 3
Source File: WebServiceWrapperGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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 );
}
 
Example 4
Source File: ServiceGenerator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void writeClassLoaderBaseResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
    JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
    JTryBlock tryBlock = staticBlock._try();
    tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(JExpr.dotclass(cm.ref(className)).invoke("getResource").arg(".")).arg(wsdlLocation));
    JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
    JVar murlVar = catchBlock.param("murl");
    catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(murlVar));
    staticBlock.assign(urlField, urlVar);
    staticBlock.assign(exField, exVar);
}
 
Example 5
Source File: AbstractFieldWithVar.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public final void toRawValue(JBlock block, JVar $var) {
    if (getOptions().enableIntrospection) {
        block.assign($var,$target.invoke(getGetterMethod()));
    } else {
        block.assign($var,$target.invoke(getGetterMethod()));
    }
}
 
Example 6
Source File: NoExtendedContentField.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void toRawValue(JBlock block, JVar $var) {
    // [RESULT]
    // $<var>.addAll(bean.getLIST());
    // list.toArray( array );
    block.assign($var,JExpr._new(codeModel.ref(ArrayList.class).narrow(getType(Aspect.EXPOSED).boxify())).arg(
        $target.invoke($get)
    ));
}
 
Example 7
Source File: ServiceGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void writeClassLoaderBaseResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
    JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
    JTryBlock tryBlock = staticBlock._try();
    tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(JExpr.dotclass(cm.ref(className)).invoke("getResource").arg(".")).arg(wsdlLocation));
    JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
    JVar murlVar = catchBlock.param("murl");
    catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(murlVar));
    staticBlock.assign(urlField, urlVar);
    staticBlock.assign(exField, exVar);
}
 
Example 8
Source File: ServiceGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void writeClassLoaderBaseResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
    JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
    JTryBlock tryBlock = staticBlock._try();
    tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(JExpr.dotclass(cm.ref(className)).invoke("getResource").arg(".")).arg(wsdlLocation));
    JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
    JVar murlVar = catchBlock.param("murl");
    catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(murlVar));
    staticBlock.assign(urlField, urlVar);
    staticBlock.assign(exField, exVar);
}
 
Example 9
Source File: UntypedListField.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void toRawValue(JBlock block, JVar $var) {
    // [RESULT]
    // $<var>.addAll(bean.getLIST());
    // list.toArray( array );
    block.assign($var,JExpr._new(codeModel.ref(ArrayList.class).narrow(exposedType.boxify())).arg(
        $target.invoke($get)
    ));
}
 
Example 10
Source File: NoExtendedContentField.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void toRawValue(JBlock block, JVar $var) {
    // [RESULT]
    // $<var>.addAll(bean.getLIST());
    // list.toArray( array );
    block.assign($var,JExpr._new(codeModel.ref(ArrayList.class).narrow(getType(Aspect.EXPOSED).boxify())).arg(
        $target.invoke($get)
    ));
}
 
Example 11
Source File: DummyListField.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void toRawValue(JBlock block, JVar $var) {
    // [RESULT]
    // $<var>.addAll(bean.getLIST());
    // list.toArray( array );
    block.assign($var,JExpr._new(codeModel.ref(ArrayList.class).narrow(exposedType.boxify())).arg(
        $target.invoke($get)
    ));
}
 
Example 12
Source File: ServiceGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void writeClassLoaderResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    staticBlock.assign(urlField, JExpr.dotclass(cm.ref(className)).invoke("getClassLoader").invoke("getResource").arg(wsdlLocation));
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
    JConditional ifBlock = staticBlock._if(urlField.eq(JExpr._null()));
    ifBlock._then().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(
            "Cannot find "+JExpr.quotify('\'', wsdlLocation)+" wsdl. Place the resource correctly in the classpath."));
    staticBlock.assign(exField, exVar);
}
 
Example 13
Source File: ServiceGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void writeClassLoaderResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    staticBlock.assign(urlField, JExpr.dotclass(cm.ref(className)).invoke("getClassLoader").invoke("getResource").arg(wsdlLocation));
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
    JConditional ifBlock = staticBlock._if(urlField.eq(JExpr._null()));
    ifBlock._then().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(
            "Cannot find "+JExpr.quotify('\'', wsdlLocation)+" wsdl. Place the resource correctly in the classpath."));
    staticBlock.assign(exField, exVar);
}
 
Example 14
Source File: AbstractFieldWithVar.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public final void toRawValue(JBlock block, JVar $var) {
    if (getOptions().enableIntrospection) {
        block.assign($var,$target.invoke(getGetterMethod()));
    } else {
        block.assign($var,$target.invoke(getGetterMethod()));
    }
}
 
Example 15
Source File: UntypedListField.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void toRawValue(JBlock block, JVar $var) {
    // [RESULT]
    // $<var>.addAll(bean.getLIST());
    // list.toArray( array );
    block.assign($var,JExpr._new(codeModel.ref(ArrayList.class).narrow(exposedType.boxify())).arg(
        $target.invoke($get)
    ));
}
 
Example 16
Source File: AbstractListField.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void unsetValues( JBlock body ) {
    body.assign(field,JExpr._null());
}
 
Example 17
Source File: ArrayField.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void toRawValue(JBlock block, JVar $var) {
    block.assign($var,$target.invoke($getAll));
}
 
Example 18
Source File: AbstractListField.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void unsetValues( JBlock body ) {
    body.assign(field,JExpr._null());
}
 
Example 19
Source File: SingleField.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void unsetValues( JBlock body ) {
    body.assign( $ref, JExpr._null() );
}
 
Example 20
Source File: CustomExceptionGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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);

}