46174
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
7 |
* contributor license agreements. See the NOTICE file distributed with
|
|
8 |
* this work for additional information regarding copyright ownership.
|
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
10 |
* (the "License"); you may not use this file except in compliance with
|
|
11 |
* the License. You may obtain a copy of the License at
|
|
12 |
*
|
|
13 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14 |
*
|
|
15 |
* Unless required by applicable law or agreed to in writing, software
|
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18 |
* See the License for the specific language governing permissions and
|
|
19 |
* limitations under the License.
|
|
20 |
*/
|
|
21 |
|
|
22 |
package com.sun.org.apache.bcel.internal.classfile;
|
|
23 |
|
|
24 |
import java.io.DataInput;
|
|
25 |
import java.io.DataOutputStream;
|
|
26 |
import java.io.IOException;
|
|
27 |
|
|
28 |
import com.sun.org.apache.bcel.internal.Const;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* This attribute exists for local or
|
|
32 |
* anonymous classes and ... there can be only one.
|
|
33 |
*
|
|
34 |
* @since 6.0
|
|
35 |
*/
|
|
36 |
public class EnclosingMethod extends Attribute {
|
|
37 |
|
|
38 |
// Pointer to the CONSTANT_Class_info structure representing the
|
|
39 |
// innermost class that encloses the declaration of the current class.
|
|
40 |
private int classIndex;
|
|
41 |
|
|
42 |
// If the current class is not immediately enclosed by a method or
|
|
43 |
// constructor, then the value of the method_index item must be zero.
|
|
44 |
// Otherwise, the value of the method_index item must point to a
|
|
45 |
// CONSTANT_NameAndType_info structure representing the name and the
|
|
46 |
// type of a method in the class referenced by the class we point
|
|
47 |
// to in the class_index. *It is the compiler responsibility* to
|
|
48 |
// ensure that the method identified by this index is the closest
|
|
49 |
// lexically enclosing method that includes the local/anonymous class.
|
|
50 |
private int methodIndex;
|
|
51 |
|
|
52 |
// Ctors - and code to read an attribute in.
|
|
53 |
EnclosingMethod(final int nameIndex, final int len, final DataInput input, final ConstantPool cpool) throws IOException {
|
|
54 |
this(nameIndex, len, input.readUnsignedShort(), input.readUnsignedShort(), cpool);
|
|
55 |
}
|
|
56 |
|
|
57 |
private EnclosingMethod(final int nameIndex, final int len, final int classIdx,final int methodIdx, final ConstantPool cpool) {
|
|
58 |
super(Const.ATTR_ENCLOSING_METHOD, nameIndex, len, cpool);
|
|
59 |
classIndex = classIdx;
|
|
60 |
methodIndex = methodIdx;
|
|
61 |
}
|
|
62 |
|
|
63 |
@Override
|
|
64 |
public void accept(final Visitor v) {
|
|
65 |
v.visitEnclosingMethod(this);
|
|
66 |
}
|
|
67 |
|
|
68 |
@Override
|
|
69 |
public Attribute copy(final ConstantPool constant_pool) {
|
|
70 |
return (Attribute) clone();
|
|
71 |
}
|
|
72 |
|
|
73 |
// Accessors
|
|
74 |
public final int getEnclosingClassIndex() {
|
|
75 |
return classIndex;
|
|
76 |
}
|
|
77 |
|
|
78 |
public final int getEnclosingMethodIndex() {
|
|
79 |
return methodIndex;
|
|
80 |
}
|
|
81 |
|
|
82 |
public final void setEnclosingClassIndex(final int idx) {
|
|
83 |
classIndex = idx;
|
|
84 |
}
|
|
85 |
|
|
86 |
public final void setEnclosingMethodIndex(final int idx) {
|
|
87 |
methodIndex = idx;
|
|
88 |
}
|
|
89 |
|
|
90 |
public final ConstantClass getEnclosingClass() {
|
|
91 |
final ConstantClass c =
|
|
92 |
(ConstantClass)super.getConstantPool().getConstant(classIndex,Const.CONSTANT_Class);
|
|
93 |
return c;
|
|
94 |
}
|
|
95 |
|
|
96 |
public final ConstantNameAndType getEnclosingMethod() {
|
|
97 |
if (methodIndex == 0) {
|
|
98 |
return null;
|
|
99 |
}
|
|
100 |
final ConstantNameAndType nat =
|
|
101 |
(ConstantNameAndType)super.getConstantPool().getConstant(methodIndex,Const.CONSTANT_NameAndType);
|
|
102 |
return nat;
|
|
103 |
}
|
|
104 |
|
|
105 |
@Override
|
|
106 |
public final void dump(final DataOutputStream file) throws IOException {
|
|
107 |
super.dump(file);
|
|
108 |
file.writeShort(classIndex);
|
|
109 |
file.writeShort(methodIndex);
|
|
110 |
}
|
|
111 |
}
|