|
1 |
| package koala.dynamicjava.tree; |
|
2 |
| |
|
3 |
| import java.util.EnumSet; |
|
4 |
| import java.util.LinkedList; |
|
5 |
| import java.util.List; |
|
6 |
| import java.util.Set; |
|
7 |
| |
|
8 |
| import koala.dynamicjava.tree.visitor.Visitor; |
|
9 |
| |
|
10 |
| public class ModifierSet extends Node { |
|
11 |
| |
|
12 |
| private final Set<Modifier> flags; |
|
13 |
| private final List<Annotation> annotations; |
|
14 |
| |
|
15 |
17
| public ModifierSet(Set<Modifier> flgs, List<Annotation> annots) {
|
|
16 |
17
| this(flgs, annots, SourceInfo.NONE);
|
|
17 |
| } |
|
18 |
| |
|
19 |
2124
| public ModifierSet(Set<Modifier> flgs, List<Annotation> annots, SourceInfo si) {
|
|
20 |
2124
| super(si);
|
|
21 |
2124
| flags = flgs;
|
|
22 |
2124
| annotations = annots;
|
|
23 |
| } |
|
24 |
| |
|
25 |
0
| @Override public <T> T acceptVisitor(Visitor<T> visitor) {
|
|
26 |
0
| return visitor.visit(this);
|
|
27 |
| } |
|
28 |
| |
|
29 |
1695
| public Set<Modifier> getFlags() { return flags; }
|
|
30 |
| |
|
31 |
0
| public List<Annotation> getAnnotations() { return annotations; }
|
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
178
| public int getBitVector(Modifier... forced) {
|
|
38 |
178
| int result = 0;
|
|
39 |
178
| for (Modifier m : flags) {
|
|
40 |
199
| result |= m.getBits();
|
|
41 |
| } |
|
42 |
178
| for (Modifier m : forced) {
|
|
43 |
0
| result |= m.getBits();
|
|
44 |
| } |
|
45 |
178
| return result;
|
|
46 |
| } |
|
47 |
| |
|
48 |
0
| public boolean isEmpty() { return flags.isEmpty() && annotations.isEmpty(); }
|
|
49 |
| |
|
50 |
500
| public boolean isPublic() { return flags.contains(Modifier.PUBLIC); }
|
|
51 |
322
| public boolean isPrivate() { return flags.contains(Modifier.PRIVATE); }
|
|
52 |
322
| public boolean isProtected() { return flags.contains(Modifier.PROTECTED); }
|
|
53 |
| |
|
54 |
207
| public boolean isStatic() { return flags.contains(Modifier.STATIC); }
|
|
55 |
1180
| public boolean isFinal() { return flags.contains(Modifier.FINAL); }
|
|
56 |
370
| public boolean isAbstract() { return flags.contains(Modifier.ABSTRACT); }
|
|
57 |
| |
|
58 |
0
| public boolean isVolatile() { return flags.contains(Modifier.VOLATILE); }
|
|
59 |
0
| public boolean isTransient() { return flags.contains(Modifier.TRANSIENT); }
|
|
60 |
| |
|
61 |
0
| public boolean isSynchronized() { return flags.contains(Modifier.SYNCHRONIZED); }
|
|
62 |
158
| public boolean isNative() { return flags.contains(Modifier.NATIVE); }
|
|
63 |
0
| public boolean isStrict() { return flags.contains(Modifier.STRICT); }
|
|
64 |
| |
|
65 |
0
| public boolean isInterface() { return flags.contains(Modifier.INTERFACE); }
|
|
66 |
0
| public boolean isAnnotation() { return flags.contains(Modifier.ANNOTATION); }
|
|
67 |
0
| public boolean isEnum() { return flags.contains(Modifier.ENUM); }
|
|
68 |
0
| public boolean isBridge() { return flags.contains(Modifier.BRIDGE); }
|
|
69 |
0
| public boolean isVarargs() { return flags.contains(Modifier.VARARGS); }
|
|
70 |
0
| public boolean isSynthetic() { return flags.contains(Modifier.SYNTHETIC); }
|
|
71 |
| |
|
72 |
32
| public String toString() {
|
|
73 |
32
| return "(" + getClass().getName() + ": " + flags + ", " + annotations + ")";
|
|
74 |
| } |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
8
| public static ModifierSet make() {
|
|
79 |
8
| return new ModifierSet(EnumSet.noneOf(Modifier.class), new LinkedList<Annotation>());
|
|
80 |
| } |
|
81 |
| |
|
82 |
2
| public static ModifierSet make(Modifier mod, Modifier... mods) {
|
|
83 |
2
| return new ModifierSet(EnumSet.of(mod, mods), new LinkedList<Annotation>());
|
|
84 |
| } |
|
85 |
| |
|
86 |
7
| public static ModifierSet make(Annotation ann, Annotation... anns) {
|
|
87 |
7
| LinkedList<Annotation> l = new LinkedList<Annotation>();
|
|
88 |
7
| l.add(ann);
|
|
89 |
0
| for (Annotation a : anns) { l.add(a); }
|
|
90 |
7
| return new ModifierSet(EnumSet.noneOf(Modifier.class), l);
|
|
91 |
| } |
|
92 |
| |
|
93 |
| public enum Modifier { |
|
94 |
| PUBLIC { |
|
95 |
166
| public int getBits() { return 0x0001; }
|
|
96 |
0
| public String getName() { return "public"; }
|
|
97 |
| }, |
|
98 |
| PRIVATE { |
|
99 |
12
| public int getBits() { return 0x0002; }
|
|
100 |
0
| public String getName() { return "private"; }
|
|
101 |
| }, |
|
102 |
| PROTECTED { |
|
103 |
0
| public int getBits() { return 0x0004; }
|
|
104 |
0
| public String getName() { return "protected"; }
|
|
105 |
| }, |
|
106 |
| STATIC { |
|
107 |
0
| public int getBits() { return 0x0008; }
|
|
108 |
0
| public String getName() { return "static"; }
|
|
109 |
| }, |
|
110 |
| FINAL { |
|
111 |
0
| public int getBits() { return 0x0010; }
|
|
112 |
0
| public String getName() { return "final"; }
|
|
113 |
| }, |
|
114 |
| ABSTRACT { |
|
115 |
0
| public int getBits() { return 0x0400; }
|
|
116 |
0
| public String getName() { return "abstract"; }
|
|
117 |
| }, |
|
118 |
| VOLATILE { |
|
119 |
0
| public int getBits() { return 0x0040; }
|
|
120 |
0
| public String getName() { return "volatile"; }
|
|
121 |
| }, |
|
122 |
| TRANSIENT { |
|
123 |
0
| public int getBits() { return 0x0080; }
|
|
124 |
0
| public String getName() { return "transient"; }
|
|
125 |
| }, |
|
126 |
| SYNCHRONIZED { |
|
127 |
0
| public int getBits() { return 0x0020; }
|
|
128 |
0
| public String getName() { return "synchronized"; }
|
|
129 |
| }, |
|
130 |
| NATIVE { |
|
131 |
0
| public int getBits() { return 0x0100; }
|
|
132 |
0
| public String getName() { return "native"; }
|
|
133 |
| }, |
|
134 |
| STRICT { |
|
135 |
0
| public int getBits() { return 0x0800; }
|
|
136 |
0
| public String getName() { return "strictfp"; }
|
|
137 |
| }, |
|
138 |
| INTERFACE { |
|
139 |
0
| public int getBits() { return 0x0200; }
|
|
140 |
0
| public String getName() { return "[interface]"; }
|
|
141 |
| }, |
|
142 |
| ANNOTATION { |
|
143 |
0
| public int getBits() { return 0x2000; }
|
|
144 |
0
| public String getName() { return "[annotation]"; }
|
|
145 |
| }, |
|
146 |
| ENUM { |
|
147 |
0
| public int getBits() { return 0x4000; }
|
|
148 |
0
| public String getName() { return "[enum]"; }
|
|
149 |
| }, |
|
150 |
| BRIDGE { |
|
151 |
0
| public int getBits() { return 0x0040; }
|
|
152 |
0
| public String getName() { return "[bridge]"; }
|
|
153 |
| }, |
|
154 |
| VARARGS { |
|
155 |
56
| public int getBits() { return 0x0080; }
|
|
156 |
0
| public String getName() { return "[varargs]"; }
|
|
157 |
| }, |
|
158 |
| SYNTHETIC { |
|
159 |
0
| public int getBits() { return 0x1000; }
|
|
160 |
0
| public String getName() { return "[synthetic]"; }
|
|
161 |
| }; |
|
162 |
| |
|
163 |
| |
|
164 |
| public abstract int getBits(); |
|
165 |
| |
|
166 |
| public abstract String getName(); |
|
167 |
| } |
|
168 |
| |
|
169 |
| } |