Mon, 16 Sep 2013 14:13:44 +0200
8021112: Spurious unchecked warning reported by javac
6480588: No way to suppress deprecation warnings when implementing deprecated interface
Summary: Fixing DeferredLintHandler configuration, so lint warnings are reported with correct @SuppressWarnings settings
Reviewed-by: jjg, vromero
1.1 --- a/src/share/classes/com/sun/tools/javac/code/DeferredLintHandler.java Sat Sep 14 19:04:47 2013 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/DeferredLintHandler.java Mon Sep 16 14:13:44 2013 +0200 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -28,6 +28,8 @@ 1.11 import java.util.HashMap; 1.12 import java.util.Map; 1.13 1.14 +import com.sun.tools.javac.tree.EndPosTable; 1.15 +import com.sun.tools.javac.tree.JCTree; 1.16 import com.sun.tools.javac.util.Assert; 1.17 import com.sun.tools.javac.util.Context; 1.18 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 1.19 @@ -53,10 +55,13 @@ 1.20 1.21 protected DeferredLintHandler(Context context) { 1.22 context.put(deferredLintHandlerKey, this); 1.23 + this.currentPos = IMMEDIATE_POSITION; 1.24 } 1.25 1.26 - private DeferredLintHandler() {} 1.27 - 1.28 + /**An interface for deferred lint reporting - loggers passed to 1.29 + * {@link #report(LintLogger) } will be called when 1.30 + * {@link #flush(DiagnosticPosition) } is invoked. 1.31 + */ 1.32 public interface LintLogger { 1.33 void report(); 1.34 } 1.35 @@ -64,12 +69,26 @@ 1.36 private DiagnosticPosition currentPos; 1.37 private Map<DiagnosticPosition, ListBuffer<LintLogger>> loggersQueue = new HashMap<DiagnosticPosition, ListBuffer<LintLogger>>(); 1.38 1.39 + /**Associate the given logger with the current position as set by {@link #setPos(DiagnosticPosition) }. 1.40 + * Will be invoked when {@link #flush(DiagnosticPosition) } will be invoked with the same position. 1.41 + * <br> 1.42 + * Will invoke the logger synchronously if {@link #immediate() } was called 1.43 + * instead of {@link #setPos(DiagnosticPosition) }. 1.44 + */ 1.45 public void report(LintLogger logger) { 1.46 - ListBuffer<LintLogger> loggers = loggersQueue.get(currentPos); 1.47 - Assert.checkNonNull(loggers); 1.48 - loggers.append(logger); 1.49 + if (currentPos == IMMEDIATE_POSITION) { 1.50 + logger.report(); 1.51 + } else { 1.52 + ListBuffer<LintLogger> loggers = loggersQueue.get(currentPos); 1.53 + if (loggers == null) { 1.54 + loggersQueue.put(currentPos, loggers = ListBuffer.<LintLogger>lb()); 1.55 + } 1.56 + loggers.append(logger); 1.57 + } 1.58 } 1.59 1.60 + /**Invoke all {@link LintLogger}s that were associated with the provided {@code pos}. 1.61 + */ 1.62 public void flush(DiagnosticPosition pos) { 1.63 ListBuffer<LintLogger> loggers = loggersQueue.get(pos); 1.64 if (loggers != null) { 1.65 @@ -80,16 +99,46 @@ 1.66 } 1.67 } 1.68 1.69 - public DeferredLintHandler setPos(DiagnosticPosition currentPos) { 1.70 + /**Sets the current position to the provided {@code currentPos}. {@link LintLogger}s 1.71 + * passed to subsequent invocations of {@link #report(LintLogger) } will be associated 1.72 + * with the given position. 1.73 + */ 1.74 + public DiagnosticPosition setPos(DiagnosticPosition currentPos) { 1.75 + DiagnosticPosition prevPosition = this.currentPos; 1.76 this.currentPos = currentPos; 1.77 - loggersQueue.put(currentPos, ListBuffer.<LintLogger>lb()); 1.78 - return this; 1.79 + return prevPosition; 1.80 } 1.81 1.82 - public static final DeferredLintHandler immediateHandler = new DeferredLintHandler() { 1.83 + /**{@link LintLogger}s passed to subsequent invocations of 1.84 + * {@link #report(LintLogger) } will be invoked immediately. 1.85 + */ 1.86 + public DiagnosticPosition immediate() { 1.87 + return setPos(IMMEDIATE_POSITION); 1.88 + } 1.89 + 1.90 + private static final DiagnosticPosition IMMEDIATE_POSITION = new DiagnosticPosition() { 1.91 @Override 1.92 - public void report(LintLogger logger) { 1.93 - logger.report(); 1.94 + public JCTree getTree() { 1.95 + Assert.error(); 1.96 + return null; 1.97 + } 1.98 + 1.99 + @Override 1.100 + public int getStartPosition() { 1.101 + Assert.error(); 1.102 + return -1; 1.103 + } 1.104 + 1.105 + @Override 1.106 + public int getPreferredPosition() { 1.107 + Assert.error(); 1.108 + return -1; 1.109 + } 1.110 + 1.111 + @Override 1.112 + public int getEndPosition(EndPosTable endPosTable) { 1.113 + Assert.error(); 1.114 + return -1; 1.115 } 1.116 }; 1.117 }
2.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Sat Sep 14 19:04:47 2013 +0100 2.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Mon Sep 16 14:13:44 2013 +0200 2.3 @@ -46,6 +46,7 @@ 2.4 import static com.sun.tools.javac.code.TypeTag.CLASS; 2.5 import static com.sun.tools.javac.code.TypeTag.FORALL; 2.6 import static com.sun.tools.javac.code.TypeTag.TYPEVAR; 2.7 +import com.sun.tools.javac.tree.JCTree.JCVariableDecl; 2.8 2.9 /** Root class for Java symbols. It contains subclasses 2.10 * for specific sorts of symbols, such as variables, methods and operators, 2.11 @@ -1167,11 +1168,11 @@ 2.12 2.13 public void setLazyConstValue(final Env<AttrContext> env, 2.14 final Attr attr, 2.15 - final JCTree.JCExpression initializer) 2.16 + final JCVariableDecl variable) 2.17 { 2.18 setData(new Callable<Object>() { 2.19 public Object call() { 2.20 - return attr.attribLazyConstantValue(env, initializer, type); 2.21 + return attr.attribLazyConstantValue(env, variable, type); 2.22 } 2.23 }); 2.24 }
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Sat Sep 14 19:04:47 2013 +0100 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Sep 16 14:13:44 2013 +0200 3.3 @@ -748,19 +748,11 @@ 3.4 * @see VarSymbol#setLazyConstValue 3.5 */ 3.6 public Object attribLazyConstantValue(Env<AttrContext> env, 3.7 - JCTree.JCExpression initializer, 3.8 + JCVariableDecl variable, 3.9 Type type) { 3.10 3.11 - /* When this env was created, it didn't have the correct lint nor had 3.12 - * annotations has been processed. 3.13 - * But now at this phase we have already processed annotations and the 3.14 - * correct lint must have been set in chk, so we should use that one to 3.15 - * attribute the initializer. 3.16 - */ 3.17 - Lint prevLint = env.info.lint; 3.18 - env.info.lint = chk.getLint(); 3.19 - 3.20 - JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile); 3.21 + DiagnosticPosition prevLintPos 3.22 + = deferredLintHandler.setPos(variable.pos()); 3.23 3.24 try { 3.25 // Use null as symbol to not attach the type annotation to any symbol. 3.26 @@ -768,17 +760,16 @@ 3.27 // to the symbol. 3.28 // This prevents having multiple type annotations, just because of 3.29 // lazy constant value evaluation. 3.30 - memberEnter.typeAnnotate(initializer, env, null); 3.31 + memberEnter.typeAnnotate(variable.init, env, null, variable.pos()); 3.32 annotate.flush(); 3.33 - Type itype = attribExpr(initializer, env, type); 3.34 + Type itype = attribExpr(variable.init, env, type); 3.35 if (itype.constValue() != null) { 3.36 return coerce(itype, type).constValue(); 3.37 } else { 3.38 return null; 3.39 } 3.40 } finally { 3.41 - env.info.lint = prevLint; 3.42 - log.useSource(prevSource); 3.43 + deferredLintHandler.setPos(prevLintPos); 3.44 } 3.45 } 3.46 3.47 @@ -1012,7 +1003,7 @@ 3.48 } 3.49 3.50 // Attribute all type annotations in the body 3.51 - memberEnter.typeAnnotate(tree.body, localEnv, m); 3.52 + memberEnter.typeAnnotate(tree.body, localEnv, m, null); 3.53 annotate.flush(); 3.54 3.55 // Attribute method body. 3.56 @@ -1042,7 +1033,7 @@ 3.57 } else { 3.58 if (tree.init != null) { 3.59 // Field initializer expression need to be entered. 3.60 - memberEnter.typeAnnotate(tree.init, env, tree.sym); 3.61 + memberEnter.typeAnnotate(tree.init, env, tree.sym, tree.pos()); 3.62 annotate.flush(); 3.63 } 3.64 } 3.65 @@ -1056,18 +1047,16 @@ 3.66 ((JCLambda)env.tree).paramKind == JCLambda.ParameterKind.IMPLICIT && 3.67 (tree.sym.flags() & PARAMETER) != 0; 3.68 chk.validate(tree.vartype, env, !isImplicitLambdaParameter); 3.69 - deferredLintHandler.flush(tree.pos()); 3.70 3.71 try { 3.72 + v.getConstValue(); // ensure compile-time constant initializer is evaluated 3.73 + deferredLintHandler.flush(tree.pos()); 3.74 chk.checkDeprecatedAnnotation(tree.pos(), v); 3.75 3.76 if (tree.init != null) { 3.77 - if ((v.flags_field & FINAL) != 0 && 3.78 - memberEnter.needsLazyConstValue(tree.init)) { 3.79 - // In this case, `v' is final. Ensure that it's initializer is 3.80 - // evaluated. 3.81 - v.getConstValue(); // ensure initializer is evaluated 3.82 - } else { 3.83 + if ((v.flags_field & FINAL) == 0 || 3.84 + !memberEnter.needsLazyConstValue(tree.init)) { 3.85 + // Not a compile-time constant 3.86 // Attribute initializer in a new environment 3.87 // with the declared variable as owner. 3.88 // Check that initializer conforms to variable's declared type. 3.89 @@ -1106,7 +1095,7 @@ 3.90 if ((tree.flags & STATIC) != 0) localEnv.info.staticLevel++; 3.91 3.92 // Attribute all type annotations in the block 3.93 - memberEnter.typeAnnotate(tree, localEnv, localEnv.info.scope.owner); 3.94 + memberEnter.typeAnnotate(tree, localEnv, localEnv.info.scope.owner, null); 3.95 annotate.flush(); 3.96 3.97 { 3.98 @@ -4209,6 +4198,7 @@ 3.99 ResultInfo prevReturnRes = env.info.returnResult; 3.100 3.101 try { 3.102 + deferredLintHandler.flush(env.tree); 3.103 env.info.returnResult = null; 3.104 // java.lang.Enum may not be subclassed by a non-enum 3.105 if (st.tsym == syms.enumSym &&
4.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Sat Sep 14 19:04:47 2013 +0100 4.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Mon Sep 16 14:13:44 2013 +0200 4.3 @@ -148,7 +148,7 @@ 4.4 sunApiHandler = new MandatoryWarningHandler(log, verboseSunApi, 4.5 enforceMandatoryWarnings, "sunapi", null); 4.6 4.7 - deferredLintHandler = DeferredLintHandler.immediateHandler; 4.8 + deferredLintHandler = DeferredLintHandler.instance(context); 4.9 } 4.10 4.11 /** Switch: generics enabled? 4.12 @@ -218,20 +218,6 @@ 4.13 return prev; 4.14 } 4.15 4.16 - /* This idiom should be used only in cases when it is needed to set the lint 4.17 - * of an environment that has been created in a phase previous to annotations 4.18 - * processing. 4.19 - */ 4.20 - Lint getLint() { 4.21 - return lint; 4.22 - } 4.23 - 4.24 - DeferredLintHandler setDeferredLintHandler(DeferredLintHandler newDeferredLintHandler) { 4.25 - DeferredLintHandler prev = deferredLintHandler; 4.26 - deferredLintHandler = newDeferredLintHandler; 4.27 - return prev; 4.28 - } 4.29 - 4.30 MethodSymbol setMethod(MethodSymbol newMethod) { 4.31 MethodSymbol prev = method; 4.32 method = newMethod; 4.33 @@ -582,14 +568,19 @@ 4.34 /** Check for redundant casts (i.e. where source type is a subtype of target type) 4.35 * The problem should only be reported for non-292 cast 4.36 */ 4.37 - public void checkRedundantCast(Env<AttrContext> env, JCTypeCast tree) { 4.38 - if (!tree.type.isErroneous() && 4.39 - (env.info.lint == null || env.info.lint.isEnabled(Lint.LintCategory.CAST)) 4.40 + public void checkRedundantCast(Env<AttrContext> env, final JCTypeCast tree) { 4.41 + if (!tree.type.isErroneous() 4.42 && types.isSameType(tree.expr.type, tree.clazz.type) 4.43 && !(ignoreAnnotatedCasts && TreeInfo.containsTypeAnnotation(tree.clazz)) 4.44 && !is292targetTypeCast(tree)) { 4.45 - log.warning(Lint.LintCategory.CAST, 4.46 - tree.pos(), "redundant.cast", tree.expr.type); 4.47 + deferredLintHandler.report(new DeferredLintHandler.LintLogger() { 4.48 + @Override 4.49 + public void report() { 4.50 + if (lint.isEnabled(Lint.LintCategory.CAST)) 4.51 + log.warning(Lint.LintCategory.CAST, 4.52 + tree.pos(), "redundant.cast", tree.expr.type); 4.53 + } 4.54 + }); 4.55 } 4.56 } 4.57 //where
5.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Sat Sep 14 19:04:47 2013 +0100 5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Mon Sep 16 14:13:44 2013 +0200 5.3 @@ -84,6 +84,7 @@ 5.4 private final Source source; 5.5 private final Target target; 5.6 private final DeferredLintHandler deferredLintHandler; 5.7 + private final Lint lint; 5.8 5.9 public static MemberEnter instance(Context context) { 5.10 MemberEnter instance = context.get(memberEnterKey); 5.11 @@ -109,6 +110,7 @@ 5.12 source = Source.instance(context); 5.13 target = Target.instance(context); 5.14 deferredLintHandler = DeferredLintHandler.instance(context); 5.15 + lint = Lint.instance(context); 5.16 allowTypeAnnos = source.allowTypeAnnotations(); 5.17 } 5.18 5.19 @@ -506,9 +508,10 @@ 5.20 } 5.21 5.22 // process package annotations 5.23 - annotateLater(tree.packageAnnotations, env, tree.packge); 5.24 + annotateLater(tree.packageAnnotations, env, tree.packge, null); 5.25 5.26 - DeferredLintHandler prevLintHandler = chk.setDeferredLintHandler(DeferredLintHandler.immediateHandler); 5.27 + DiagnosticPosition prevLintPos = deferredLintHandler.immediate(); 5.28 + Lint prevLint = chk.setLint(lint); 5.29 5.30 try { 5.31 // Import-on-demand java.lang. 5.32 @@ -517,7 +520,8 @@ 5.33 // Process all import clauses. 5.34 memberEnter(tree.defs, env); 5.35 } finally { 5.36 - chk.setDeferredLintHandler(prevLintHandler); 5.37 + chk.setLint(prevLint); 5.38 + deferredLintHandler.setPos(prevLintPos); 5.39 } 5.40 } 5.41 5.42 @@ -564,8 +568,7 @@ 5.43 5.44 Env<AttrContext> localEnv = methodEnv(tree, env); 5.45 5.46 - DeferredLintHandler prevLintHandler = 5.47 - chk.setDeferredLintHandler(deferredLintHandler.setPos(tree.pos())); 5.48 + DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); 5.49 try { 5.50 // Compute the method type 5.51 m.type = signature(m, tree.typarams, tree.params, 5.52 @@ -573,7 +576,7 @@ 5.53 tree.thrown, 5.54 localEnv); 5.55 } finally { 5.56 - chk.setDeferredLintHandler(prevLintHandler); 5.57 + deferredLintHandler.setPos(prevLintPos); 5.58 } 5.59 5.60 if (types.isSignaturePolymorphic(m)) { 5.61 @@ -597,10 +600,10 @@ 5.62 if (chk.checkUnique(tree.pos(), m, enclScope)) { 5.63 enclScope.enter(m); 5.64 } 5.65 - annotateLater(tree.mods.annotations, localEnv, m); 5.66 + annotateLater(tree.mods.annotations, localEnv, m, tree.pos()); 5.67 // Visit the signature of the method. Note that 5.68 // TypeAnnotate doesn't descend into the body. 5.69 - typeAnnotate(tree, localEnv, m); 5.70 + typeAnnotate(tree, localEnv, m, tree.pos()); 5.71 5.72 if (tree.defaultValue != null) 5.73 annotateDefaultValueLater(tree.defaultValue, localEnv, m); 5.74 @@ -630,15 +633,14 @@ 5.75 localEnv = env.dup(tree, env.info.dup()); 5.76 localEnv.info.staticLevel++; 5.77 } 5.78 - DeferredLintHandler prevLintHandler = 5.79 - chk.setDeferredLintHandler(deferredLintHandler.setPos(tree.pos())); 5.80 + DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); 5.81 try { 5.82 if (TreeInfo.isEnumInit(tree)) { 5.83 attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype); 5.84 } else { 5.85 // Make sure type annotations are processed. 5.86 // But we don't have a symbol to attach them to yet - use null. 5.87 - typeAnnotate(tree.vartype, env, null); 5.88 + typeAnnotate(tree.vartype, env, null, tree.pos()); 5.89 attr.attribType(tree.vartype, localEnv); 5.90 if (tree.nameexpr != null) { 5.91 attr.attribExpr(tree.nameexpr, localEnv); 5.92 @@ -658,7 +660,7 @@ 5.93 } 5.94 } 5.95 } finally { 5.96 - chk.setDeferredLintHandler(prevLintHandler); 5.97 + deferredLintHandler.setPos(prevLintPos); 5.98 } 5.99 5.100 if ((tree.mods.flags & VARARGS) != 0) { 5.101 @@ -680,15 +682,15 @@ 5.102 needsLazyConstValue(tree.init)) { 5.103 Env<AttrContext> initEnv = getInitEnv(tree, env); 5.104 initEnv.info.enclVar = v; 5.105 - v.setLazyConstValue(initEnv(tree, initEnv), attr, tree.init); 5.106 + v.setLazyConstValue(initEnv(tree, initEnv), attr, tree); 5.107 } 5.108 } 5.109 if (chk.checkUnique(tree.pos(), v, enclScope)) { 5.110 chk.checkTransparentVar(tree.pos(), v, enclScope); 5.111 enclScope.enter(v); 5.112 } 5.113 - annotateLater(tree.mods.annotations, localEnv, v); 5.114 - typeAnnotate(tree.vartype, env, v); 5.115 + annotateLater(tree.mods.annotations, localEnv, v, tree.pos()); 5.116 + typeAnnotate(tree.vartype, env, v, tree.pos()); 5.117 annotate.flush(); 5.118 v.pos = tree.pos; 5.119 } 5.120 @@ -720,6 +722,11 @@ 5.121 } 5.122 5.123 @Override 5.124 + public void visitNewArray(JCNewArray that) { 5.125 + result = false; 5.126 + } 5.127 + 5.128 + @Override 5.129 public void visitLambda(JCLambda that) { 5.130 result = false; 5.131 } 5.132 @@ -730,6 +737,11 @@ 5.133 } 5.134 5.135 @Override 5.136 + public void visitApply(JCMethodInvocation that) { 5.137 + result = false; 5.138 + } 5.139 + 5.140 + @Override 5.141 public void visitSelect(JCFieldAccess tree) { 5.142 tree.selected.accept(this); 5.143 } 5.144 @@ -820,7 +832,8 @@ 5.145 /** Queue annotations for later processing. */ 5.146 void annotateLater(final List<JCAnnotation> annotations, 5.147 final Env<AttrContext> localEnv, 5.148 - final Symbol s) { 5.149 + final Symbol s, 5.150 + final DiagnosticPosition deferPos) { 5.151 if (annotations.isEmpty()) { 5.152 return; 5.153 } 5.154 @@ -837,6 +850,11 @@ 5.155 public void enterAnnotation() { 5.156 Assert.check(s.kind == PCK || s.annotationsPendingCompletion()); 5.157 JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); 5.158 + DiagnosticPosition prevLintPos = 5.159 + deferPos != null 5.160 + ? deferredLintHandler.setPos(deferPos) 5.161 + : deferredLintHandler.immediate(); 5.162 + Lint prevLint = deferPos != null ? null : chk.setLint(lint); 5.163 try { 5.164 if (s.hasAnnotations() && 5.165 annotations.nonEmpty()) 5.166 @@ -845,6 +863,9 @@ 5.167 kindName(s), s); 5.168 actualEnterAnnotations(annotations, localEnv, s); 5.169 } finally { 5.170 + if (prevLint != null) 5.171 + chk.setLint(prevLint); 5.172 + deferredLintHandler.setPos(prevLintPos); 5.173 log.useSource(prev); 5.174 } 5.175 } 5.176 @@ -964,6 +985,7 @@ 5.177 isFirst = false; 5.178 5.179 JavaFileObject prev = log.useSource(env.toplevel.sourcefile); 5.180 + DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); 5.181 try { 5.182 // Save class environment for later member enter (2) processing. 5.183 halfcompleted.append(env); 5.184 @@ -985,9 +1007,9 @@ 5.185 Env<AttrContext> baseEnv = baseEnv(tree, env); 5.186 5.187 if (tree.extending != null) 5.188 - typeAnnotate(tree.extending, baseEnv, sym); 5.189 + typeAnnotate(tree.extending, baseEnv, sym, tree.pos()); 5.190 for (JCExpression impl : tree.implementing) 5.191 - typeAnnotate(impl, baseEnv, sym); 5.192 + typeAnnotate(impl, baseEnv, sym, tree.pos()); 5.193 annotate.flush(); 5.194 5.195 // Determine supertype. 5.196 @@ -1048,7 +1070,7 @@ 5.197 attr.attribAnnotationTypes(tree.mods.annotations, baseEnv); 5.198 if (hasDeprecatedAnnotation(tree.mods.annotations)) 5.199 c.flags_field |= DEPRECATED; 5.200 - annotateLater(tree.mods.annotations, baseEnv, c); 5.201 + annotateLater(tree.mods.annotations, baseEnv, c, tree.pos()); 5.202 // class type parameters use baseEnv but everything uses env 5.203 5.204 chk.checkNonCyclicDecl(tree); 5.205 @@ -1056,7 +1078,7 @@ 5.206 attr.attribTypeVariables(tree.typarams, baseEnv); 5.207 // Do this here, where we have the symbol. 5.208 for (JCTypeParameter tp : tree.typarams) 5.209 - typeAnnotate(tp, baseEnv, sym); 5.210 + typeAnnotate(tp, baseEnv, sym, tree.pos()); 5.211 annotate.flush(); 5.212 5.213 // Add default constructor if needed. 5.214 @@ -1126,6 +1148,7 @@ 5.215 } catch (CompletionFailure ex) { 5.216 chk.completionError(tree.pos(), ex); 5.217 } finally { 5.218 + deferredLintHandler.setPos(prevLintPos); 5.219 log.useSource(prev); 5.220 } 5.221 5.222 @@ -1186,9 +1209,9 @@ 5.223 } 5.224 } 5.225 5.226 - public void typeAnnotate(final JCTree tree, final Env<AttrContext> env, final Symbol sym) { 5.227 + public void typeAnnotate(final JCTree tree, final Env<AttrContext> env, final Symbol sym, DiagnosticPosition deferPos) { 5.228 if (allowTypeAnnos) { 5.229 - tree.accept(new TypeAnnotate(env, sym)); 5.230 + tree.accept(new TypeAnnotate(env, sym, deferPos)); 5.231 } 5.232 } 5.233 5.234 @@ -1199,10 +1222,12 @@ 5.235 private class TypeAnnotate extends TreeScanner { 5.236 private Env<AttrContext> env; 5.237 private Symbol sym; 5.238 + private DiagnosticPosition deferPos; 5.239 5.240 - public TypeAnnotate(final Env<AttrContext> env, final Symbol sym) { 5.241 + public TypeAnnotate(final Env<AttrContext> env, final Symbol sym, DiagnosticPosition deferPos) { 5.242 this.env = env; 5.243 this.sym = sym; 5.244 + this.deferPos = deferPos; 5.245 } 5.246 5.247 void annotateTypeLater(final List<JCAnnotation> annotations) { 5.248 @@ -1210,6 +1235,8 @@ 5.249 return; 5.250 } 5.251 5.252 + final DiagnosticPosition deferPos = this.deferPos; 5.253 + 5.254 annotate.normal(new Annotate.Annotator() { 5.255 @Override 5.256 public String toString() { 5.257 @@ -1218,9 +1245,16 @@ 5.258 @Override 5.259 public void enterAnnotation() { 5.260 JavaFileObject prev = log.useSource(env.toplevel.sourcefile); 5.261 + DiagnosticPosition prevLintPos = null; 5.262 + 5.263 + if (deferPos != null) { 5.264 + prevLintPos = deferredLintHandler.setPos(deferPos); 5.265 + } 5.266 try { 5.267 actualEnterTypeAnnotations(annotations, env, sym); 5.268 } finally { 5.269 + if (prevLintPos != null) 5.270 + deferredLintHandler.setPos(prevLintPos); 5.271 log.useSource(prev); 5.272 } 5.273 } 5.274 @@ -1262,13 +1296,19 @@ 5.275 5.276 @Override 5.277 public void visitVarDef(final JCVariableDecl tree) { 5.278 - if (sym != null && sym.kind == Kinds.VAR) { 5.279 - // Don't visit a parameter once when the sym is the method 5.280 - // and once when the sym is the parameter. 5.281 - scan(tree.mods); 5.282 - scan(tree.vartype); 5.283 + DiagnosticPosition prevPos = deferPos; 5.284 + deferPos = tree.pos(); 5.285 + try { 5.286 + if (sym != null && sym.kind == Kinds.VAR) { 5.287 + // Don't visit a parameter once when the sym is the method 5.288 + // and once when the sym is the parameter. 5.289 + scan(tree.mods); 5.290 + scan(tree.vartype); 5.291 + } 5.292 + scan(tree.init); 5.293 + } finally { 5.294 + deferPos = prevPos; 5.295 } 5.296 - scan(tree.init); 5.297 } 5.298 5.299 @Override
6.1 --- a/test/tools/javac/depDocComment/SuppressDeprecation.out Sat Sep 14 19:04:47 2013 +0100 6.2 +++ b/test/tools/javac/depDocComment/SuppressDeprecation.out Mon Sep 16 14:13:44 2013 +0200 6.3 @@ -1,8 +1,8 @@ 6.4 -SuppressDeprecation.java:130:17: compiler.warn.has.been.deprecated: X, compiler.misc.unnamed.package 6.5 SuppressDeprecation.java:82:10: compiler.warn.has.been.deprecated: g(), T 6.6 SuppressDeprecation.java:83:14: compiler.warn.has.been.deprecated: g(), T 6.7 SuppressDeprecation.java:84:9: compiler.warn.has.been.deprecated: var, T 6.8 SuppressDeprecation.java:87:9: compiler.warn.has.been.deprecated: T(), T 6.9 SuppressDeprecation.java:90:9: compiler.warn.has.been.deprecated: T(int), T 6.10 SuppressDeprecation.java:98:1: compiler.warn.has.been.deprecated: T(), T 6.11 +SuppressDeprecation.java:130:17: compiler.warn.has.been.deprecated: X, compiler.misc.unnamed.package 6.12 7 warnings
7.1 --- a/test/tools/javac/warnings/6594914/T6594914a.out Sat Sep 14 19:04:47 2013 +0100 7.2 +++ b/test/tools/javac/warnings/6594914/T6594914a.out Mon Sep 16 14:13:44 2013 +0200 7.3 @@ -1,7 +1,7 @@ 7.4 T6594914a.java:11:5: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 7.5 T6594914a.java:16:16: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 7.6 -T6594914a.java:16:52: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 7.7 T6594914a.java:16:33: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 7.8 T6594914a.java:17:20: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 7.9 +T6594914a.java:16:52: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 7.10 T6594914a.java:24:9: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 7.11 6 warnings
8.1 --- a/test/tools/javac/warnings/6594914/T6594914b.out Sat Sep 14 19:04:47 2013 +0100 8.2 +++ b/test/tools/javac/warnings/6594914/T6594914b.out Mon Sep 16 14:13:44 2013 +0200 8.3 @@ -1,7 +1,7 @@ 8.4 T6594914b.java:11:13: compiler.warn.sun.proprietary: sun.misc.Lock 8.5 T6594914b.java:16:24: compiler.warn.sun.proprietary: sun.misc.Lock 8.6 -T6594914b.java:16:56: compiler.warn.sun.proprietary: sun.misc.Lock 8.7 T6594914b.java:16:39: compiler.warn.sun.proprietary: sun.misc.Lock 8.8 T6594914b.java:17:28: compiler.warn.sun.proprietary: sun.misc.CEFormatException 8.9 +T6594914b.java:16:56: compiler.warn.sun.proprietary: sun.misc.Lock 8.10 T6594914b.java:24:17: compiler.warn.sun.proprietary: sun.misc.Lock 8.11 6 warnings
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/test/tools/javac/warnings/suppress/ImplicitTest.java Mon Sep 16 14:13:44 2013 +0200 9.3 @@ -0,0 +1,31 @@ 9.4 +/* 9.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.7 + * 9.8 + * This code is free software; you can redistribute it and/or modify it 9.9 + * under the terms of the GNU General Public License version 2 only, as 9.10 + * published by the Free Software Foundation. 9.11 + * 9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 9.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 9.15 + * version 2 for more details (a copy is included in the LICENSE file that 9.16 + * accompanied this code). 9.17 + * 9.18 + * You should have received a copy of the GNU General Public License version 9.19 + * 2 along with this work; if not, write to the Free Software Foundation, 9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 9.21 + * 9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 9.23 + * or visit www.oracle.com if you need additional information or have any 9.24 + * questions. 9.25 + */ 9.26 + 9.27 +/** 9.28 + * @test 9.29 + * @bug 8021112 9.30 + * @summary Verify that deprecated warning is printed correctly for import 9.31 + * statement when processing a file on demand while attributing another file. 9.32 + * @clean pack.ImplicitUse pack.ImplicitMain pack.Dep 9.33 + * @compile/ref=ImplicitTest.out -XDrawDiagnostics -Xlint:deprecation pack/ImplicitMain.java 9.34 + */
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/test/tools/javac/warnings/suppress/ImplicitTest.out Mon Sep 16 14:13:44 2013 +0200 10.3 @@ -0,0 +1,2 @@ 10.4 +ImplicitUse.java:4:12: compiler.warn.has.been.deprecated: pack.Dep, pack 10.5 +1 warning 10.6 \ No newline at end of file
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/tools/javac/warnings/suppress/PackageInfo.java Mon Sep 16 14:13:44 2013 +0200 11.3 @@ -0,0 +1,30 @@ 11.4 +/* 11.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.7 + * 11.8 + * This code is free software; you can redistribute it and/or modify it 11.9 + * under the terms of the GNU General Public License version 2 only, as 11.10 + * published by the Free Software Foundation. 11.11 + * 11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11.15 + * version 2 for more details (a copy is included in the LICENSE file that 11.16 + * accompanied this code). 11.17 + * 11.18 + * You should have received a copy of the GNU General Public License version 11.19 + * 2 along with this work; if not, write to the Free Software Foundation, 11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 11.21 + * 11.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 11.23 + * or visit www.oracle.com if you need additional information or have any 11.24 + * questions. 11.25 + */ 11.26 + 11.27 +/** 11.28 + * @test 11.29 + * @bug 8021112 11.30 + * @summary Verify that deprecated warnings are printed correctly for package-info.java 11.31 + * @clean pack.package-info pack.DeprecatedClass 11.32 + * @compile/ref=PackageInfo.out -XDrawDiagnostics -Xlint:deprecation pack/package-info.java pack/DeprecatedClass.java 11.33 + */
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/tools/javac/warnings/suppress/PackageInfo.out Mon Sep 16 14:13:44 2013 +0200 12.3 @@ -0,0 +1,3 @@ 12.4 +package-info.java:5:12: compiler.warn.has.been.deprecated: pack.DeprecatedClass, pack 12.5 +package-info.java:2:2: compiler.warn.has.been.deprecated: pack.DeprecatedClass, pack 12.6 +2 warnings
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/tools/javac/warnings/suppress/T6480588.java Mon Sep 16 14:13:44 2013 +0200 13.3 @@ -0,0 +1,36 @@ 13.4 +/** 13.5 + * @test /nodynamiccopyright/ 13.6 + * @bug 6470588 13.7 + * @summary Verify that \\@SuppressWarnings("deprecation") works OK for all parts 13.8 + * of class/method/field "header", including (declaration) annotations 13.9 + * @build VerifySuppressWarnings 13.10 + * @compile/ref=T6480588.out -XDrawDiagnostics -Xlint:unchecked,deprecation,cast T6480588.java 13.11 + * @run main VerifySuppressWarnings T6480588.java 13.12 + */ 13.13 + 13.14 +@DeprecatedAnnotation 13.15 +class T6480588 extends DeprecatedClass implements DeprecatedInterface { 13.16 + @DeprecatedAnnotation 13.17 + public DeprecatedClass method(DeprecatedClass param) throws DeprecatedClass { 13.18 + DeprecatedClass lv = new DeprecatedClass(); 13.19 + @Deprecated 13.20 + DeprecatedClass lvd = new DeprecatedClass(); 13.21 + return null; 13.22 + } 13.23 + 13.24 + @Deprecated 13.25 + public void methodD() { 13.26 + } 13.27 + 13.28 + @DeprecatedAnnotation 13.29 + DeprecatedClass field = new DeprecatedClass(); 13.30 + 13.31 + @DeprecatedAnnotation 13.32 + class Inner extends DeprecatedClass implements DeprecatedInterface { 13.33 + } 13.34 + 13.35 +} 13.36 + 13.37 +@Deprecated class DeprecatedClass extends Throwable { } 13.38 +@Deprecated interface DeprecatedInterface { } 13.39 +@Deprecated @interface DeprecatedAnnotation { }
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/tools/javac/warnings/suppress/T6480588.out Mon Sep 16 14:13:44 2013 +0200 14.3 @@ -0,0 +1,18 @@ 14.4 +T6480588.java:12:24: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 14.5 +T6480588.java:12:51: compiler.warn.has.been.deprecated: DeprecatedInterface, compiler.misc.unnamed.package 14.6 +T6480588.java:11:2: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package 14.7 +T6480588.java:14:12: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 14.8 +T6480588.java:14:65: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 14.9 +T6480588.java:13:6: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package 14.10 +T6480588.java:14:35: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 14.11 +T6480588.java:15:9: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 14.12 +T6480588.java:15:34: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 14.13 +T6480588.java:17:9: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 14.14 +T6480588.java:17:35: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 14.15 +T6480588.java:26:5: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 14.16 +T6480588.java:25:6: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package 14.17 +T6480588.java:26:33: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 14.18 +T6480588.java:29:25: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package 14.19 +T6480588.java:29:52: compiler.warn.has.been.deprecated: DeprecatedInterface, compiler.misc.unnamed.package 14.20 +T6480588.java:28:6: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package 14.21 +17 warnings 14.22 \ No newline at end of file
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/tools/javac/warnings/suppress/T8021112a.java Mon Sep 16 14:13:44 2013 +0200 15.3 @@ -0,0 +1,45 @@ 15.4 +/* 15.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.7 + * 15.8 + * This code is free software; you can redistribute it and/or modify it 15.9 + * under the terms of the GNU General Public License version 2 only, as 15.10 + * published by the Free Software Foundation. 15.11 + * 15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15.15 + * version 2 for more details (a copy is included in the LICENSE file that 15.16 + * accompanied this code). 15.17 + * 15.18 + * You should have received a copy of the GNU General Public License version 15.19 + * 2 along with this work; if not, write to the Free Software Foundation, 15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 15.21 + * 15.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 15.23 + * or visit www.oracle.com if you need additional information or have any 15.24 + * questions. 15.25 + */ 15.26 +package test; 15.27 + 15.28 +/** 15.29 + * @test 15.30 + * @bug 8021112 15.31 + * @summary Verify that \\@SuppressWarnings work even if the value is defined 15.32 + * inside the suppressed class itself, and verify that "unnecessary cast" 15.33 + * lint can be properly suppressed. 15.34 + * @compile -Xlint:cast -Werror T8021112a.java 15.35 + */ 15.36 + 15.37 +import static test.T8021112a.D; 15.38 + 15.39 +@SuppressWarnings(D) 15.40 +public class T8021112a { 15.41 + public static final String D = (String) "cast"; 15.42 +} 15.43 + 15.44 +class Other { 15.45 + public static final String D = "cast"; 15.46 + @SuppressWarnings(D) 15.47 + public static final String D2 = (String) "cast"; 15.48 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/tools/javac/warnings/suppress/T8021112b.java Mon Sep 16 14:13:44 2013 +0200 16.3 @@ -0,0 +1,22 @@ 16.4 +/** 16.5 + * @test /nodynamiccopyright/ 16.6 + * @bug 8021112 16.7 + * @summary Verify that \\@SuppressWarnings("unchecked") works correctly for lazy attrib values 16.8 + * @build VerifySuppressWarnings 16.9 + * @compile/ref=T8021112b.out -XDrawDiagnostics -Xlint:unchecked,deprecation,cast T8021112b.java 16.10 + * @run main VerifySuppressWarnings T8021112b.java 16.11 + */ 16.12 + 16.13 +public class T8021112b { 16.14 + public static final String D1 = Dep.D; 16.15 + public static final String D2 = ""; 16.16 + public static final Object[] o = { 16.17 + new Object() { 16.18 + Dep d; 16.19 + } 16.20 + }; 16.21 +} 16.22 + 16.23 +@Deprecated class Dep { 16.24 + public static final String D = T8021112b.D2; 16.25 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/tools/javac/warnings/suppress/T8021112b.out Mon Sep 16 14:13:44 2013 +0200 17.3 @@ -0,0 +1,3 @@ 17.4 +T8021112b.java:11:37: compiler.warn.has.been.deprecated: Dep, compiler.misc.unnamed.package 17.5 +T8021112b.java:15:13: compiler.warn.has.been.deprecated: Dep, compiler.misc.unnamed.package 17.6 +2 warnings 17.7 \ No newline at end of file
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/test/tools/javac/warnings/suppress/TypeAnnotations.java Mon Sep 16 14:13:44 2013 +0200 18.3 @@ -0,0 +1,51 @@ 18.4 +/** 18.5 + * @test /nodynamiccopyright/ 18.6 + * @bug 8021112 18.7 + * @summary Verify that \\@SuppressWarnings("unchecked") works for type annotations 18.8 + * @build VerifySuppressWarnings 18.9 + * @compile/ref=TypeAnnotations.out -XDrawDiagnostics -Xlint:unchecked,deprecation,cast TypeAnnotations.java 18.10 + * @run main VerifySuppressWarnings TypeAnnotations.java 18.11 + */ 18.12 + 18.13 +import java.lang.annotation.*; 18.14 + 18.15 +public class TypeAnnotations extends @TA Object implements @TA Runnable { 18.16 + 18.17 + public @TA String @TA [] m(@TA String @TA [] p) throws @TA Throwable { 18.18 + Runnable r = () -> { 18.19 + @TA Object tested = null; 18.20 + @TA boolean isAnnotated = tested instanceof @TA String; 18.21 + }; 18.22 + 18.23 + @TA Object tested = null; 18.24 + @TA boolean isAnnotated = tested instanceof @TA String; 18.25 + 18.26 + return (@TA String @TA []) null; 18.27 + } 18.28 + 18.29 + { 18.30 + Runnable r = () -> { 18.31 + @TA Object tested = null; 18.32 + @TA boolean isAnnotated = tested instanceof @TA String; 18.33 + }; 18.34 + 18.35 + @TA Object tested = null; 18.36 + @TA boolean isAnnotated = tested instanceof @TA String; 18.37 + 18.38 + @TA String @TA [] ret = (@TA String @TA []) null; 18.39 + } 18.40 + 18.41 + @TA String @TA [] f = new @TA String @TA[0]; 18.42 + 18.43 + @Override public void run() { } 18.44 + 18.45 + public static class Inner extends @TA Object implements @TA Runnable { 18.46 + @Override public void run() { } 18.47 + } 18.48 +} 18.49 + 18.50 +@Target({ElementType.TYPE_USE, ElementType.TYPE}) 18.51 +@Deprecated 18.52 +@interface TA { 18.53 + 18.54 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/test/tools/javac/warnings/suppress/TypeAnnotations.out Mon Sep 16 14:13:44 2013 +0200 19.3 @@ -0,0 +1,41 @@ 19.4 +TypeAnnotations.java:12:39: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.5 +TypeAnnotations.java:12:61: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.6 +TypeAnnotations.java:14:24: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.7 +TypeAnnotations.java:14:61: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.8 +TypeAnnotations.java:14:13: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.9 +TypeAnnotations.java:14:44: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.10 +TypeAnnotations.java:14:33: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.11 +TypeAnnotations.java:23:29: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.12 +TypeAnnotations.java:23:18: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.13 +TypeAnnotations.java:16:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.14 +TypeAnnotations.java:17:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.15 +TypeAnnotations.java:17:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.16 +TypeAnnotations.java:17:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.17 +TypeAnnotations.java:20:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.18 +TypeAnnotations.java:21:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.19 +TypeAnnotations.java:21:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.20 +TypeAnnotations.java:21:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.21 +TypeAnnotations.java:23:18: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.22 +TypeAnnotations.java:23:29: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.23 +TypeAnnotations.java:28:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.24 +TypeAnnotations.java:29:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.25 +TypeAnnotations.java:29:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.26 +TypeAnnotations.java:29:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.27 +TypeAnnotations.java:32:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.28 +TypeAnnotations.java:33:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.29 +TypeAnnotations.java:33:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.30 +TypeAnnotations.java:33:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.31 +TypeAnnotations.java:35:46: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.32 +TypeAnnotations.java:35:35: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.33 +TypeAnnotations.java:35:21: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.34 +TypeAnnotations.java:35:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.35 +TypeAnnotations.java:35:35: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.36 +TypeAnnotations.java:35:46: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.37 +TypeAnnotations.java:38:17: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.38 +TypeAnnotations.java:38:6: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.39 +TypeAnnotations.java:38:43: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.40 +TypeAnnotations.java:38:32: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.41 +TypeAnnotations.java:38:32: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.42 +TypeAnnotations.java:42:40: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.43 +TypeAnnotations.java:42:62: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package 19.44 +40 warnings 19.45 \ No newline at end of file
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/test/tools/javac/warnings/suppress/VerifySuppressWarnings.java Mon Sep 16 14:13:44 2013 +0200 20.3 @@ -0,0 +1,212 @@ 20.4 +/* 20.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.7 + * 20.8 + * This code is free software; you can redistribute it and/or modify it 20.9 + * under the terms of the GNU General Public License version 2 only, as 20.10 + * published by the Free Software Foundation. 20.11 + * 20.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 20.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20.15 + * version 2 for more details (a copy is included in the LICENSE file that 20.16 + * accompanied this code). 20.17 + * 20.18 + * You should have received a copy of the GNU General Public License version 20.19 + * 2 along with this work; if not, write to the Free Software Foundation, 20.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20.21 + * 20.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20.23 + * or visit www.oracle.com if you need additional information or have any 20.24 + * questions. 20.25 + */ 20.26 + 20.27 +import com.sun.source.tree.ClassTree; 20.28 +import com.sun.source.tree.CompilationUnitTree; 20.29 +import com.sun.source.tree.MethodTree; 20.30 +import com.sun.source.tree.NewClassTree; 20.31 +import com.sun.source.tree.Tree; 20.32 +import com.sun.source.tree.VariableTree; 20.33 +import com.sun.source.util.JavacTask; 20.34 +import com.sun.source.util.TreeScanner; 20.35 +import com.sun.source.util.Trees; 20.36 +import com.sun.tools.javac.api.JavacTool; 20.37 +import com.sun.tools.javac.code.Flags; 20.38 +import com.sun.tools.javac.file.JavacFileManager; 20.39 +import com.sun.tools.javac.tree.JCTree.JCMethodDecl; 20.40 +import java.io.File; 20.41 +import java.io.IOException; 20.42 +import java.net.URI; 20.43 +import java.net.URISyntaxException; 20.44 +import java.util.ArrayList; 20.45 +import java.util.Arrays; 20.46 +import java.util.Iterator; 20.47 +import java.util.List; 20.48 +import javax.tools.Diagnostic; 20.49 +import javax.tools.DiagnosticListener; 20.50 +import javax.tools.FileObject; 20.51 +import javax.tools.ForwardingJavaFileManager; 20.52 +import javax.tools.JavaFileManager; 20.53 +import javax.tools.JavaFileObject; 20.54 +import javax.tools.SimpleJavaFileObject; 20.55 + 20.56 +/**Takes a source file, parses it once to get the warnings inside the file and 20.57 + * then for each and every declaration in the file, it tries to place 20.58 + * the @SuppressWarnings annotation on the declaration and verifies than no 20.59 + * warnings are produced inside the declaration, but all are produced outside it. 20.60 + * 20.61 + * Currently only works with <code>unchecked,deprecation,cast</code> warnings. 20.62 + */ 20.63 +public class VerifySuppressWarnings { 20.64 + 20.65 + private static final List<String> STANDARD_PARAMS = Arrays.asList("-Xlint:unchecked,deprecation,cast", "-Xjcov"); 20.66 + 20.67 + public static void main(String... args) throws IOException, URISyntaxException { 20.68 + if (args.length != 1) throw new IllegalStateException("Must provide class name!"); 20.69 + String testContent = null; 20.70 + List<File> sourcePath = new ArrayList<>(); 20.71 + for (String sourcePaths : System.getProperty("test.src.path").split(":")) { 20.72 + sourcePath.add(new File(sourcePaths)); 20.73 + } 20.74 + JavacFileManager fm = JavacTool.create().getStandardFileManager(null, null, null); 20.75 + for (File sp : sourcePath) { 20.76 + File inp = new File(sp, args[0]); 20.77 + 20.78 + if (inp.canRead()) { 20.79 + testContent = fm.getRegularFile(inp).getCharContent(true).toString(); 20.80 + } 20.81 + } 20.82 + if (testContent == null) throw new IllegalStateException(); 20.83 + final List<Diagnostic<?>> diagnostics = new ArrayList<>(); 20.84 + DiagnosticListener<JavaFileObject> collectDiagnostics = new DiagnosticListener<JavaFileObject>() { 20.85 + @Override public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 20.86 + diagnostics.add(diagnostic); 20.87 + } 20.88 + }; 20.89 + JavaFileObject testFile = new TestFO(new URI("mem://" + args[0]), testContent); 20.90 + JavacTask task = JavacTool.create().getTask(null, 20.91 + new TestFM(fm), 20.92 + collectDiagnostics, 20.93 + STANDARD_PARAMS, 20.94 + null, 20.95 + Arrays.asList(testFile)); 20.96 + final Trees trees = Trees.instance(task); 20.97 + final CompilationUnitTree cut = task.parse().iterator().next(); 20.98 + task.analyze(); 20.99 + 20.100 + final List<int[]> declarationSpans = new ArrayList<>(); 20.101 + 20.102 + new TreeScanner<Void, Void>() { 20.103 + @Override public Void visitClass(ClassTree node, Void p) { 20.104 + handleDeclaration(node); 20.105 + return super.visitClass(node, p); 20.106 + } 20.107 + @Override public Void visitMethod(MethodTree node, Void p) { 20.108 + handleDeclaration(node); 20.109 + return super.visitMethod(node, p); 20.110 + } 20.111 + @Override public Void visitVariable(VariableTree node, Void p) { 20.112 + handleDeclaration(node); 20.113 + return super.visitVariable(node, p); 20.114 + } 20.115 + 20.116 + @Override 20.117 + public Void visitNewClass(NewClassTree node, Void p) { 20.118 + if (node.getClassBody() != null) { 20.119 + scan(node.getClassBody().getMembers(), null); 20.120 + } 20.121 + return null; 20.122 + } 20.123 + 20.124 + private void handleDeclaration(Tree node) { 20.125 + int endPos = (int) trees.getSourcePositions().getEndPosition(cut, node); 20.126 + 20.127 + if (endPos == (-1)) { 20.128 + if (node.getKind() == Tree.Kind.METHOD && (((JCMethodDecl) node).getModifiers().flags & Flags.GENERATEDCONSTR) != 0) { 20.129 + return ; 20.130 + } 20.131 + throw new IllegalStateException(); 20.132 + } 20.133 + 20.134 + declarationSpans.add(new int[] {(int) trees.getSourcePositions().getStartPosition(cut, node), endPos}); 20.135 + } 20.136 + }.scan(cut, null); 20.137 + 20.138 + for (final int[] declarationSpan : declarationSpans) { 20.139 + final String suppressWarnings = "@SuppressWarnings({\"deprecation\", \"unchecked\", \"serial\"})"; 20.140 + final String updatedContent = testContent.substring(0, declarationSpan[0]) + suppressWarnings + testContent.substring(declarationSpan[0]); 20.141 + final List<Diagnostic<?>> foundErrors = new ArrayList<>(diagnostics); 20.142 + DiagnosticListener<JavaFileObject> verifyDiagnostics = new DiagnosticListener<JavaFileObject>() { 20.143 + @Override public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 20.144 + long adjustedPos = diagnostic.getPosition(); 20.145 + 20.146 + if (adjustedPos >= declarationSpan[0]) adjustedPos -= suppressWarnings.length(); 20.147 + 20.148 + if (declarationSpan[0] <= adjustedPos && adjustedPos <= declarationSpan[1]) { 20.149 + throw new IllegalStateException("unsuppressed: " + diagnostic.getMessage(null)); 20.150 + } 20.151 + 20.152 + boolean found = false; 20.153 + 20.154 + for (Iterator<Diagnostic<?>> it = foundErrors.iterator(); it.hasNext();) { 20.155 + Diagnostic<?> d = it.next(); 20.156 + if (d.getPosition() == adjustedPos && d.getCode().equals(diagnostic.getCode())) { 20.157 + it.remove(); 20.158 + found = true; 20.159 + break; 20.160 + } 20.161 + } 20.162 + 20.163 + if (!found) { 20.164 + throw new IllegalStateException("diagnostic not originally reported: " + diagnostic.getMessage(null)); 20.165 + } 20.166 + } 20.167 + }; 20.168 + 20.169 + JavaFileObject updatedFile = new TestFO(new URI("mem://" + args[0]), updatedContent); 20.170 + JavacTask testTask = JavacTool.create().getTask(null, 20.171 + new TestFM(fm), 20.172 + verifyDiagnostics, 20.173 + STANDARD_PARAMS, 20.174 + null, 20.175 + Arrays.asList(updatedFile)); 20.176 + 20.177 + testTask.analyze(); 20.178 + 20.179 + for (Diagnostic<?> d : foundErrors) { 20.180 + if (d.getPosition() < declarationSpan[0] || declarationSpan[1] < d.getPosition()) { 20.181 + throw new IllegalStateException("missing: " + d.getMessage(null)); 20.182 + } 20.183 + } 20.184 + } 20.185 + } 20.186 + 20.187 + private static final class TestFO extends SimpleJavaFileObject { 20.188 + private final String content; 20.189 + public TestFO(URI uri, String content) { 20.190 + super(uri, Kind.SOURCE); 20.191 + this.content = content; 20.192 + } 20.193 + 20.194 + @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { 20.195 + return content; 20.196 + } 20.197 + 20.198 + @Override public boolean isNameCompatible(String simpleName, Kind kind) { 20.199 + return true; 20.200 + } 20.201 + } 20.202 + 20.203 + private static final class TestFM extends ForwardingJavaFileManager<JavaFileManager> { 20.204 + 20.205 + public TestFM(JavaFileManager fileManager) { 20.206 + super(fileManager); 20.207 + } 20.208 + 20.209 + @Override 20.210 + public boolean isSameFile(FileObject a, FileObject b) { 20.211 + return a.equals(b); 20.212 + } 20.213 + 20.214 + } 20.215 +}
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/test/tools/javac/warnings/suppress/pack/DeprecatedClass.java Mon Sep 16 14:13:44 2013 +0200 21.3 @@ -0,0 +1,5 @@ 21.4 +/* /nodynamiccopyright/ */ 21.5 +package pack; 21.6 +@Deprecated 21.7 +@interface DeprecatedClass { 21.8 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/test/tools/javac/warnings/suppress/pack/ImplicitMain.java Mon Sep 16 14:13:44 2013 +0200 22.3 @@ -0,0 +1,14 @@ 22.4 +/* /nodynamiccopyright/ */ 22.5 +package pack; 22.6 + 22.7 +@SuppressWarnings("deprecation") 22.8 +public class ImplicitMain { 22.9 + private Object test() { 22.10 + return new ImplicitUse(); 22.11 + } 22.12 +} 22.13 + 22.14 +@Deprecated 22.15 +class Dep { 22.16 + 22.17 +}
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/test/tools/javac/warnings/suppress/pack/ImplicitUse.java Mon Sep 16 14:13:44 2013 +0200 23.3 @@ -0,0 +1,7 @@ 23.4 +/* /nodynamiccopyright/ */ 23.5 +package pack; 23.6 + 23.7 +import pack.Dep; 23.8 + 23.9 +public class ImplicitUse { 23.10 +}
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/test/tools/javac/warnings/suppress/pack/package-info.java Mon Sep 16 14:13:44 2013 +0200 24.3 @@ -0,0 +1,5 @@ 24.4 +/* /nodynamiccopyright/ */ 24.5 +@DeprecatedClass 24.6 +package pack; 24.7 + 24.8 +import pack.DeprecatedClass;