diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2014-09-15 20:37:58 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2014-09-15 20:37:58 -0400 |
commit | 6f87abbdabd02244a536acbf7f1895f4466a095d (patch) | |
tree | bf8819fd7a85b886dbd727157dae6a6a2b0db7d8 /sangria-core/src/main/java | |
parent | 7af926e2d02823c94a65310756f0ca7595908521 (diff) | |
parent | 75db2e06b7a6b1f15bad5986b33bc3aa1bb31f26 (diff) | |
download | sangria-6f87abbdabd02244a536acbf7f1895f4466a095d.tar.xz |
Merge branch 'lazy'
Diffstat (limited to 'sangria-core/src/main/java')
-rw-r--r-- | sangria-core/src/main/java/com/tavianator/sangria/core/PotentialAnnotation.java | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/sangria-core/src/main/java/com/tavianator/sangria/core/PotentialAnnotation.java b/sangria-core/src/main/java/com/tavianator/sangria/core/PotentialAnnotation.java index 302e5e1..7c3680f 100644 --- a/sangria-core/src/main/java/com/tavianator/sangria/core/PotentialAnnotation.java +++ b/sangria-core/src/main/java/com/tavianator/sangria/core/PotentialAnnotation.java @@ -29,7 +29,7 @@ import com.google.inject.spi.Message; * A record of stored annotations, perfect for builders with {@code annotatedWith()} methods. * * @author Tavian Barnes (tavianator@tavianator.com) - * @version 1.1 + * @version 1.2 * @since 1.1 */ public abstract class PotentialAnnotation { @@ -75,6 +75,24 @@ public abstract class PotentialAnnotation { return NONE; } + /** + * @return A {@link PotentialAnnotation} with the annotation from a {@link Key}. + * @since 1.2 + */ + public static PotentialAnnotation from(Key<?> key) { + Annotation instance = key.getAnnotation(); + if (instance != null) { + return none().annotatedWith(instance); + } + + Class<? extends Annotation> type = key.getAnnotationType(); + if (type != null) { + return none().annotatedWith(type); + } + + return none(); + } + private PotentialAnnotation() { } @@ -140,6 +158,12 @@ public abstract class PotentialAnnotation { public abstract <T> T accept(Visitor<T> visitor); @Override + public abstract boolean equals(Object o); + + @Override + public abstract int hashCode(); + + @Override public abstract String toString(); /** @@ -172,6 +196,16 @@ public abstract class PotentialAnnotation { } @Override + public boolean equals(Object o) { + return o == this || o instanceof NoAnnotation; + } + + @Override + public int hashCode() { + return NoAnnotation.class.hashCode(); + } + + @Override public String toString() { return "[no annotation]"; } @@ -203,6 +237,23 @@ public abstract class PotentialAnnotation { } @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } else if (!(o instanceof AnnotationType)) { + return false; + } + + AnnotationType other = (AnnotationType)o; + return annotationType.equals(other.annotationType); + } + + @Override + public int hashCode() { + return annotationType.hashCode(); + } + + @Override public String toString() { return "@" + annotationType.getCanonicalName(); } @@ -234,6 +285,23 @@ public abstract class PotentialAnnotation { } @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } else if (!(o instanceof AnnotationInstance)) { + return false; + } + + AnnotationInstance other = (AnnotationInstance)o; + return annotation.equals(other.annotation); + } + + @Override + public int hashCode() { + return annotation.hashCode(); + } + + @Override public String toString() { return annotation.toString(); } |