Do not crash if @GwtIncompatible is used in annotations. @GwtIcompatible in annotations is considered noop. Change-Id: Iff75cb012024f8394caab9c2241ed16cb4fc0803
diff --git a/dev/core/src/com/google/gwt/dev/javac/GwtIncompatiblePreprocessor.java b/dev/core/src/com/google/gwt/dev/javac/GwtIncompatiblePreprocessor.java index 862ed1c..426cb53 100644 --- a/dev/core/src/com/google/gwt/dev/javac/GwtIncompatiblePreprocessor.java +++ b/dev/core/src/com/google/gwt/dev/javac/GwtIncompatiblePreprocessor.java
@@ -146,14 +146,17 @@ * Removes all members of a class to leave it as an empty stub. */ private static void stripAllMembers(TypeDeclaration tyDecl) { + if (TypeDeclaration.kind(tyDecl.modifiers) == TypeDeclaration.ANNOTATION_TYPE_DECL) { + // Do not modify annotations at all. + return; + } tyDecl.superclass = null; tyDecl.superInterfaces = new TypeReference[0]; tyDecl.annotations = new Annotation[0]; tyDecl.methods = new AbstractMethodDeclaration[0]; tyDecl.memberTypes = new TypeDeclaration[0]; tyDecl.fields = new FieldDeclaration[0]; - if (TypeDeclaration.kind(tyDecl.modifiers) != TypeDeclaration.INTERFACE_DECL && - TypeDeclaration.kind(tyDecl.modifiers) != TypeDeclaration.ENUM_DECL) { + if (TypeDeclaration.kind(tyDecl.modifiers) == TypeDeclaration.CLASS_DECL) { // Create a default constructor so that the class is proper. ConstructorDeclaration constructor = tyDecl.createDefaultConstructor(true, true); // Mark only constructor as private so that it can not be instantiated.
diff --git a/dev/core/test/com/google/gwt/dev/javac/GwtIncompatibleJdtCompilerTest.java b/dev/core/test/com/google/gwt/dev/javac/GwtIncompatibleJdtCompilerTest.java index 261fe79..86bbb6a 100644 --- a/dev/core/test/com/google/gwt/dev/javac/GwtIncompatibleJdtCompilerTest.java +++ b/dev/core/test/com/google/gwt/dev/javac/GwtIncompatibleJdtCompilerTest.java
@@ -80,6 +80,10 @@ "GwtIncompatibleWithStaticInnerClass.Child cannot be resolved to a type"); } + public void testCompileGwtIncompatibleAnnotation() throws Exception { + assertResourcesCompileSuccessfully(GWTINCOMPATIBLE_ANNOTATION, GWTINCOMPATIBLE_ANNOTATION_TYPE); + } + public static final MockJavaResource GWTINCOMPATIBLE_ANNOTATION = new MockJavaResource( "com.google.gwt.GwtIncompatible") { @Override @@ -245,5 +249,16 @@ "}"); } }; + + public static final MockJavaResource GWTINCOMPATIBLE_ANNOTATION_TYPE = new MockJavaResource( + "com.google.gwt.GwtIncompatibleAnnotation") { + @Override + public CharSequence getContent() { + return Joiner.on("\n").join("package com.google.gwt;", + "@GwtIncompatible(\" not compatible \") ", + "public @interface GwtIncompatibleAnnotation {", + "}"); + } + }; }