Java Code Examples for com.sun.tools.internal.xjc.generator.bean.MethodWriter#addParameter()
The following examples show how to use
com.sun.tools.internal.xjc.generator.bean.MethodWriter#addParameter() .
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: ArrayField.java From TencentKona-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 2
Source File: ArrayField.java From jdk8u60 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 3
Source File: ArrayField.java From openjdk-jdk8u 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 4
Source File: ArrayField.java From openjdk-jdk8u-backup 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 5
Source File: ArrayField.java From openjdk-jdk9 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 6
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 7
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); }
Example 8
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); }