Allows annotation types to be used as normal interfaces in web mode.
Review by: mmendez
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1745 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java b/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java
index 60f2288..5b4a526 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/BuildTypeMap.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
@@ -50,6 +50,7 @@
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.AllocationExpression;
+import org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.Argument;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
@@ -154,6 +155,12 @@
}
@Override
+ public boolean visit(AnnotationMethodDeclaration methodDeclaration,
+ ClassScope scope) {
+ return visit((MethodDeclaration) methodDeclaration, scope);
+ }
+
+ @Override
public boolean visit(Argument argument, BlockScope scope) {
try {
if (scope == scope.methodScope()) {
@@ -511,10 +518,7 @@
currentSeparatorPositions = compResult.lineSeparatorPositions;
currentFileName = String.valueOf(compResult.fileName);
SourceTypeBinding binding = typeDeclaration.binding;
- if (binding.isAnnotationType()) {
- // Ignore these.
- return false;
- }
+
if (binding.constantPoolName() == null) {
/*
* Weird case: if JDT determines that this local class is totally
@@ -819,7 +823,7 @@
if (binding.isClass()) {
newType = program.createClass(info, name, binding.isAbstract(),
binding.isFinal());
- } else if (binding.isInterface()) {
+ } else if (binding.isInterface() || binding.isAnnotationType()) {
newType = program.createInterface(info, name);
} else if (binding.isEnum()) {
if (binding.isAnonymousType()) {
@@ -828,9 +832,6 @@
} else {
newType = program.createEnum(info, name);
}
- } else if (binding.isAnnotationType()) {
- // TODO
- return false;
} else {
assert (false);
return false;
diff --git a/user/test/com/google/gwt/dev/jjs/CompilerSuite.java b/user/test/com/google/gwt/dev/jjs/CompilerSuite.java
index 32605a3..254bdf3 100644
--- a/user/test/com/google/gwt/dev/jjs/CompilerSuite.java
+++ b/user/test/com/google/gwt/dev/jjs/CompilerSuite.java
@@ -15,6 +15,7 @@
*/
package com.google.gwt.dev.jjs;
+import com.google.gwt.dev.jjs.test.AnnotationsTest;
import com.google.gwt.dev.jjs.test.AutoboxTest;
import com.google.gwt.dev.jjs.test.BlankInterfaceTest;
import com.google.gwt.dev.jjs.test.ClassCastTest;
@@ -47,6 +48,7 @@
TestSuite suite = new TestSuite("Test for com.google.gwt.dev.jjs");
// $JUnit-BEGIN$
+ suite.addTestSuite(AnnotationsTest.class);
suite.addTestSuite(AutoboxTest.class);
suite.addTestSuite(ClassCastTest.class);
suite.addTestSuite(ClassObjectTest.class);
diff --git a/user/test/com/google/gwt/dev/jjs/test/AnnotationsTest.java b/user/test/com/google/gwt/dev/jjs/test/AnnotationsTest.java
new file mode 100644
index 0000000..0fa15ed
--- /dev/null
+++ b/user/test/com/google/gwt/dev/jjs/test/AnnotationsTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.dev.jjs.test;
+
+import com.google.gwt.junit.client.GWTTestCase;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * Tests annotations support.
+ */
+public class AnnotationsTest extends GWTTestCase {
+
+ private static class Foo implements IFoo {
+ public Class<? extends Annotation> annotationType() {
+ return IFoo.class;
+ }
+
+ public NestedEnum value() {
+ return IFoo.NestedEnum.FOO2;
+ }
+
+ public Class<? extends NestedEnum> valueClass() {
+ return IFoo.NestedEnum.class;
+ }
+ }
+
+ private @interface IFoo {
+ enum NestedEnum {
+ FOO1, FOO2
+ }
+
+ NestedEnum value() default NestedEnum.FOO1;
+
+ Class<? extends NestedEnum> valueClass() default NestedEnum.class;
+ }
+
+ public String getModuleName() {
+ return "com.google.gwt.dev.jjs.CompilerSuite";
+ }
+
+ public void testAnnotationImplementor() {
+ Foo f = new Foo();
+ assertEquals(Foo.class, f.getClass());
+ assertEquals(IFoo.NestedEnum.FOO2, f.value());
+ assertEquals(IFoo.NestedEnum.class, f.valueClass());
+ }
+
+}