View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.util.annotation;
8   
9   import java.lang.annotation.Annotation;
10  import java.lang.annotation.ElementType;
11  import java.lang.reflect.Member;
12  
13  /**
14   * A data class that associates context information about an annotation. This class allows for associated annotation data
15   * to be passed between methods.
16   */
17  public class AnnotationMetaData
18  {
19      private ElementType type;
20  
21      private Member member;
22  
23      private Class clazz;
24  
25      private Annotation annotation;
26  
27      public AnnotationMetaData(Class clazz, Member member, ElementType type, Annotation annotation)
28      {
29          this.type = type;
30          this.clazz = clazz;
31          this.member = member;
32          this.annotation = annotation;
33      }
34  
35      public ElementType getType()
36      {
37          return type;
38      }
39  
40      public String getElementName()
41      {
42          if (member == null)
43          {
44              return clazz.getName();
45          }
46          return member.getName();
47      }
48  
49      public Annotation getAnnotation()
50      {
51          return annotation;
52      }
53  
54      public Member getMember()
55      {
56          return member;
57      }
58  
59      public Class getClazz()
60      {
61          return clazz;
62      }
63  
64      @Override
65      public String toString()
66      {
67          return "AnnotationMetaData{" +
68                  "type=" + type +
69                  ", member=" + member +
70                  ", clazz=" + clazz +
71                  ", annotation=" + annotation +
72                  '}';
73      }
74  
75      @Override
76      public boolean equals(Object o)
77      {
78          if (this == o)
79          {
80              return true;
81          }
82          if (o == null || getClass() != o.getClass())
83          {
84              return false;
85          }
86  
87          AnnotationMetaData that = (AnnotationMetaData) o;
88  
89          if (annotation != null ? !annotation.equals(that.annotation) : that.annotation != null)
90          {
91              return false;
92          }
93          if (clazz != null ? !clazz.equals(that.clazz) : that.clazz != null)
94          {
95              return false;
96          }
97          if (member != null ? !member.equals(that.member) : that.member != null)
98          {
99              return false;
100         }
101         if (type != that.type)
102         {
103             return false;
104         }
105 
106         return true;
107     }
108 
109     @Override
110     public int hashCode()
111     {
112         int result = type != null ? type.hashCode() : 0;
113         result = 31 * result + (member != null ? member.hashCode() : 0);
114         result = 31 * result + (clazz != null ? clazz.hashCode() : 0);
115         result = 31 * result + (annotation != null ? annotation.hashCode() : 0);
116         return result;
117     }
118 }