1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jadira.scanner.classpath.types;
17
18 import java.util.Set;
19
20 import org.apache.commons.lang3.builder.EqualsBuilder;
21 import org.apache.commons.lang3.builder.HashCodeBuilder;
22 import org.apache.commons.lang3.builder.ToStringBuilder;
23 import org.apache.commons.lang3.builder.ToStringStyle;
24 import org.jadira.scanner.classpath.ClasspathResolver;
25 import org.jadira.scanner.core.exception.ClasspathAccessException;
26
27 public abstract class JVariable extends JElement {
28
29 protected JVariable(String name, ClasspathResolver resolver) {
30 super(name, resolver);
31 }
32
33 public abstract JType getEnclosingType() throws ClasspathAccessException;
34
35 public abstract JType getType() throws ClasspathAccessException;
36
37 @Override
38 public abstract Set<JAnnotation<?>> getAnnotations() throws ClasspathAccessException;
39
40 @Override
41 public <A extends java.lang.annotation.Annotation> JAnnotation<A> getAnnotation(Class<A> annotation) throws ClasspathAccessException {
42
43 Set<JAnnotation<?>> inspAnnotations = getAnnotations();
44 for (JAnnotation<?> next : inspAnnotations) {
45 if (next.getName().equals(annotation.getName())
46 && (next.getActualAnnotation().getClass().equals(annotation.getClass()))) {
47 @SuppressWarnings("unchecked") JAnnotation<A> retVal = (JAnnotation<A>)next;
48 return retVal;
49 }
50 }
51 return null;
52 }
53
54 @Override
55 public String toString() {
56
57 ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
58 builder.append("name", this.getName());
59 builder.append("type", this.getType());
60 builder.append("enclosingType", this.getEnclosingType());
61
62 return builder.toString();
63 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (obj == null) {
68 return false;
69 }
70 if (obj == this) {
71 return true;
72 }
73 if (obj.getClass() != getClass()) {
74 return false;
75 }
76
77 return new EqualsBuilder()
78 .appendSuper(super.equals(obj))
79 .isEquals();
80 }
81
82 @Override
83 public int hashCode() {
84 return new HashCodeBuilder(11, 47).append(super.hashCode())
85 .toHashCode();
86 }
87 }