1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| package com.jeantessier.classreader.impl; |
34 |
| |
35 |
| import java.io.*; |
36 |
| import java.util.*; |
37 |
| |
38 |
| import org.apache.log4j.*; |
39 |
| |
40 |
| import com.jeantessier.classreader.*; |
41 |
| |
42 |
| public abstract class Feature_info implements com.jeantessier.classreader.Feature_info { |
43 |
| private static final int ACC_PUBLIC = 0x0001; |
44 |
| private static final int ACC_PRIVATE = 0x0002; |
45 |
| private static final int ACC_PROTECTED = 0x0004; |
46 |
| private static final int ACC_STATIC = 0x0008; |
47 |
| private static final int ACC_FINAL = 0x0010; |
48 |
| private static final int ACC_SYNTHETIC = 0x1000; |
49 |
| |
50 |
| private Classfile classfile; |
51 |
| private int accessFlag; |
52 |
| private int nameIndex; |
53 |
| private int descriptorIndex; |
54 |
| private Collection<Attribute_info> attributes = new LinkedList<Attribute_info>(); |
55 |
| |
56 |
5020
| public Feature_info(Classfile classfile, DataInput in) throws IOException {
|
57 |
5020
| this(classfile, in, new AttributeFactory());
|
58 |
| } |
59 |
| |
60 |
5020
| public Feature_info(Classfile classfile, DataInput in, AttributeFactory attributeFactory) throws IOException {
|
61 |
5020
| this.classfile = classfile;
|
62 |
| |
63 |
5020
| accessFlag = in.readUnsignedShort();
|
64 |
5020
| Logger.getLogger(getClass()).debug(getFeatureType() + " access flag: " + accessFlag);
|
65 |
| |
66 |
5020
| nameIndex = in.readUnsignedShort();
|
67 |
5020
| Logger.getLogger(getClass()).debug(getFeatureType() + " name: " + nameIndex + " (" + getName() + ")");
|
68 |
| |
69 |
5020
| descriptorIndex = in.readUnsignedShort();
|
70 |
5020
| Logger.getLogger(getClass()).debug(getFeatureType() + " Descriptor: " + descriptorIndex + " (" + getDescriptor() + ")");
|
71 |
| |
72 |
5020
| int attributeCount = in.readUnsignedShort();
|
73 |
5020
| Logger.getLogger(getClass()).debug("Reading " + attributeCount + " " + getFeatureType() + " attribute(s)");
|
74 |
5020
| for (int i=0; i<attributeCount; i++) {
|
75 |
4184
| Logger.getLogger(getClass()).debug(getFeatureType() + " attribute " + i + ":");
|
76 |
4184
| attributes.add(attributeFactory.create(getClassfile().getConstantPool(), this, in));
|
77 |
| } |
78 |
| } |
79 |
| |
80 |
218637
| public Classfile getClassfile() {
|
81 |
218637
| return classfile;
|
82 |
| } |
83 |
| |
84 |
117669
| public int getAccessFlag() {
|
85 |
117669
| return accessFlag;
|
86 |
| } |
87 |
| |
88 |
16313
| public boolean isPublic() {
|
89 |
16313
| return (getAccessFlag() & ACC_PUBLIC) != 0;
|
90 |
| } |
91 |
| |
92 |
15347
| public boolean isProtected() {
|
93 |
15347
| return (getAccessFlag() & ACC_PROTECTED) != 0;
|
94 |
| } |
95 |
| |
96 |
15164
| public boolean isPrivate() {
|
97 |
15164
| return (getAccessFlag() & ACC_PRIVATE) != 0;
|
98 |
| } |
99 |
| |
100 |
99
| public boolean isPackage() {
|
101 |
99
| return (getAccessFlag() & (ACC_PUBLIC | ACC_PROTECTED | ACC_PRIVATE)) == 0;
|
102 |
| } |
103 |
| |
104 |
16136
| public boolean isStatic() {
|
105 |
16136
| return (getAccessFlag() & ACC_STATIC) != 0;
|
106 |
| } |
107 |
| |
108 |
15340
| public boolean isFinal() {
|
109 |
15340
| return (getAccessFlag() & ACC_FINAL) != 0;
|
110 |
| } |
111 |
| |
112 |
0
| public int getNameIndex() {
|
113 |
0
| return nameIndex;
|
114 |
| } |
115 |
| |
116 |
136824
| public UTF8_info getRawName() {
|
117 |
136824
| return (UTF8_info) getClassfile().getConstantPool().get(nameIndex);
|
118 |
| } |
119 |
| |
120 |
136760
| public String getName() {
|
121 |
136760
| return getRawName().getValue();
|
122 |
| } |
123 |
| |
124 |
267
| public String getFullName() {
|
125 |
267
| return getClassfile().getClassName() + "." + getName();
|
126 |
| } |
127 |
| |
128 |
0
| public int getDescriptorIndex() {
|
129 |
0
| return descriptorIndex;
|
130 |
| } |
131 |
| |
132 |
54433
| public UTF8_info getRawDescriptor() {
|
133 |
54433
| return (UTF8_info) getClassfile().getConstantPool().get(descriptorIndex);
|
134 |
| } |
135 |
| |
136 |
54433
| public String getDescriptor() {
|
137 |
54433
| return getRawDescriptor().getValue();
|
138 |
| } |
139 |
| |
140 |
21046
| public Collection<Attribute_info> getAttributes() {
|
141 |
21046
| return attributes;
|
142 |
| } |
143 |
| |
144 |
1065
| public boolean isSynthetic() {
|
145 |
1065
| return isSyntheticFromAccessFlag() || isSyntheticFromAttribute();
|
146 |
| } |
147 |
| |
148 |
1065
| private boolean isSyntheticFromAccessFlag() {
|
149 |
1065
| return (getAccessFlag() & ACC_SYNTHETIC) != 0;
|
150 |
| } |
151 |
| |
152 |
1065
| private boolean isSyntheticFromAttribute() {
|
153 |
1065
| boolean result = false;
|
154 |
| |
155 |
1065
| Iterator i = getAttributes().iterator();
|
156 |
1065
| while (!result && i.hasNext()) {
|
157 |
776
| result = i.next() instanceof Synthetic_attribute;
|
158 |
| } |
159 |
| |
160 |
1065
| return result;
|
161 |
| } |
162 |
| |
163 |
8076
| public boolean isDeprecated() {
|
164 |
8076
| boolean result = false;
|
165 |
| |
166 |
8076
| Iterator i = getAttributes().iterator();
|
167 |
8076
| while (!result && i.hasNext()) {
|
168 |
7489
| result = i.next() instanceof Deprecated_attribute;
|
169 |
| } |
170 |
| |
171 |
8076
| return result;
|
172 |
| } |
173 |
| |
174 |
5
| public boolean isGeneric() {
|
175 |
5
| SignatureFinder finder = new SignatureFinder();
|
176 |
5
| accept(finder);
|
177 |
5
| return finder.getSignature() != null;
|
178 |
| } |
179 |
| |
180 |
5397
| public String getFullSignature() {
|
181 |
5397
| return getClassfile().getClassName() + "." + getSignature();
|
182 |
| } |
183 |
| |
184 |
| |
185 |
| |
186 |
| |
187 |
| |
188 |
| protected abstract String getFeatureType(); |
189 |
| |
190 |
0
| public String toString() {
|
191 |
0
| return getFullName();
|
192 |
| } |
193 |
| } |