View Javadoc
1   /*
2    * Copyright (C) 2008 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.codehaus.plexus.metadata.ann;
18  
19  import java.util.LinkedHashMap;
20  import java.util.Map;
21  
22  import org.objectweb.asm.Type;
23  
24  /**
25   * @author Eugene Kuleshov
26   */
27  public class AnnField {
28  
29    private final AnnClass owner;
30    private final int access;
31    private final String name;
32    private final String desc;
33    private Map<String, Ann> anns = new LinkedHashMap<String,Ann>();
34    
35    public AnnField(AnnClass owner, int access, String name, String desc) {
36      this.owner = owner;
37      this.access = access;
38      this.desc = desc;
39      this.name = name;
40    }
41  
42    public int getAccess() {
43      return access;
44    }
45    
46    public String getName() {
47      return name;
48    }
49    
50    public String getDesc() {
51      return desc;
52    }
53    
54    public Map<String, Ann> getAnns() {
55      return anns;
56    }
57    
58    public String getType() {
59      return Type.getType(desc).getClassName();
60    }
61  
62    public void addAnn(Ann ann) {
63      anns.put(ann.getDesc(), ann);
64    }
65    
66    public <T> T getAnnotation(Class<T> c) {
67      Ann ann = anns.get(Type.getDescriptor(c));
68      return ann == null ? null : ann.getAnnotation(c, owner.getClassLoader());
69    }
70  
71  }
72