com.sun.codemodel.internal.JVar Java Examples

The following examples show how to use com.sun.codemodel.internal.JVar. 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 jdk8u60 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: SourceLocationAddOn.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public boolean run(
    Outline outline,
    Options opt,
    ErrorHandler errorHandler ) {

    for( ClassOutline ci : outline.getClasses() ) {
        JDefinedClass impl = ci.implClass;
        if (ci.getSuperClass() == null) {
            JVar $loc = impl.field(JMod.PROTECTED, Locator.class, fieldName);
            $loc.annotate(XmlLocation.class);
            $loc.annotate(XmlTransient.class);

            impl._implements(Locatable.class);

            impl.method(JMod.PUBLIC, Locator.class, "sourceLocation").body()._return($loc);

            JMethod setter = impl.method(JMod.PUBLIC, Void.TYPE, "setSourceLocation");
            JVar $newLoc = setter.param(Locator.class, "newLocator");
            setter.body().assign($loc, $newLoc);
        }
    }

    return true;
}
 
Example #3
Source File: WebServiceWrapperGenerator.java    From openjdk-8-source 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: ElementCollectionAdapter.java    From openjdk-jdk8u-backup 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 #5
Source File: SourceLocationAddOn.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public boolean run(
    Outline outline,
    Options opt,
    ErrorHandler errorHandler ) {

    for( ClassOutline ci : outline.getClasses() ) {
        JDefinedClass impl = ci.implClass;
        if (ci.getSuperClass() == null) {
            JVar $loc = impl.field(JMod.PROTECTED, Locator.class, fieldName);
            $loc.annotate(XmlLocation.class);
            $loc.annotate(XmlTransient.class);

            impl._implements(Locatable.class);

            impl.method(JMod.PUBLIC, Locator.class, "sourceLocation").body()._return($loc);

            JMethod setter = impl.method(JMod.PUBLIC, Void.TYPE, "setSourceLocation");
            JVar $newLoc = setter.param(Locator.class, "newLocator");
            setter.body().assign($loc, $newLoc);
        }
    }

    return true;
}
 
Example #6
Source File: ElementCollectionAdapter.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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 #7
Source File: ElementCollectionAdapter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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 #8
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 #9
Source File: ElementCollectionAdapter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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 #10
Source File: SourceLocationAddOn.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public boolean run(
    Outline outline,
    Options opt,
    ErrorHandler errorHandler ) {

    for( ClassOutline ci : outline.getClasses() ) {
        JDefinedClass impl = ci.implClass;
        if (ci.getSuperClass() == null) {
            JVar $loc = impl.field(JMod.PROTECTED, Locator.class, fieldName);
            $loc.annotate(XmlLocation.class);
            $loc.annotate(XmlTransient.class);

            impl._implements(Locatable.class);

            impl.method(JMod.PUBLIC, Locator.class, "sourceLocation").body()._return($loc);

            JMethod setter = impl.method(JMod.PUBLIC, Void.TYPE, "setSourceLocation");
            JVar $newLoc = setter.param(Locator.class, "newLocator");
            setter.body().assign($loc, $newLoc);
        }
    }

    return true;
}
 
Example #11
Source File: SourceLocationAddOn.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public boolean run(
    Outline outline,
    Options opt,
    ErrorHandler errorHandler ) {

    for( ClassOutline ci : outline.getClasses() ) {
        JDefinedClass impl = ci.implClass;
        if (ci.getSuperClass() == null) {
            JVar $loc = impl.field(JMod.PROTECTED, Locator.class, fieldName);
            $loc.annotate(XmlLocation.class);
            $loc.annotate(XmlTransient.class);

            impl._implements(Locatable.class);

            impl.method(JMod.PUBLIC, Locator.class, "sourceLocation").body()._return($loc);

            JMethod setter = impl.method(JMod.PUBLIC, Void.TYPE, "setSourceLocation");
            JVar $newLoc = setter.param(Locator.class, "newLocator");
            setter.body().assign($loc, $newLoc);
        }
    }

    return true;
}
 
Example #12
Source File: WebServiceWrapperGenerator.java    From TencentKona-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 #13
Source File: SourceLocationAddOn.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public boolean run(
    Outline outline,
    Options opt,
    ErrorHandler errorHandler ) {

    for( ClassOutline ci : outline.getClasses() ) {
        JDefinedClass impl = ci.implClass;
        if (ci.getSuperClass() == null) {
            JVar $loc = impl.field(JMod.PROTECTED, Locator.class, fieldName);
            $loc.annotate(XmlLocation.class);
            $loc.annotate(XmlTransient.class);

            impl._implements(Locatable.class);

            impl.method(JMod.PUBLIC, Locator.class, "sourceLocation").body()._return($loc);

            JMethod setter = impl.method(JMod.PUBLIC, Void.TYPE, "setSourceLocation");
            JVar $newLoc = setter.param(Locator.class, "newLocator");
            setter.body().assign($loc, $newLoc);
        }
    }

    return true;
}
 
Example #14
Source File: SourceLocationAddOn.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public boolean run(
    Outline outline,
    Options opt,
    ErrorHandler errorHandler ) {

    for( ClassOutline ci : outline.getClasses() ) {
        JDefinedClass impl = ci.implClass;
        if (ci.getSuperClass() == null) {
            JVar $loc = impl.field(JMod.PROTECTED, Locator.class, fieldName);
            $loc.annotate(XmlLocation.class);
            $loc.annotate(XmlTransient.class);

            impl._implements(Locatable.class);

            impl.method(JMod.PUBLIC, Locator.class, "sourceLocation").body()._return($loc);

            JMethod setter = impl.method(JMod.PUBLIC, Void.TYPE, "setSourceLocation");
            JVar $newLoc = setter.param(Locator.class, "newLocator");
            setter.body().assign($loc, $newLoc);
        }
    }

    return true;
}
 
Example #15
Source File: NoExtendedContentField.java    From openjdk-8-source 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 #16
Source File: ServiceGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void writeResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    staticBlock.assign(urlField, JExpr.dotclass(cm.ref(className)).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 #17
Source File: ContentListField.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(exposedType.boxify())).arg(
        $target.invoke($get)
    ));
}
 
Example #18
Source File: ServiceGenerator.java    From openjdk-jdk8u 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 #19
Source File: DummyListField.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(exposedType.boxify())).arg(
        $target.invoke($get)
    ));
}
 
Example #20
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 #21
Source File: ServiceGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void writeAbsWSDLLocation(JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());

    JTryBlock tryBlock = staticBlock._try();
    tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(wsdlLocation));
    JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
    catchBlock.param("ex");
    catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(JExpr.ref("ex")));

    staticBlock.assign(urlField, urlVar);
    staticBlock.assign(exField, exVar);
}
 
Example #22
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 #23
Source File: ContentListField.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 #24
Source File: ServiceGenerator.java    From openjdk-jdk8u-backup 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 #25
Source File: ContentListField.java    From hottub 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 #26
Source File: ServiceGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void writeAbsWSDLLocation(JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());

    JTryBlock tryBlock = staticBlock._try();
    tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(wsdlLocation));
    JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
    catchBlock.param("ex");
    catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(JExpr.ref("ex")));

    staticBlock.assign(urlField, urlVar);
    staticBlock.assign(exField, exVar);
}
 
Example #27
Source File: ContentListField.java    From openjdk-jdk9 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 #28
Source File: UntypedListField.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(exposedType.boxify())).arg(
        $target.invoke($get)
    ));
}
 
Example #29
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 #30
Source File: ElementSingleAdapter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void toRawValue(JBlock block, JVar $var) {
    // [RESULT]
    // if([core.hasSetValue])
    //   $var = [core.toRawValue].getValue();
    // else
    //   $var = null;

    JConditional cond = block._if(acc.hasSetValue());
    JVar $v = cond._then().decl(core.getRawType(), "v" + hashCode());// TODO: unique value control
    acc.toRawValue(cond._then(),$v);
    cond._then().assign($var,$v.invoke("getValue"));
    cond._else().assign($var, JExpr._null());
}