changeset 3069:a1e5ee2e18c2

Automated merge with http://hg.openjdk.java.net/jdk8/tl/langtools
author wmdietl
date Sat, 23 Nov 2013 18:15:40 -0500
parents 4fa835472e3c 4e4a9fe1b751
children 40743a0133df
files src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
diffstat 13 files changed, 97 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Fri Nov 22 17:07:35 2013 -0800
+++ b/.hgtags	Sat Nov 23 18:15:40 2013 -0500
@@ -140,6 +140,7 @@
 1cbe86c11ba69521875c0b0357d7540781eb334d jdk8-b17
 ec2c0973cc31e143cffc05ceb63d98fae76f97d4 jdk8-b16
 ab1b1cc7857716914f2bb20b3128e5a8978290f7 jdk8-b18
+2a2d6ac056cfde7326f309ab73b8cddf518cc729 308-jdk8-sync
 77b2c066084cbc75150efc6603a713c558329813 jdk8-b19
 ffd294128a48cbb90ce8f0569f82b61f1f164a18 jdk8-b20
 bcb21abf1c4177baf4574f99709513dcd4474727 jdk8-b21
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Nov 22 17:07:35 2013 -0800
+++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Sat Nov 23 18:15:40 2013 -0500
@@ -28,7 +28,6 @@
 import java.util.*;
 
 import javax.lang.model.element.ElementKind;
-import javax.lang.model.type.TypeKind;
 import javax.tools.JavaFileObject;
 
 import com.sun.source.tree.IdentifierTree;
@@ -2163,11 +2162,6 @@
                     tree.constructor,
                     localEnv,
                     new ResultInfo(pkind, newMethodTemplate(syms.voidType, argtypes, typeargtypes)));
-            } else {
-                if (tree.clazz.hasTag(ANNOTATED_TYPE)) {
-                    checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations,
-                            tree.clazz.type.tsym);
-                }
             }
 
             if (tree.constructor != null && tree.constructor.kind == MTH)
@@ -2229,21 +2223,6 @@
                 }
             }
 
-    private void checkForDeclarationAnnotations(List<? extends JCAnnotation> annotations,
-            Symbol sym) {
-        // Ensure that no declaration annotations are present.
-        // Note that a tree type might be an AnnotatedType with
-        // empty annotations, if only declaration annotations were given.
-        // This method will raise an error for such a type.
-        for (JCAnnotation ai : annotations) {
-            if (!ai.type.isErroneous() &&
-                typeAnnotations.annotationType(ai.attribute, sym) == TypeAnnotations.AnnotationType.DECLARATION) {
-                log.error(ai.pos(), "annotation.type.not.applicable");
-            }
-        }
-    }
-
-
     /** Make an attributed null check tree.
      */
     public JCExpression makeNullCheck(JCExpression arg) {
@@ -2270,10 +2249,6 @@
                 attribExpr(l.head, localEnv, syms.intType);
                 owntype = new ArrayType(owntype, syms.arrayClass);
             }
-            if (tree.elemtype.hasTag(ANNOTATED_TYPE)) {
-                checkForDeclarationAnnotations(((JCAnnotatedType) tree.elemtype).annotations,
-                        tree.elemtype.type.tsym);
-            }
         } else {
             // we are seeing an untyped aggregate { ... }
             // this is allowed only if the prototype is an array
@@ -4418,7 +4393,7 @@
         }
         public void visitMethodDef(JCMethodDecl tree) {
             if (tree.recvparam != null &&
-                    tree.recvparam.vartype.type.getKind() != TypeKind.ERROR) {
+                    !tree.recvparam.vartype.type.isErroneous()) {
                 checkForDeclarationAnnotations(tree.recvparam.mods.annotations,
                         tree.recvparam.vartype.type.tsym);
             }
@@ -4457,17 +4432,28 @@
             super.visitTypeTest(tree);
         }
         public void visitNewClass(JCNewClass tree) {
-            if (tree.clazz.type != null)
+            if (tree.clazz.hasTag(ANNOTATED_TYPE)) {
+                checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations,
+                        tree.clazz.type.tsym);
+            }
+            if (tree.def != null) {
+                checkForDeclarationAnnotations(tree.def.mods.annotations, tree.clazz.type.tsym);
+            }
+            if (tree.clazz.type != null) {
                 validateAnnotatedType(tree.clazz, tree.clazz.type);
+            }
             super.visitNewClass(tree);
         }
         public void visitNewArray(JCNewArray tree) {
-            if (tree.elemtype != null && tree.elemtype.type != null)
+            if (tree.elemtype != null && tree.elemtype.type != null) {
+                if (tree.elemtype.hasTag(ANNOTATED_TYPE)) {
+                    checkForDeclarationAnnotations(((JCAnnotatedType) tree.elemtype).annotations,
+                            tree.elemtype.type.tsym);
+                }
                 validateAnnotatedType(tree.elemtype, tree.elemtype.type);
+            }
             super.visitNewArray(tree);
         }
-
-        @Override
         public void visitClassDef(JCClassDecl tree) {
             if (sigOnly) {
                 scan(tree.mods);
@@ -4482,8 +4468,6 @@
                 scan(member);
             }
         }
-
-        @Override
         public void visitBlock(JCBlock tree) {
             if (!sigOnly) {
                 scan(tree.stats);
@@ -4589,6 +4573,20 @@
                 }
             }
         }
+
+        private void checkForDeclarationAnnotations(List<? extends JCAnnotation> annotations,
+                Symbol sym) {
+            // Ensure that no declaration annotations are present.
+            // Note that a tree type might be an AnnotatedType with
+            // empty annotations, if only declaration annotations were given.
+            // This method will raise an error for such a type.
+            for (JCAnnotation ai : annotations) {
+                if (!ai.type.isErroneous() &&
+                        typeAnnotations.annotationType(ai.attribute, sym) == TypeAnnotations.AnnotationType.DECLARATION) {
+                    log.error(ai.pos(), "annotation.type.not.applicable");
+                }
+            }
+        }
     };
 
     // <editor-fold desc="post-attribution visitor">
--- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Nov 22 17:07:35 2013 -0800
+++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Sat Nov 23 18:15:40 2013 -0500
@@ -2977,6 +2977,7 @@
     boolean annotationApplicable(JCAnnotation a, Symbol s) {
         Attribute.Array arr = getAttributeTargetAttribute(a.annotationType.type.tsym);
         Name[] targets;
+
         if (arr == null) {
             targets = defaultTargetMetaInfo(a, s);
         } else {
@@ -2993,7 +2994,7 @@
         }
         for (Name target : targets) {
             if (target == names.TYPE)
-                { if (s.kind == TYP && !s.isAnonymous()) return true; }
+                { if (s.kind == TYP) return true; }
             else if (target == names.FIELD)
                 { if (s.kind == VAR && s.owner.kind != MTH) return true; }
             else if (target == names.METHOD)
--- a/test/com/sun/javadoc/typeAnnotations/smoke/TestSmoke.java	Fri Nov 22 17:07:35 2013 -0800
+++ b/test/com/sun/javadoc/typeAnnotations/smoke/TestSmoke.java	Sat Nov 23 18:15:40 2013 -0500
@@ -52,24 +52,12 @@
         {BUG_ID + FS + "pkg" + FS + "T0x06.html", "@DA"},
         {BUG_ID + FS + "pkg" + FS + "T0x0B.html", "@DA"},
         {BUG_ID + FS + "pkg" + FS + "T0x0F.html", "@DA"},
-        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
         {BUG_ID + FS + "pkg" + FS + "T0x20.html", "@DA"},
-        */
-        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
         {BUG_ID + FS + "pkg" + FS + "T0x20A.html", "@DTPA"},
-        */
-        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
         {BUG_ID + FS + "pkg" + FS + "T0x20B.html", "@DA"},
-        */
-        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
         {BUG_ID + FS + "pkg" + FS + "T0x22.html", "@DA"},
-        */
-        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
         {BUG_ID + FS + "pkg" + FS + "T0x22A.html", "@DTPA"},
-        */
-        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
         {BUG_ID + FS + "pkg" + FS + "T0x22B.html", "@DA"},
-        */
         {BUG_ID + FS + "pkg" + FS + "T0x10.html", "@DA"},
         {BUG_ID + FS + "pkg" + FS + "T0x10A.html", "@DA"},
         {BUG_ID + FS + "pkg" + FS + "T0x12.html", "@DA"},
--- a/test/tools/javac/annotations/typeAnnotations/classfile/T8008762.java	Fri Nov 22 17:07:35 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/classfile/T8008762.java	Sat Nov 23 18:15:40 2013 -0500
@@ -61,12 +61,12 @@
     static class Test {
         Object mtest( Test t){ return null; }
         public void test() {
-          mtest( new Test() {
+            mtest( new Test() {
                 class InnerAnon { // Test1$1$InnerAnon.class
-                  @A @B String ai_data = null;
-                  @A @B String ai_m(){ return null; };
+                    @A @B String ai_data = null;
+                    @A @B String ai_m(){ return null; };
                 }
-               InnerAnon IA = new InnerAnon();
+                InnerAnon IA = new InnerAnon();
             });
         }
         @Retention(RUNTIME) @Target(TYPE_USE) @interface A { }
--- a/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.java	Fri Nov 22 17:07:35 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.java	Sat Nov 23 18:15:40 2013 -0500
@@ -3,11 +3,11 @@
  * @bug 8006775
  * @summary Import clauses cannot use annotations.
  * @author Werner Dietl
- * @ignore
  * @compile/fail/ref=AnnotatedImport.out -XDrawDiagnostics AnnotatedImport.java
  */
 
 import java.lang.annotation.*;
+
 import java.@A util.List;
 import @A java.util.Map;
 import java.util.@A HashMap;
--- a/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.out	Fri Nov 22 17:07:35 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedImport.out	Sat Nov 23 18:15:40 2013 -0500
@@ -1,7 +1,7 @@
-AnnotatedImport.java:9:13: compiler.err.expected: token.identifier
-AnnotatedImport.java:9:14: compiler.err.expected3: class, interface, enum
-AnnotatedImport.java:10:7: compiler.err.expected: token.identifier
-AnnotatedImport.java:10:10: compiler.err.expected: ';'
-AnnotatedImport.java:11:18: compiler.err.expected: token.identifier
-AnnotatedImport.java:11:19: compiler.err.expected3: class, interface, enum
+AnnotatedImport.java:11:13: compiler.err.expected: token.identifier
+AnnotatedImport.java:11:14: compiler.err.expected3: class, interface, enum
+AnnotatedImport.java:12:7: compiler.err.expected: token.identifier
+AnnotatedImport.java:12:10: compiler.err.expected: ';'
+AnnotatedImport.java:13:18: compiler.err.expected: token.identifier
+AnnotatedImport.java:13:19: compiler.err.expected3: class, interface, enum
 6 errors
--- a/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedPackage1.java	Fri Nov 22 17:07:35 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/failures/AnnotatedPackage1.java	Sat Nov 23 18:15:40 2013 -0500
@@ -3,11 +3,12 @@
  * @bug 8006775
  * @summary Package declarations cannot use annotations.
  * @author Werner Dietl
- * @ignore
  * @compile/fail/ref=AnnotatedPackage1.out -XDrawDiagnostics AnnotatedPackage1.java
  */
 
-package name.@A p1.p2;
+package name. @A p1.p2;
+
+import java.lang.annotation.*;
 
 import java.lang.annotation.*;
 
--- a/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.java	Fri Nov 22 17:07:35 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.java	Sat Nov 23 18:15:40 2013 -0500
@@ -3,7 +3,6 @@
  * @bug 8006733 8006775
  * @summary Ensure behavior for nested types is correct.
  * @author Werner Dietl
- * @ignore
  * @compile/fail/ref=CantAnnotateStaticClass3.out -XDrawDiagnostics CantAnnotateStaticClass3.java
  */
 
--- a/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.out	Fri Nov 22 17:07:35 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.out	Sat Nov 23 18:15:40 2013 -0500
@@ -32,12 +32,6 @@
 CantAnnotateStaticClass3.java:65:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB
 CantAnnotateStaticClass3.java:66:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB
 CantAnnotateStaticClass3.java:67:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB
-CantAnnotateStaticClass3.java:99:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
-CantAnnotateStaticClass3.java:101:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
-CantAnnotateStaticClass3.java:106:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
-CantAnnotateStaticClass3.java:108:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
-CantAnnotateStaticClass3.java:113:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
-CantAnnotateStaticClass3.java:115:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
 CantAnnotateStaticClass3.java:120:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB
 CantAnnotateStaticClass3.java:121:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB
 CantAnnotateStaticClass3.java:122:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB
@@ -66,6 +60,12 @@
 CantAnnotateStaticClass3.java:168:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB
 CantAnnotateStaticClass3.java:170:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB
 CantAnnotateStaticClass3.java:172:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB
+CantAnnotateStaticClass3.java:99:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
+CantAnnotateStaticClass3.java:101:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
+CantAnnotateStaticClass3.java:106:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
+CantAnnotateStaticClass3.java:108:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
+CantAnnotateStaticClass3.java:113:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
+CantAnnotateStaticClass3.java:115:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
 CantAnnotateStaticClass3.java:177:35: compiler.err.cant.type.annotate.scoping.1: @Top.TB
 CantAnnotateStaticClass3.java:179:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB
 CantAnnotateStaticClass3.java:180:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/CheckForDeclAnnoNPE.java	Sat Nov 23 18:15:40 2013 -0500
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013, 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 8027310
+ * @summary Ensure there is no NPE in checking for decl. annotations in this example
+ * @author Werner Dietl
+ * @compile -doe CheckForDeclAnnoNPE.java
+ */
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+
+class CheckForDeclAnnoNPE {
+    void test(String s) {
+        test(new @TA String().toString());
+    }
+}
+
+@Target(ElementType.TYPE_USE)
+@interface TA {}
--- a/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.java	Fri Nov 22 17:07:35 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.java	Sat Nov 23 18:15:40 2013 -0500
@@ -10,9 +10,6 @@
     Object e1 = new @DA int[5];
     Object e2 = new @DA String[42];
     Object e3 = new @DA Object();
-
-    // The declaration annotation is only allowed for
-    // an anonymous class creation.
     Object ok = new @DA Object() { };
 }
 
--- a/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.out	Fri Nov 22 17:07:35 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.out	Sat Nov 23 18:15:40 2013 -0500
@@ -1,5 +1,5 @@
 DeclarationAnnotation.java:10:21: compiler.err.annotation.type.not.applicable
 DeclarationAnnotation.java:11:21: compiler.err.annotation.type.not.applicable
 DeclarationAnnotation.java:12:21: compiler.err.annotation.type.not.applicable
-DeclarationAnnotation.java:16:21: compiler.err.annotation.type.not.applicable
+DeclarationAnnotation.java:13:21: compiler.err.annotation.type.not.applicable
 4 errors