Removed the getAnnotations() and getDeclaredAnnotations() methods from the HasAnnotations interface like we agreed as part of the last annotations discussion.  As a result, you can only inquire about an annotation if you have access to its class.  The visibility of the getAnnotations() and getDeclaredAnnotations() methods on JClassType was changed to default access to allow for testing.

Review by: jat

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1845 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/core/ext/typeinfo/HasAnnotations.java b/dev/core/src/com/google/gwt/core/ext/typeinfo/HasAnnotations.java
index 37d1cc1..7707c2f 100644
--- a/dev/core/src/com/google/gwt/core/ext/typeinfo/HasAnnotations.java
+++ b/dev/core/src/com/google/gwt/core/ext/typeinfo/HasAnnotations.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007 Google Inc.
+ * Copyright 2008 Google Inc.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
@@ -36,20 +36,6 @@
   <T extends Annotation> T getAnnotation(Class<T> annotationClass);
 
   /**
-   * Returns all annotations that are declared or inherited by this element.
-   * 
-   * @return annotations that are declared or inherited by this element
-   */
-  Annotation[] getAnnotations();
-
-  /**
-   * Returns annotations that are declared on this element.
-   * 
-   * @return annotations that are declared on this element
-   */
-  Annotation[] getDeclaredAnnotations();
-
-  /**
    * Returns <code>true</code> if this item has an annotation of the specified
    * type.
    * 
diff --git a/dev/core/src/com/google/gwt/core/ext/typeinfo/JAbstractMethod.java b/dev/core/src/com/google/gwt/core/ext/typeinfo/JAbstractMethod.java
index d8c6fa9..91b7f71 100644
--- a/dev/core/src/com/google/gwt/core/ext/typeinfo/JAbstractMethod.java
+++ b/dev/core/src/com/google/gwt/core/ext/typeinfo/JAbstractMethod.java
@@ -50,6 +50,18 @@
 
   private final List<JTypeParameter> typeParams = new ArrayList<JTypeParameter>();
 
+  JAbstractMethod(JAbstractMethod srcMethod) {
+    this.annotations = new Annotations(srcMethod.annotations);
+    this.bodyEnd = srcMethod.bodyEnd;
+    this.bodyStart = srcMethod.bodyStart;
+    this.declEnd = srcMethod.declEnd;
+    this.declStart = srcMethod.declStart;
+    this.isVarArgs = srcMethod.isVarArgs;
+    MetaData.copy(this, srcMethod.metaData);
+    this.modifierBits = srcMethod.modifierBits;
+    this.name = srcMethod.name;
+  }
+
   // Only the builder can construct
   JAbstractMethod(String name, int declStart, int declEnd, int bodyStart,
       int bodyEnd,
@@ -70,18 +82,6 @@
     }
   }
 
-  JAbstractMethod(JAbstractMethod srcMethod) {
-    this.annotations = new Annotations(srcMethod.annotations);
-    this.bodyEnd = srcMethod.bodyEnd;
-    this.bodyStart = srcMethod.bodyStart;
-    this.declEnd = srcMethod.declEnd;
-    this.declStart = srcMethod.declStart;
-    this.isVarArgs = srcMethod.isVarArgs;
-    MetaData.copy(this, srcMethod.metaData);
-    this.modifierBits = srcMethod.modifierBits;
-    this.name = srcMethod.name;
-  }
-
   public void addMetaData(String tagName, String[] values) {
     metaData.addMetaData(tagName, values);
   }
@@ -107,10 +107,6 @@
     return annotations.getAnnotation(annotationClass);
   }
 
-  public Annotation[] getAnnotations() {
-    return annotations.getAnnotations();
-  }
-
   public int getBodyEnd() {
     return bodyEnd;
   }
@@ -119,10 +115,6 @@
     return bodyStart;
   }
 
-  public Annotation[] getDeclaredAnnotations() {
-    return annotations.getDeclaredAnnotations();
-  }
-
   public int getDeclEnd() {
     return declEnd;
   }
@@ -258,6 +250,20 @@
     params.add(param);
   }
 
+  /**
+   * NOTE: This method is for testing purposes only.
+   */
+  Annotation[] getAnnotations() {
+    return annotations.getAnnotations();
+  }
+
+  /**
+   * NOTE: This method is for testing purposes only.
+   */
+  Annotation[] getDeclaredAnnotations() {
+    return annotations.getDeclaredAnnotations();
+  }
+
   boolean hasParamTypes(JType[] paramTypes) {
     if (params.size() != paramTypes.length) {
       return false;
diff --git a/dev/core/src/com/google/gwt/core/ext/typeinfo/JArrayType.java b/dev/core/src/com/google/gwt/core/ext/typeinfo/JArrayType.java
index fd67a67..910f5b8 100644
--- a/dev/core/src/com/google/gwt/core/ext/typeinfo/JArrayType.java
+++ b/dev/core/src/com/google/gwt/core/ext/typeinfo/JArrayType.java
@@ -83,11 +83,6 @@
   }
 
   @Override
-  public Annotation[] getAnnotations() {
-    return TypeOracle.NO_ANNOTATIONS;
-  }
-
-  @Override
   public int getBodyEnd() {
     return 0;
   }
@@ -118,11 +113,6 @@
   }
 
   @Override
-  public Annotation[] getDeclaredAnnotations() {
-    return TypeOracle.NO_ANNOTATIONS;
-  }
-
-  @Override
   public JClassType getEnclosingType() {
     return null;
   }
@@ -459,6 +449,22 @@
     return null;
   }
 
+  /**
+   * NOTE: This method is for testing purposes only.
+   */
+  @Override
+  Annotation[] getAnnotations() {
+    return TypeOracle.NO_ANNOTATIONS;
+  }
+
+  /**
+   * NOTE: This method is for testing purposes only.
+   */
+  @Override
+  Annotation[] getDeclaredAnnotations() {
+    return TypeOracle.NO_ANNOTATIONS;
+  }
+
   @Override
   JArrayType getSubstitutedType(JParameterizedType parameterizedType) {
     return oracle.getArrayType(getComponentType().getSubstitutedType(
diff --git a/dev/core/src/com/google/gwt/core/ext/typeinfo/JClassType.java b/dev/core/src/com/google/gwt/core/ext/typeinfo/JClassType.java
index be49e4e..db71429 100644
--- a/dev/core/src/com/google/gwt/core/ext/typeinfo/JClassType.java
+++ b/dev/core/src/com/google/gwt/core/ext/typeinfo/JClassType.java
@@ -114,7 +114,7 @@
     if (lhsType.isGenericType() != null) {
       lhsType = lhsType.isGenericType().getRawType();
     }
-    
+
     if (rhsType.isGenericType() != null) {
       // Treat the generic rhs type as a raw type.
       rhsType = rhsType.isGenericType().getRawType();
@@ -166,7 +166,7 @@
         // ? super T will reach object no matter what the rhs type is
         return true;
       }
-    } 
+    }
 
     // Check for JArrayTypes.
     JArrayType lhsArray = lhsType.isArray();
@@ -196,14 +196,12 @@
           return true;
         }
 
-        assert (lhsMaybeParameterized.isRawType() == null && 
-            rhsMaybeParameterized.isRawType() == null);
+        assert (lhsMaybeParameterized.isRawType() == null && rhsMaybeParameterized.isRawType() == null);
         JParameterizedType lhsParameterized = lhsMaybeParameterized.isParameterized();
         JParameterizedType rhsParameterized = rhsMaybeParameterized.isParameterized();
         assert (lhsParameterized != null && rhsParameterized != null);
 
-        return areTypeArgumentsAssignable(lhsParameterized,
-            rhsParameterized);
+        return areTypeArgumentsAssignable(lhsParameterized, rhsParameterized);
       }
     }
 
@@ -241,8 +239,7 @@
 
   /**
    * Returns <code>true</code> if the rhsWildcard can be assigned to the
-   * lhsWildcard.  This method does not consider supertypes of either
-   * lhs or rhs.
+   * lhsWildcard. This method does not consider supertypes of either lhs or rhs.
    */
   private static boolean areWildcardsAssignable(JWildcardType lhsWildcard,
       JWildcardType rhsWildcard) {
@@ -269,7 +266,7 @@
   }
 
   /**
-   * A restricted version of areClassTypesAssignable that is used for comparing 
+   * A restricted version of areClassTypesAssignable that is used for comparing
    * the type arguments of parameterized types, where the lhsTypeArg is the
    * container.
    */
@@ -296,7 +293,7 @@
         }
       }
     }
-    
+
     /*
      * At this point the arguments are not the same and they are not wildcards
      * so, they cannot be assignable, Eh.
@@ -341,8 +338,6 @@
   public abstract <T extends Annotation> T getAnnotation(
       Class<T> annotationClass);
 
-  public abstract Annotation[] getAnnotations();
-
   public abstract int getBodyEnd();
 
   public abstract int getBodyStart();
@@ -354,8 +349,6 @@
 
   public abstract JConstructor[] getConstructors();
 
-  public abstract Annotation[] getDeclaredAnnotations();
-
   public abstract JClassType getEnclosingType();
 
   public abstract JClassType getErasedType();
@@ -528,6 +521,20 @@
 
   abstract JClassType findNestedTypeImpl(String[] typeName, int index);
 
+  /**
+   * Returns all of the annotations declared or inherited by this instance. 
+   * 
+   * NOTE: This method is for testing purposes only.
+   */
+  abstract Annotation[] getAnnotations();
+
+  /**
+   * Returns all of the annotations declared on this instance. 
+   * 
+   * NOTE: This method is for testing purposes only.
+   */
+  abstract Annotation[] getDeclaredAnnotations();
+
   @Override
   abstract JClassType getSubstitutedType(JParameterizedType parameterizedType);
 
diff --git a/dev/core/src/com/google/gwt/core/ext/typeinfo/JDelegatingClassType.java b/dev/core/src/com/google/gwt/core/ext/typeinfo/JDelegatingClassType.java
index 62ab6cd..7f422d0 100644
--- a/dev/core/src/com/google/gwt/core/ext/typeinfo/JDelegatingClassType.java
+++ b/dev/core/src/com/google/gwt/core/ext/typeinfo/JDelegatingClassType.java
@@ -79,11 +79,6 @@
     return baseType.getAnnotation(annotationClass);
   }
 
-  @Override
-  public Annotation[] getAnnotations() {
-    return baseType.getAnnotations();
-  }
-
   public JClassType getBaseType() {
     return baseType;
   }
@@ -121,11 +116,6 @@
   }
 
   @Override
-  public Annotation[] getDeclaredAnnotations() {
-    return baseType.getDeclaredAnnotations();
-  }
-
-  @Override
   public JClassType getEnclosingType() {
     // TODO this can be wrong if the enclosing type is a parameterized type. For
     // example, if a generic class has a non-static generic inner class.
@@ -398,6 +388,22 @@
     return baseType.findNestedTypeImpl(typeName, index);
   }
 
+  /**
+   * NOTE: This method is for testing purposes only.
+   */
+  @Override
+  Annotation[] getAnnotations() {
+    return baseType.getAnnotations();
+  }
+
+  /**
+   * NOTE: This method is for testing purposes only.
+   */
+  @Override
+  Annotation[] getDeclaredAnnotations() {
+    return baseType.getDeclaredAnnotations();
+  }
+
   @Override
   void notifySuperTypes() {
   }
diff --git a/dev/core/src/com/google/gwt/core/ext/typeinfo/JField.java b/dev/core/src/com/google/gwt/core/ext/typeinfo/JField.java
index f7ce1d7..1de133b 100644
--- a/dev/core/src/com/google/gwt/core/ext/typeinfo/JField.java
+++ b/dev/core/src/com/google/gwt/core/ext/typeinfo/JField.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006 Google Inc.
+ * Copyright 2008 Google Inc.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
@@ -71,14 +71,6 @@
     return annotations.getAnnotation(annotationClass);
   }
 
-  public Annotation[] getAnnotations() {
-    return annotations.getAnnotations();
-  }
-
-  public Annotation[] getDeclaredAnnotations() {
-    return annotations.getDeclaredAnnotations();
-  }
-
   public JClassType getEnclosingType() {
     return enclosingType;
   }
@@ -162,4 +154,18 @@
     sb.append(getName());
     return sb.toString();
   }
+
+  /**
+   * NOTE: This method is for testing purposes only.
+   */
+  Annotation[] getAnnotations() {
+    return annotations.getAnnotations();
+  }
+
+  /**
+   * NOTE: This method is for testing purposes only.
+   */
+  Annotation[] getDeclaredAnnotations() {
+    return annotations.getDeclaredAnnotations();
+  }
 }
diff --git a/dev/core/src/com/google/gwt/core/ext/typeinfo/JPackage.java b/dev/core/src/com/google/gwt/core/ext/typeinfo/JPackage.java
index f3c6592..23ea00f 100644
--- a/dev/core/src/com/google/gwt/core/ext/typeinfo/JPackage.java
+++ b/dev/core/src/com/google/gwt/core/ext/typeinfo/JPackage.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007 Google Inc.
+ * Copyright 2008 Google Inc.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
@@ -52,14 +52,6 @@
     return annotations.getAnnotation(annotationClass);
   }
 
-  public Annotation[] getAnnotations() {
-    return annotations.getAnnotations();
-  }
-
-  public Annotation[] getDeclaredAnnotations() {
-    return annotations.getDeclaredAnnotations();
-  }
-
   public String getName() {
     return name;
   }
@@ -104,6 +96,20 @@
     }
   }
 
+  /**
+   * NOTE: This method is for testing purposes only.
+   */
+  Annotation[] getAnnotations() {
+    return annotations.getAnnotations();
+  }
+
+  /**
+   * NOTE: This method is for testing purposes only.
+   */
+  Annotation[] getDeclaredAnnotations() {
+    return annotations.getDeclaredAnnotations();
+  }
+
   void remove(JClassType type) {
     types.remove(type.getSimpleSourceName());
     // JDT will occasionally remove non-existent items, such as packages.
diff --git a/dev/core/src/com/google/gwt/core/ext/typeinfo/JParameter.java b/dev/core/src/com/google/gwt/core/ext/typeinfo/JParameter.java
index bf4b2b2..767cbea 100644
--- a/dev/core/src/com/google/gwt/core/ext/typeinfo/JParameter.java
+++ b/dev/core/src/com/google/gwt/core/ext/typeinfo/JParameter.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007 Google Inc.
+ * Copyright 2008 Google Inc.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
@@ -65,14 +65,6 @@
     return annotations.getAnnotation(annotationClass);
   }
 
-  public Annotation[] getAnnotations() {
-    return annotations.getAnnotations();
-  }
-
-  public Annotation[] getDeclaredAnnotations() {
-    return annotations.getDeclaredAnnotations();
-  }
-
   public JAbstractMethod getEnclosingMethod() {
     return enclosingMethod;
   }
@@ -105,6 +97,20 @@
     return sb.toString();
   }
 
+  /**
+   * NOTE: This method is for testing purposes only.
+   */
+  Annotation[] getAnnotations() {
+    return annotations.getAnnotations();
+  }
+
+  /**
+   * NOTE: This method is for testing purposes only.
+   */
+  Annotation[] getDeclaredAnnotations() {
+    return annotations.getDeclaredAnnotations();
+  }
+
   // Called when parameter types are found to be parameterized
   void setType(JType type) {
     this.type = type;
diff --git a/dev/core/src/com/google/gwt/core/ext/typeinfo/JRealClassType.java b/dev/core/src/com/google/gwt/core/ext/typeinfo/JRealClassType.java
index 78a0779..4e744ea 100644
--- a/dev/core/src/com/google/gwt/core/ext/typeinfo/JRealClassType.java
+++ b/dev/core/src/com/google/gwt/core/ext/typeinfo/JRealClassType.java
@@ -154,10 +154,6 @@
     return annotations.getAnnotation(annotationClass);
   }
 
-  public Annotation[] getAnnotations() {
-    return annotations.getAnnotations();
-  }
-
   public int getBodyEnd() {
     return bodyEnd;
   }
@@ -181,10 +177,6 @@
     return members.getConstructors();
   }
 
-  public Annotation[] getDeclaredAnnotations() {
-    return annotations.getDeclaredAnnotations();
-  }
-
   public JClassType getEnclosingType() {
     return enclosingType;
   }
@@ -536,6 +528,20 @@
     }
   }
 
+  /**
+   * NOTE: This method is for testing purposes only.
+   */
+  Annotation[] getAnnotations() {
+    return annotations.getAnnotations();
+  }
+
+  /**
+   * NOTE: This method is for testing purposes only.
+   */
+  Annotation[] getDeclaredAnnotations() {
+    return annotations.getDeclaredAnnotations();
+  }
+
   @Override
   JRealClassType getSubstitutedType(JParameterizedType parameterizedType) {
     return this;
diff --git a/dev/core/test/com/google/gwt/core/ext/typeinfo/JDelegatingClassTypeTestBase.java b/dev/core/test/com/google/gwt/core/ext/typeinfo/JDelegatingClassTypeTestBase.java
index d0058f8..cfeb03b 100644
--- a/dev/core/test/com/google/gwt/core/ext/typeinfo/JDelegatingClassTypeTestBase.java
+++ b/dev/core/test/com/google/gwt/core/ext/typeinfo/JDelegatingClassTypeTestBase.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007 Google Inc.
+ * Copyright 2008 Google Inc.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
@@ -39,7 +39,8 @@
     assertEquals(preSubMethod.getModifierBits(),
         postSubMethod.getModifierBits());
 
-    validateAnnotations(preSubMethod, postSubMethod);
+    validateAnnotations(preSubMethod.getAnnotations(),
+        postSubMethod.getAnnotations());
 
     validateMetaData(preSubMethod, postSubMethod);
 
@@ -52,7 +53,8 @@
       JParameter preSubParam = preSubParams[j];
       JParameter postSubParam = postSubParams[j];
 
-      validateAnnotations(preSubParam, postSubParam);
+      validateAnnotations(preSubParam.getAnnotations(),
+          postSubParam.getAnnotations());
       validateMetaData(preSubParam, postSubParam);
 
       assertEquals(substitution.getSubstitution(preSubParam.getType()),
@@ -60,9 +62,9 @@
     }
   }
 
-  protected static void validateAnnotations(HasAnnotations ha1,
-      HasAnnotations ha2) {
-    assertArraysEqual(ha1.getAnnotations(), ha2.getAnnotations());
+  protected static void validateAnnotations(Annotation[] expected,
+      Annotation[] actual) {
+    assertArraysEqual(expected, actual);
   }
 
   protected static void validateConstructorSubstitutions(
@@ -78,10 +80,9 @@
     }
   }
 
-  protected static void validateDeclaredAnnotations(HasAnnotations ha1,
-      HasAnnotations ha2) {
-    assertArraysEqual(ha1.getDeclaredAnnotations(),
-        ha2.getDeclaredAnnotations());
+  protected static void validateDeclaredAnnotations(Annotation[] expected,
+      Annotation[] actual) {
+    assertArraysEqual(expected, actual);
   }
 
   protected static void validateEquals(TypeOracle oracle,
@@ -276,11 +277,12 @@
     if (preSubstitution.isGenericType() == null) {
       return;
     }
-    
+
     assertEquals(preSubstitution.getModifierBits(),
         postSubstituion.getModifierBits());
 
-    validateAnnotations(preSubstitution, postSubstituion);
+    validateAnnotations(preSubstitution.getAnnotations(),
+        postSubstituion.getAnnotations());
 
     validateMetaData(preSubstitution, postSubstituion);
 
@@ -368,7 +370,7 @@
     JDelegatingClassType testType = getTestType();
     JClassType baseType = testType.getBaseType();
 
-    validateAnnotations(baseType, testType);
+    validateAnnotations(baseType.getAnnotations(), testType.getAnnotations());
   }
 
   /**
@@ -420,7 +422,8 @@
     JDelegatingClassType testType = getTestType();
     JClassType baseType = testType.getBaseType();
 
-    validateDeclaredAnnotations(baseType, testType);
+    validateDeclaredAnnotations(baseType.getDeclaredAnnotations(),
+        testType.getDeclaredAnnotations());
   }
 
   /**