01: /*
02: * Copyright 2000-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
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,
29: AllocationInstruction, 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: public NEW(int index) {
39: super (org.apache.bcel.Constants.NEW, index);
40: }
41:
42: public Class[] getExceptions() {
43: Class[] cs = new Class[2 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length];
44: System
45: .arraycopy(
46: ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION,
47: 0,
48: cs,
49: 0,
50: ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length);
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: return cs;
54: }
55:
56: public ObjectType getLoadClassType(ConstantPoolGen cpg) {
57: return (ObjectType) getType(cpg);
58: }
59:
60: /**
61: * Call corresponding visitor method(s). The order is:
62: * Call visitor methods of implemented interfaces first, then
63: * call methods according to the class hierarchy in descending order,
64: * i.e., the most specific visitXXX() call comes last.
65: *
66: * @param v Visitor object
67: */
68: public void accept(Visitor v) {
69: v.visitLoadClass(this);
70: v.visitAllocationInstruction(this);
71: v.visitExceptionThrower(this);
72: v.visitStackProducer(this);
73: v.visitTypedInstruction(this);
74: v.visitCPInstruction(this);
75: v.visitNEW(this);
76: }
77: }
|