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 * ANEWARRAY - Create new array of references
23 * <PRE>Stack: ..., count -> ..., arrayref</PRE>
24 *
25 * @version $Id: ANEWARRAY.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 ANEWARRAY extends CPInstruction implements LoadClass, AllocationInstruction,
29 ExceptionThrower, StackConsumer, StackProducer {
30
31 /***
32 * Empty constructor needed for the Class.newInstance() statement in
33 * Instruction.readInstruction(). Not to be used otherwise.
34 */
35 ANEWARRAY() {
36 }
37
38
39 public ANEWARRAY(int index) {
40 super(org.apache.bcel.Constants.ANEWARRAY, index);
41 }
42
43
44 public Class[] getExceptions() {
45 Class[] cs = new Class[1 + 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] = ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION;
49 return cs;
50 }
51
52
53 /***
54 * Call corresponding visitor method(s). The order is:
55 * Call visitor methods of implemented interfaces first, then
56 * call methods according to the class hierarchy in descending order,
57 * i.e., the most specific visitXXX() call comes last.
58 *
59 * @param v Visitor object
60 */
61 public void accept( Visitor v ) {
62 v.visitLoadClass(this);
63 v.visitAllocationInstruction(this);
64 v.visitExceptionThrower(this);
65 v.visitStackProducer(this);
66 v.visitTypedInstruction(this);
67 v.visitCPInstruction(this);
68 v.visitANEWARRAY(this);
69 }
70
71
72 public ObjectType getLoadClassType( ConstantPoolGen cpg ) {
73 Type t = getType(cpg);
74 if (t instanceof ArrayType) {
75 t = ((ArrayType) t).getBasicType();
76 }
77 return (t instanceof ObjectType) ? (ObjectType) t : null;
78 }
79 }