changeset 51004:dcbbc6fb0b69

8200166: Repeating annotations refering to to-be-generated classes don't work. Reviewed-by: jjg
author jlahoda
date Tue, 05 Jun 2018 14:55:13 +0200
parents ee87876734c9
children bf7eb61349d2
files src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java test/langtools/tools/javac/annotations/repeatingAnnotations/generatedInRepeating/GeneratedInRepeating.java test/langtools/tools/javac/annotations/repeatingAnnotations/generatedInRepeating/Processor.java
diffstat 3 files changed, 109 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Tue Jun 05 13:02:01 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Tue Jun 05 14:55:13 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,7 @@
 import com.sun.source.tree.ModuleTree.ModuleKind;
 import com.sun.source.tree.Tree.Kind;
 import com.sun.tools.javac.code.*;
+import com.sun.tools.javac.code.Attribute.UnresolvedClass;
 import com.sun.tools.javac.code.Symbol.*;
 import com.sun.tools.javac.code.Type.*;
 import com.sun.tools.javac.util.*;
@@ -872,7 +873,11 @@
             result = QualIdent(e.value);
         }
         public void visitError(Attribute.Error e) {
-            result = Erroneous();
+            if (e instanceof UnresolvedClass) {
+                result = ClassLiteral(((UnresolvedClass) e).classType).setType(syms.classType);
+            } else {
+                result = Erroneous();
+            }
         }
         public void visitCompound(Attribute.Compound compound) {
             if (compound instanceof Attribute.TypeCompound) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/annotations/repeatingAnnotations/generatedInRepeating/GeneratedInRepeating.java	Tue Jun 05 14:55:13 2018 +0200
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8200166
+ * @summary Check that repeating annotations whose attributes are not-yet-generated classes work.
+ * @compile Processor.java
+ * @compile -processor Processor GeneratedInRepeating.java
+ */
+
+import java.lang.annotation.Repeatable;
+
+@Annot(Gen.class)
+@Annot(Gen.class)
+public class GeneratedInRepeating {
+}
+
+@Repeatable(AnnotContainer.class)
+@interface Annot {
+    public Class<?> value();
+}
+
+@interface AnnotContainer {
+    public Annot[] value();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/annotations/repeatingAnnotations/generatedInRepeating/Processor.java	Tue Jun 05 14:55:13 2018 +0200
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Set;
+
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.TypeElement;
+
+@SupportedAnnotationTypes("*")
+public class Processor extends AbstractProcessor {
+
+    int round;
+
+    @Override
+    public SourceVersion getSupportedSourceVersion() {
+        return SourceVersion.latestSupported();
+    }
+
+    @Override
+    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+        if (round == 0) {
+            try (Writer w = processingEnv.getFiler().createSourceFile("Gen").openWriter()) {
+                w.write("class Gen {}");
+            } catch (IOException ex) {
+                throw new IllegalStateException(ex);
+            }
+        }
+        round++;
+        return false;
+    }
+}