1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.codehaus.plexus.metadata.ann;
18
19 import java.util.HashMap;
20 import java.util.LinkedHashMap;
21 import java.util.Map;
22
23 import org.objectweb.asm.Type;
24
25
26
27
28 public class AnnMethod {
29
30 private final AnnClass owner;
31 private final int access;
32 private final String name;
33 private final String desc;
34 private Map<String, Ann> anns = new LinkedHashMap<String, Ann>();
35 private Map<Integer, Map<String, Ann>> paramAnns = new HashMap<Integer, Map<String, Ann>>();
36
37 public AnnMethod(AnnClass owner, int access, String name, String desc) {
38 this.owner = owner;
39 this.access = access;
40 this.name = name;
41 this.desc = desc;
42 }
43
44 public int getAccess() {
45 return access;
46 }
47
48 public String getName() {
49 return name;
50 }
51
52 public String getDesc() {
53 return desc;
54 }
55
56 public Map<String, Ann> getAnns() {
57 return anns;
58 }
59
60 public Map<Integer, Map<String, Ann>> getParamAnns() {
61 return paramAnns;
62 }
63
64 public void addAnn(Ann ann) {
65 anns.put(ann.getDesc(), ann);
66 }
67
68 public void addParamAnn(int parameter, Ann ann) {
69 Map<String, Ann> anns = paramAnns.get(parameter);
70 if (anns == null) {
71 anns = new LinkedHashMap<String, Ann>();
72 paramAnns.put(parameter, anns);
73 }
74 anns.put(ann.getDesc(), ann);
75 }
76
77 public <T> T getAnnotation(Class<T> c) {
78 Ann ann = anns.get(Type.getDescriptor(c));
79 return ann == null ? null : ann.getAnnotation(c, owner.getClassLoader());
80 }
81
82 public <T> T getParameterAnnotation(int parameter, Class<T> c) {
83 Map<String, Ann> anns = paramAnns.get(parameter);
84 if (anns == null) {
85 return null;
86 }
87 Ann ann = anns.get(Type.getDescriptor(c));
88 return ann == null ? null : ann.getAnnotation(c, owner.getClassLoader());
89 }
90 }