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