changeset 2800:1b58b3cc63bc

8069094: SuppressWarnings(\"deprecation\") not respected on default clause on annotation declarations Summary: Properly deferring warnings that are reported during entering of annotation's default value. Reviewed-by: mcimadamore
author jlahoda
date Tue, 20 Jan 2015 12:00:25 +0100
parents 2dc86bb9736a
children 1580b10e028a
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java test/tools/javac/warnings/suppress/T8069094.java test/tools/javac/warnings/suppress/T8069094.out
diffstat 3 files changed, 25 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Tue Jan 20 09:51:17 2015 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Tue Jan 20 12:00:25 2015 +0100
@@ -227,7 +227,7 @@
         annotate.annotateTypeLater(tree, localEnv, m, tree.pos());
 
         if (tree.defaultValue != null)
-            annotateDefaultValueLater(tree.defaultValue, localEnv, m);
+            annotateDefaultValueLater(tree.defaultValue, localEnv, m, tree.pos());
     }
 
     /** Create a fresh environment for method bodies.
@@ -438,7 +438,8 @@
     /** Queue processing of an attribute default value. */
     void annotateDefaultValueLater(final JCExpression defaultValue,
                                    final Env<AttrContext> localEnv,
-                                   final MethodSymbol m) {
+                                   final MethodSymbol m,
+                                   final DiagnosticPosition deferPos) {
         annotate.normal(new Annotate.Worker() {
                 @Override
                 public String toString() {
@@ -449,9 +450,11 @@
                 @Override
                 public void run() {
                     JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
+                    DiagnosticPosition prevLintPos = deferredLintHandler.setPos(deferPos);
                     try {
                         enterDefaultValue(defaultValue, localEnv, m);
                     } finally {
+                        deferredLintHandler.setPos(prevLintPos);
                         log.useSource(prev);
                     }
                 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/warnings/suppress/T8069094.java	Tue Jan 20 12:00:25 2015 +0100
@@ -0,0 +1,17 @@
+/**
+ * @test /nodynamiccopyright/
+ * @bug 8069094
+ * @summary Verify that \\@SuppressWarnings("unchecked") works correctly for annotation default values
+ * @build VerifySuppressWarnings
+ * @compile/ref=T8069094.out -XDrawDiagnostics -Xlint:unchecked,deprecation,cast T8069094.java
+ * @run main VerifySuppressWarnings T8069094.java
+ */
+
+@interface T8069094 {
+    T8069094A foo() default T8069094A.Bar;
+}
+
+@Deprecated
+enum T8069094A {
+    Bar
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/warnings/suppress/T8069094.out	Tue Jan 20 12:00:25 2015 +0100
@@ -0,0 +1,3 @@
+T8069094.java:11:5: compiler.warn.has.been.deprecated: T8069094A, compiler.misc.unnamed.package
+T8069094.java:11:29: compiler.warn.has.been.deprecated: T8069094A, compiler.misc.unnamed.package
+2 warnings