19 * limitations under the License. |
19 * limitations under the License. |
20 */ |
20 */ |
21 |
21 |
22 package com.sun.org.apache.bcel.internal.generic; |
22 package com.sun.org.apache.bcel.internal.generic; |
23 |
23 |
24 import java.io.*; |
24 import com.sun.org.apache.bcel.internal.ExceptionConst; |
25 import com.sun.org.apache.bcel.internal.ExceptionConstants; |
|
26 |
25 |
27 /** |
26 /** |
28 * NEW - Create new object |
27 * NEW - Create new object |
29 * <PRE>Stack: ... -> ..., objectref</PRE> |
28 * <PRE>Stack: ... -> ..., objectref</PRE> |
30 * |
29 * |
31 * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> |
30 * @version $Id: NEW.java 1747278 2016-06-07 17:28:43Z britter $ |
32 */ |
31 */ |
33 public class NEW extends CPInstruction |
32 public class NEW extends CPInstruction implements LoadClass, AllocationInstruction, |
34 implements LoadClass, AllocationInstruction, ExceptionThrower, StackProducer { |
33 ExceptionThrower, StackProducer { |
35 /** |
|
36 * Empty constructor needed for the Class.newInstance() statement in |
|
37 * Instruction.readInstruction(). Not to be used otherwise. |
|
38 */ |
|
39 NEW() {} |
|
40 |
34 |
41 public NEW(int index) { |
35 /** |
42 super(com.sun.org.apache.bcel.internal.Constants.NEW, index); |
36 * Empty constructor needed for the Class.newInstance() statement in |
43 } |
37 * Instruction.readInstruction(). Not to be used otherwise. |
|
38 */ |
|
39 NEW() { |
|
40 } |
44 |
41 |
45 public Class[] getExceptions(){ |
|
46 Class[] cs = new Class[2 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length]; |
|
47 |
42 |
48 System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0, |
43 public NEW(final int index) { |
49 cs, 0, ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length); |
44 super(com.sun.org.apache.bcel.internal.Const.NEW, index); |
|
45 } |
50 |
46 |
51 cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length+1] = ExceptionConstants.INSTANTIATION_ERROR; |
|
52 cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = ExceptionConstants.ILLEGAL_ACCESS_ERROR; |
|
53 |
47 |
54 return cs; |
48 @Override |
55 } |
49 public Class<?>[] getExceptions() { |
|
50 return ExceptionConst.createExceptions(ExceptionConst.EXCS.EXCS_CLASS_AND_INTERFACE_RESOLUTION, |
|
51 ExceptionConst.ILLEGAL_ACCESS_ERROR, |
|
52 ExceptionConst.INSTANTIATION_ERROR); |
|
53 } |
56 |
54 |
57 public ObjectType getLoadClassType(ConstantPoolGen cpg) { |
|
58 return (ObjectType)getType(cpg); |
|
59 } |
|
60 |
55 |
61 /** |
56 @Override |
62 * Call corresponding visitor method(s). The order is: |
57 public ObjectType getLoadClassType( final ConstantPoolGen cpg ) { |
63 * Call visitor methods of implemented interfaces first, then |
58 return (ObjectType) getType(cpg); |
64 * call methods according to the class hierarchy in descending order, |
59 } |
65 * i.e., the most specific visitXXX() call comes last. |
60 |
66 * |
61 |
67 * @param v Visitor object |
62 /** |
68 */ |
63 * Call corresponding visitor method(s). The order is: |
69 public void accept(Visitor v) { |
64 * Call visitor methods of implemented interfaces first, then |
70 v.visitLoadClass(this); |
65 * call methods according to the class hierarchy in descending order, |
71 v.visitAllocationInstruction(this); |
66 * i.e., the most specific visitXXX() call comes last. |
72 v.visitExceptionThrower(this); |
67 * |
73 v.visitStackProducer(this); |
68 * @param v Visitor object |
74 v.visitTypedInstruction(this); |
69 */ |
75 v.visitCPInstruction(this); |
70 @Override |
76 v.visitNEW(this); |
71 public void accept( final Visitor v ) { |
77 } |
72 v.visitLoadClass(this); |
|
73 v.visitAllocationInstruction(this); |
|
74 v.visitExceptionThrower(this); |
|
75 v.visitStackProducer(this); |
|
76 v.visitTypedInstruction(this); |
|
77 v.visitCPInstruction(this); |
|
78 v.visitNEW(this); |
|
79 } |
78 } |
80 } |