com.sun.codemodel.internal.JBlock Java Examples

The following examples show how to use com.sun.codemodel.internal.JBlock. 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: ServiceGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #2
Source File: ServiceGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: ElementCollectionAdapter.java    From jdk8u60 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 #4
Source File: ServiceGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #5
Source File: ElementCollectionAdapter.java    From openjdk-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 #6
Source File: ContentListField.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(exposedType.boxify())).arg(
        $target.invoke($get)
    ));
}
 
Example #7
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 #8
Source File: DummyListField.java    From TencentKona-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(exposedType.boxify())).arg(
        $target.invoke($get)
    ));
}
 
Example #9
Source File: ServiceGenerator.java    From openjdk-8-source 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 #10
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 #11
Source File: ServiceGenerator.java    From TencentKona-8 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 #12
Source File: ServiceGenerator.java    From TencentKona-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 #13
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 #14
Source File: ContentListField.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void generateAccessors() {
    final MethodWriter writer = outline.createMethodWriter();
    final Accessor acc = create(JExpr._this());

    // [RESULT]
    // List getXXX() {
    //     return <ref>;
    // }
    $get = writer.declareMethod(listT,"get"+prop.getName(true));
    writer.javadoc().append(prop.javadoc);
    JBlock block = $get.body();
    fixNullRef(block);  // avoid using an internal getter
    block._return(acc.ref(true));

    String pname = NameConverter.standard.toVariableName(prop.getName(true));
    writer.javadoc().append(
        "Gets the value of the "+pname+" property.\n\n"+
        "<p>\n" +
        "This accessor method returns a reference to the live list,\n" +
        "not a snapshot. Therefore any modification you make to the\n" +
        "returned list will be present inside the JAXB object.\n" +
        "This is why there is not a <CODE>set</CODE> method for the " +pname+ " property.\n" +
        "\n"+
        "<p>\n" +
        "For example, to add a new item, do as follows:\n"+
        "<pre>\n"+
        "   get"+prop.getName(true)+"().add(newItem);\n"+
        "</pre>\n"+
        "\n\n"
    );

    writer.javadoc().append(
        "<p>\n" +
        "Objects of the following type(s) are allowed in the list\n")
        .append(listPossibleTypes(prop));
}
 
Example #15
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 #16
Source File: ContentListField.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void generateAccessors() {
    final MethodWriter writer = outline.createMethodWriter();
    final Accessor acc = create(JExpr._this());

    // [RESULT]
    // List getXXX() {
    //     return <ref>;
    // }
    $get = writer.declareMethod(listT,"get"+prop.getName(true));
    writer.javadoc().append(prop.javadoc);
    JBlock block = $get.body();
    fixNullRef(block);  // avoid using an internal getter
    block._return(acc.ref(true));

    String pname = NameConverter.standard.toVariableName(prop.getName(true));
    writer.javadoc().append(
        "Gets the value of the "+pname+" property.\n\n"+
        "<p>\n" +
        "This accessor method returns a reference to the live list,\n" +
        "not a snapshot. Therefore any modification you make to the\n" +
        "returned list will be present inside the JAXB object.\n" +
        "This is why there is not a <CODE>set</CODE> method for the " +pname+ " property.\n" +
        "\n"+
        "<p>\n" +
        "For example, to add a new item, do as follows:\n"+
        "<pre>\n"+
        "   get"+prop.getName(true)+"().add(newItem);\n"+
        "</pre>\n"+
        "\n\n"
    );

    writer.javadoc().append(
        "<p>\n" +
        "Objects of the following type(s) are allowed in the list\n")
        .append(listPossibleTypes(prop));
}
 
Example #17
Source File: ContentListField.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void generateAccessors() {
    final MethodWriter writer = outline.createMethodWriter();
    final Accessor acc = create(JExpr._this());

    // [RESULT]
    // List getXXX() {
    //     return <ref>;
    // }
    $get = writer.declareMethod(listT,"get"+prop.getName(true));
    writer.javadoc().append(prop.javadoc);
    JBlock block = $get.body();
    fixNullRef(block);  // avoid using an internal getter
    block._return(acc.ref(true));

    String pname = NameConverter.standard.toVariableName(prop.getName(true));
    writer.javadoc().append(
        "Gets the value of the "+pname+" property.\n\n"+
        "<p>\n" +
        "This accessor method returns a reference to the live list,\n" +
        "not a snapshot. Therefore any modification you make to the\n" +
        "returned list will be present inside the JAXB object.\n" +
        "This is why there is not a <CODE>set</CODE> method for the " +pname+ " property.\n" +
        "\n"+
        "<p>\n" +
        "For example, to add a new item, do as follows:\n"+
        "<pre>\n"+
        "   get"+prop.getName(true)+"().add(newItem);\n"+
        "</pre>\n"+
        "\n\n"
    );

    writer.javadoc().append(
        "<p>\n" +
        "Objects of the following type(s) are allowed in the list\n")
        .append(listPossibleTypes(prop));
}
 
Example #18
Source File: ServiceGenerator.java    From openjdk-8-source 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 #19
Source File: ElementSingleAdapter.java    From jdk8u60 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());
}
 
Example #20
Source File: ServiceGenerator.java    From openjdk-8-source 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 #21
Source File: ServiceGenerator.java    From openjdk-8 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 #22
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 #23
Source File: ElementSingleAdapter.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]
    // 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());
}
 
Example #24
Source File: ContentListField.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(exposedType.boxify())).arg(
        $target.invoke($get)
    ));
}
 
Example #25
Source File: ServiceGenerator.java    From openjdk-8 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 #26
Source File: DummyListField.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 #27
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 #28
Source File: ContentListField.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void generateAccessors() {
    final MethodWriter writer = outline.createMethodWriter();
    final Accessor acc = create(JExpr._this());

    // [RESULT]
    // List getXXX() {
    //     return <ref>;
    // }
    $get = writer.declareMethod(listT,"get"+prop.getName(true));
    writer.javadoc().append(prop.javadoc);
    JBlock block = $get.body();
    fixNullRef(block);  // avoid using an internal getter
    block._return(acc.ref(true));

    String pname = NameConverter.standard.toVariableName(prop.getName(true));
    writer.javadoc().append(
        "Gets the value of the "+pname+" property.\n\n"+
        "<p>\n" +
        "This accessor method returns a reference to the live list,\n" +
        "not a snapshot. Therefore any modification you make to the\n" +
        "returned list will be present inside the JAXB object.\n" +
        "This is why there is not a <CODE>set</CODE> method for the " +pname+ " property.\n" +
        "\n"+
        "<p>\n" +
        "For example, to add a new item, do as follows:\n"+
        "<pre>\n"+
        "   get"+prop.getName(true)+"().add(newItem);\n"+
        "</pre>\n"+
        "\n\n"
    );

    writer.javadoc().append(
        "<p>\n" +
        "Objects of the following type(s) are allowed in the list\n")
        .append(listPossibleTypes(prop));
}
 
Example #29
Source File: AbstractFieldWithVar.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public final void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
    block.invoke($target,("set"+prop.getName(true))).arg($var);
}
 
Example #30
Source File: CustomExceptionGenerator.java    From openjdk-8-source 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);

}