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 | |
|
37 | 33 | public enum ElementValueType { |
38 | 1 | BYTE(com.jeantessier.classreader.ElementValueType.BYTE) { |
39 | |
public ElementValue create(ConstantPool constantPool, DataInput in) throws IOException { |
40 | 2 | return new ByteConstantElementValue(constantPool, in); |
41 | |
} |
42 | |
}, |
43 | |
|
44 | 1 | CHAR(com.jeantessier.classreader.ElementValueType.CHAR) { |
45 | |
public ElementValue create(ConstantPool constantPool, DataInput in) throws IOException { |
46 | 1 | return new CharConstantElementValue(constantPool, in); |
47 | |
} |
48 | |
}, |
49 | |
|
50 | 1 | DOUBLE(com.jeantessier.classreader.ElementValueType.DOUBLE) { |
51 | |
public ElementValue create(ConstantPool constantPool, DataInput in) throws IOException { |
52 | 1 | return new DoubleConstantElementValue(constantPool, in); |
53 | |
} |
54 | |
}, |
55 | |
|
56 | 1 | FLOAT(com.jeantessier.classreader.ElementValueType.FLOAT) { |
57 | |
public ElementValue create(ConstantPool constantPool, DataInput in) throws IOException { |
58 | 1 | return new FloatConstantElementValue(constantPool, in); |
59 | |
} |
60 | |
}, |
61 | |
|
62 | 1 | INTEGER(com.jeantessier.classreader.ElementValueType.INTEGER) { |
63 | |
public ElementValue create(ConstantPool constantPool, DataInput in) throws IOException { |
64 | 1 | return new IntegerConstantElementValue(constantPool, in); |
65 | |
} |
66 | |
}, |
67 | |
|
68 | 1 | LONG(com.jeantessier.classreader.ElementValueType.LONG) { |
69 | |
public ElementValue create(ConstantPool constantPool, DataInput in) throws IOException { |
70 | 1 | return new LongConstantElementValue(constantPool, in); |
71 | |
} |
72 | |
}, |
73 | |
|
74 | 1 | SHORT(com.jeantessier.classreader.ElementValueType.SHORT) { |
75 | |
public ElementValue create(ConstantPool constantPool, DataInput in) throws IOException { |
76 | 1 | return new ShortConstantElementValue(constantPool, in); |
77 | |
} |
78 | |
}, |
79 | |
|
80 | 1 | BOOLEAN(com.jeantessier.classreader.ElementValueType.BOOLEAN) { |
81 | |
public ElementValue create(ConstantPool constantPool, DataInput in) throws IOException { |
82 | 1 | return new BooleanConstantElementValue(constantPool, in); |
83 | |
} |
84 | |
}, |
85 | |
|
86 | 1 | STRING(com.jeantessier.classreader.ElementValueType.STRING) { |
87 | |
public ElementValue create(ConstantPool constantPool, DataInput in) throws IOException { |
88 | 1 | return new StringConstantElementValue(constantPool, in); |
89 | |
} |
90 | |
}, |
91 | |
|
92 | 1 | ENUM(com.jeantessier.classreader.ElementValueType.ENUM) { |
93 | |
public ElementValue create(ConstantPool constantPool, DataInput in) throws IOException { |
94 | 4 | return new EnumElementValue(constantPool, in); |
95 | |
} |
96 | |
}, |
97 | |
|
98 | 1 | CLASS(com.jeantessier.classreader.ElementValueType.CLASS) { |
99 | |
public ElementValue create(ConstantPool constantPool, DataInput in) throws IOException { |
100 | 1 | return new ClassElementValue(constantPool, in); |
101 | |
} |
102 | |
}, |
103 | |
|
104 | 1 | ANNOTATION(com.jeantessier.classreader.ElementValueType.ANNOTATION) { |
105 | |
public ElementValue create(ConstantPool constantPool, DataInput in) throws IOException { |
106 | 1 | return new AnnotationElementValue(constantPool, in); |
107 | |
} |
108 | |
}, |
109 | |
|
110 | 1 | ARRAY(com.jeantessier.classreader.ElementValueType.ARRAY) { |
111 | |
public ElementValue create(ConstantPool constantPool, DataInput in) throws IOException { |
112 | 2 | return new ArrayElementValue(constantPool, in); |
113 | |
} |
114 | |
}; |
115 | |
|
116 | |
private final com.jeantessier.classreader.ElementValueType elementValueType; |
117 | |
|
118 | 13 | ElementValueType(com.jeantessier.classreader.ElementValueType elementValueType) { |
119 | 13 | this.elementValueType = elementValueType; |
120 | 13 | } |
121 | |
|
122 | |
public char getTag() { |
123 | 273 | return elementValueType.getTag(); |
124 | |
} |
125 | |
|
126 | |
public abstract ElementValue create(ConstantPool constantPool, DataInput in) throws IOException; |
127 | |
|
128 | |
public static ElementValueType forTag(char tag) { |
129 | 19 | ElementValueType result = null; |
130 | |
|
131 | 266 | for (ElementValueType elementValueType : values()) { |
132 | 247 | if (elementValueType.getTag() == tag) { |
133 | 18 | result = elementValueType; |
134 | |
} |
135 | |
} |
136 | |
|
137 | 19 | return result; |
138 | |
} |
139 | |
} |