1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
package org.apache.commons.classscan.bcel; |
15 | |
|
16 | |
import java.util.Set; |
17 | |
|
18 | |
import org.apache.bcel.classfile.AnnotationEntry; |
19 | |
import org.apache.bcel.classfile.ElementValuePair; |
20 | |
import org.apache.commons.classscan.builtin.ClassNameHelper; |
21 | |
import org.apache.commons.classscan.spi.model.SpiMetaAnnotation; |
22 | |
import org.apache.commons.classscan.spi.model.SpiMetaClassLoader; |
23 | |
import org.apache.commons.classscan.util.NameSet; |
24 | |
|
25 | |
public class BcelAnnotation implements SpiMetaAnnotation { |
26 | |
|
27 | |
private final String name; |
28 | |
private final NameSet<SpiProperty> properties; |
29 | |
|
30 | 32461 | public BcelAnnotation(AnnotationEntry annotation) { |
31 | 32461 | name = ClassNameHelper.internalToCanonicalName(annotation.getAnnotationType()); |
32 | |
|
33 | 32461 | ElementValuePair[] elementValuePairs = annotation.getElementValuePairs(); |
34 | 32461 | if (elementValuePairs.length == 0) { |
35 | 27093 | properties = NameSet.emptyNameSet(); |
36 | |
} |
37 | |
else { |
38 | 5368 | properties = new NameSet<SpiProperty>(fillMapAndArray(elementValuePairs)); |
39 | |
} |
40 | 32461 | } |
41 | |
|
42 | |
@Override |
43 | |
public boolean resolve(SpiMetaClassLoader classLoader) { |
44 | 32428 | return properties.resolve(classLoader); |
45 | |
} |
46 | |
|
47 | |
private SpiProperty[] fillMapAndArray(ElementValuePair[] evPairs) { |
48 | 5368 | SpiProperty[] values = new SpiProperty[evPairs.length]; |
49 | 11495 | for (int i = 0; i < evPairs.length; ++i) { |
50 | 6127 | values[i] = new BcelProperty(evPairs[i]); |
51 | |
} |
52 | 5368 | return values; |
53 | |
} |
54 | |
|
55 | |
@Override |
56 | |
public String getName() { |
57 | 4818 | return name; |
58 | |
} |
59 | |
|
60 | |
@Override |
61 | |
public Set<? extends Property> getProperties() { |
62 | 22 | return properties; |
63 | |
} |
64 | |
|
65 | |
@Override |
66 | |
public Property getProperty(String propertyName) { |
67 | 44 | return properties.getValue(propertyName); |
68 | |
} |
69 | |
} |