Java Code Examples for com.sun.codemodel.internal.JBlock#_return
The following examples show how to use
com.sun.codemodel.internal.JBlock#_return .
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 TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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: WebServiceWrapperGenerator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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 3
Source File: WebServiceWrapperGenerator.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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: NoExtendedContentField.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@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 5
Source File: UntypedListField.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@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 6
Source File: NoExtendedContentField.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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 7
Source File: ContentListField.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@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 8
Source File: NoExtendedContentField.java From hottub with GNU General Public License v2.0 | 5 votes |
@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 9
Source File: ContentListField.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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 10
Source File: UntypedListField.java From hottub with GNU General Public License v2.0 | 5 votes |
@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 11
Source File: UntypedListField.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@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 12
Source File: NoExtendedContentField.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@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 13
Source File: ContentListField.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@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 14
Source File: CustomExceptionGenerator.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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); }
Example 15
Source File: CustomExceptionGenerator.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
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); }
Example 16
Source File: CustomExceptionGenerator.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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); }
Example 17
Source File: ArrayField.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public void generateAccessors() { MethodWriter writer = outline.createMethodWriter(); Accessor acc = create(JExpr._this()); JVar $idx,$value; JBlock body; // [RESULT] T[] getX() { // if( <var>==null ) return new T[0]; // T[] retVal = new T[this._return.length] ; // System.arraycopy(this._return, 0, "retVal", 0, this._return.length); // return (retVal); // } $getAll = writer.declareMethod( exposedType.array(),"get"+prop.getName(true)); writer.javadoc().append(prop.javadoc); body = $getAll.body(); body._if( acc.ref(true).eq(JExpr._null()) )._then() ._return(JExpr.newArray(exposedType,0)); JVar var = body.decl(exposedType.array(), "retVal", JExpr.newArray(implType,acc.ref(true).ref("length"))); body.add(codeModel.ref(System.class).staticInvoke("arraycopy") .arg(acc.ref(true)).arg(JExpr.lit(0)) .arg(var) .arg(JExpr.lit(0)).arg(acc.ref(true).ref("length"))); body._return(JExpr.direct("retVal")); List<Object> returnTypes = listPossibleTypes(prop); writer.javadoc().addReturn().append("array of\n").append(returnTypes); // [RESULT] // ET getX(int idx) { // if( <var>==null ) throw new IndexOutOfBoundsException(); // return unbox(<var>.get(idx)); // } JMethod $get = writer.declareMethod(exposedType,"get"+prop.getName(true)); $idx = writer.addParameter(codeModel.INT,"idx"); $get.body()._if(acc.ref(true).eq(JExpr._null()))._then() ._throw(JExpr._new(codeModel.ref(IndexOutOfBoundsException.class))); writer.javadoc().append(prop.javadoc); $get.body()._return(acc.ref(true).component($idx)); writer.javadoc().addReturn().append("one of\n").append(returnTypes); // [RESULT] int getXLength() { // if( <var>==null ) throw new IndexOutOfBoundsException(); // return <ref>.length; // } JMethod $getLength = writer.declareMethod(codeModel.INT,"get"+prop.getName(true)+"Length"); $getLength.body()._if(acc.ref(true).eq(JExpr._null()))._then() ._return(JExpr.lit(0)); $getLength.body()._return(acc.ref(true).ref("length")); // [RESULT] void setX(ET[] values) { // int len = values.length; // for( int i=0; i<len; i++ ) // <ref>[i] = values[i]; // } $setAll = writer.declareMethod( codeModel.VOID, "set"+prop.getName(true)); writer.javadoc().append(prop.javadoc); $value = writer.addParameter(exposedType.array(),"values"); JVar $len = $setAll.body().decl(codeModel.INT,"len", $value.ref("length")); $setAll.body().assign( (JAssignmentTarget) acc.ref(true), castToImplTypeArray(JExpr.newArray( codeModel.ref(exposedType.erasure().fullName()), $len))); JForLoop _for = $setAll.body()._for(); JVar $i = _for.init( codeModel.INT, "i", JExpr.lit(0) ); _for.test( JOp.lt($i,$len) ); _for.update( $i.incr() ); _for.body().assign(acc.ref(true).component($i), castToImplType(acc.box($value.component($i)))); writer.javadoc().addParam($value) .append("allowed objects are\n") .append(returnTypes); // [RESULT] ET setX(int idx, ET value) // <ref>[idx] = value JMethod $set = writer.declareMethod( exposedType, "set"+prop.getName(true)); $idx = writer.addParameter( codeModel.INT, "idx" ); $value = writer.addParameter( exposedType, "value" ); writer.javadoc().append(prop.javadoc); body = $set.body(); body._return( JExpr.assign(acc.ref(true).component($idx), castToImplType(acc.box($value)))); writer.javadoc().addParam($value) .append("allowed object is\n") .append(returnTypes); }
Example 18
Source File: ArrayField.java From hottub with GNU General Public License v2.0 | 4 votes |
public void generateAccessors() { MethodWriter writer = outline.createMethodWriter(); Accessor acc = create(JExpr._this()); JVar $idx,$value; JBlock body; // [RESULT] T[] getX() { // if( <var>==null ) return new T[0]; // T[] retVal = new T[this._return.length] ; // System.arraycopy(this._return, 0, "retVal", 0, this._return.length); // return (retVal); // } $getAll = writer.declareMethod( exposedType.array(),"get"+prop.getName(true)); writer.javadoc().append(prop.javadoc); body = $getAll.body(); body._if( acc.ref(true).eq(JExpr._null()) )._then() ._return(JExpr.newArray(exposedType,0)); JVar var = body.decl(exposedType.array(), "retVal", JExpr.newArray(implType,acc.ref(true).ref("length"))); body.add(codeModel.ref(System.class).staticInvoke("arraycopy") .arg(acc.ref(true)).arg(JExpr.lit(0)) .arg(var) .arg(JExpr.lit(0)).arg(acc.ref(true).ref("length"))); body._return(JExpr.direct("retVal")); List<Object> returnTypes = listPossibleTypes(prop); writer.javadoc().addReturn().append("array of\n").append(returnTypes); // [RESULT] // ET getX(int idx) { // if( <var>==null ) throw new IndexOutOfBoundsException(); // return unbox(<var>.get(idx)); // } JMethod $get = writer.declareMethod(exposedType,"get"+prop.getName(true)); $idx = writer.addParameter(codeModel.INT,"idx"); $get.body()._if(acc.ref(true).eq(JExpr._null()))._then() ._throw(JExpr._new(codeModel.ref(IndexOutOfBoundsException.class))); writer.javadoc().append(prop.javadoc); $get.body()._return(acc.ref(true).component($idx)); writer.javadoc().addReturn().append("one of\n").append(returnTypes); // [RESULT] int getXLength() { // if( <var>==null ) throw new IndexOutOfBoundsException(); // return <ref>.length; // } JMethod $getLength = writer.declareMethod(codeModel.INT,"get"+prop.getName(true)+"Length"); $getLength.body()._if(acc.ref(true).eq(JExpr._null()))._then() ._return(JExpr.lit(0)); $getLength.body()._return(acc.ref(true).ref("length")); // [RESULT] void setX(ET[] values) { // int len = values.length; // for( int i=0; i<len; i++ ) // <ref>[i] = values[i]; // } $setAll = writer.declareMethod( codeModel.VOID, "set"+prop.getName(true)); writer.javadoc().append(prop.javadoc); $value = writer.addParameter(exposedType.array(),"values"); JVar $len = $setAll.body().decl(codeModel.INT,"len", $value.ref("length")); $setAll.body().assign( (JAssignmentTarget) acc.ref(true), castToImplTypeArray(JExpr.newArray( codeModel.ref(exposedType.erasure().fullName()), $len))); JForLoop _for = $setAll.body()._for(); JVar $i = _for.init( codeModel.INT, "i", JExpr.lit(0) ); _for.test( JOp.lt($i,$len) ); _for.update( $i.incr() ); _for.body().assign(acc.ref(true).component($i), castToImplType(acc.box($value.component($i)))); writer.javadoc().addParam($value) .append("allowed objects are\n") .append(returnTypes); // [RESULT] ET setX(int idx, ET value) // <ref>[idx] = value JMethod $set = writer.declareMethod( exposedType, "set"+prop.getName(true)); $idx = writer.addParameter( codeModel.INT, "idx" ); $value = writer.addParameter( exposedType, "value" ); writer.javadoc().append(prop.javadoc); body = $set.body(); body._return( JExpr.assign(acc.ref(true).component($idx), castToImplType(acc.box($value)))); writer.javadoc().addParam($value) .append("allowed object is\n") .append(returnTypes); }
Example 19
Source File: CustomExceptionGenerator.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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); }
Example 20
Source File: ArrayField.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public void generateAccessors() { MethodWriter writer = outline.createMethodWriter(); Accessor acc = create(JExpr._this()); JVar $idx,$value; JBlock body; // [RESULT] T[] getX() { // if( <var>==null ) return new T[0]; // T[] retVal = new T[this._return.length] ; // System.arraycopy(this._return, 0, "retVal", 0, this._return.length); // return (retVal); // } $getAll = writer.declareMethod( exposedType.array(),"get"+prop.getName(true)); writer.javadoc().append(prop.javadoc); body = $getAll.body(); body._if( acc.ref(true).eq(JExpr._null()) )._then() ._return(JExpr.newArray(exposedType,0)); JVar var = body.decl(exposedType.array(), "retVal", JExpr.newArray(implType,acc.ref(true).ref("length"))); body.add(codeModel.ref(System.class).staticInvoke("arraycopy") .arg(acc.ref(true)).arg(JExpr.lit(0)) .arg(var) .arg(JExpr.lit(0)).arg(acc.ref(true).ref("length"))); body._return(JExpr.direct("retVal")); List<Object> returnTypes = listPossibleTypes(prop); writer.javadoc().addReturn().append("array of\n").append(returnTypes); // [RESULT] // ET getX(int idx) { // if( <var>==null ) throw new IndexOutOfBoundsException(); // return unbox(<var>.get(idx)); // } JMethod $get = writer.declareMethod(exposedType,"get"+prop.getName(true)); $idx = writer.addParameter(codeModel.INT,"idx"); $get.body()._if(acc.ref(true).eq(JExpr._null()))._then() ._throw(JExpr._new(codeModel.ref(IndexOutOfBoundsException.class))); writer.javadoc().append(prop.javadoc); $get.body()._return(acc.ref(true).component($idx)); writer.javadoc().addReturn().append("one of\n").append(returnTypes); // [RESULT] int getXLength() { // if( <var>==null ) throw new IndexOutOfBoundsException(); // return <ref>.length; // } JMethod $getLength = writer.declareMethod(codeModel.INT,"get"+prop.getName(true)+"Length"); $getLength.body()._if(acc.ref(true).eq(JExpr._null()))._then() ._return(JExpr.lit(0)); $getLength.body()._return(acc.ref(true).ref("length")); // [RESULT] void setX(ET[] values) { // int len = values.length; // for( int i=0; i<len; i++ ) // <ref>[i] = values[i]; // } $setAll = writer.declareMethod( codeModel.VOID, "set"+prop.getName(true)); writer.javadoc().append(prop.javadoc); $value = writer.addParameter(exposedType.array(),"values"); JVar $len = $setAll.body().decl(codeModel.INT,"len", $value.ref("length")); $setAll.body().assign( (JAssignmentTarget) acc.ref(true), castToImplTypeArray(JExpr.newArray( codeModel.ref(exposedType.erasure().fullName()), $len))); JForLoop _for = $setAll.body()._for(); JVar $i = _for.init( codeModel.INT, "i", JExpr.lit(0) ); _for.test( JOp.lt($i,$len) ); _for.update( $i.incr() ); _for.body().assign(acc.ref(true).component($i), castToImplType(acc.box($value.component($i)))); writer.javadoc().addParam($value) .append("allowed objects are\n") .append(returnTypes); // [RESULT] ET setX(int idx, ET value) // <ref>[idx] = value JMethod $set = writer.declareMethod( exposedType, "set"+prop.getName(true)); $idx = writer.addParameter( codeModel.INT, "idx" ); $value = writer.addParameter( exposedType, "value" ); writer.javadoc().append(prop.javadoc); body = $set.body(); body._return( JExpr.assign(acc.ref(true).component($idx), castToImplType(acc.box($value)))); writer.javadoc().addParam($value) .append("allowed object is\n") .append(returnTypes); }