src/share/classes/com/sun/tools/javac/comp/Attr.java

changeset 795
7b99f98b3035
parent 780
1d625fbe6c22
child 798
4868a36f6fd8
equal deleted inserted replaced
794:2f2ead61db06 795:7b99f98b3035
36 import com.sun.tools.javac.util.*; 36 import com.sun.tools.javac.util.*;
37 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 37 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
38 import com.sun.tools.javac.util.List; 38 import com.sun.tools.javac.util.List;
39 39
40 import com.sun.tools.javac.jvm.Target; 40 import com.sun.tools.javac.jvm.Target;
41 import com.sun.tools.javac.code.Lint.LintCategory;
41 import com.sun.tools.javac.code.Symbol.*; 42 import com.sun.tools.javac.code.Symbol.*;
42 import com.sun.tools.javac.tree.JCTree.*; 43 import com.sun.tools.javac.tree.JCTree.*;
43 import com.sun.tools.javac.code.Type.*; 44 import com.sun.tools.javac.code.Type.*;
44 45
45 import com.sun.source.tree.IdentifierTree; 46 import com.sun.source.tree.IdentifierTree;
667 public void visitMethodDef(JCMethodDecl tree) { 668 public void visitMethodDef(JCMethodDecl tree) {
668 MethodSymbol m = tree.sym; 669 MethodSymbol m = tree.sym;
669 670
670 Lint lint = env.info.lint.augment(m.attributes_field, m.flags()); 671 Lint lint = env.info.lint.augment(m.attributes_field, m.flags());
671 Lint prevLint = chk.setLint(lint); 672 Lint prevLint = chk.setLint(lint);
673 MethodSymbol prevMethod = chk.setMethod(m);
672 try { 674 try {
673 chk.checkDeprecatedAnnotation(tree.pos(), m); 675 chk.checkDeprecatedAnnotation(tree.pos(), m);
674 676
675 attribBounds(tree.typarams); 677 attribBounds(tree.typarams);
676 678
698 // Attribute all value parameters. 700 // Attribute all value parameters.
699 for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { 701 for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
700 attribStat(l.head, localEnv); 702 attribStat(l.head, localEnv);
701 } 703 }
702 704
703 chk.checkVarargMethodDecl(tree); 705 chk.checkVarargsMethodDecl(localEnv, tree);
704 706
705 // Check that type parameters are well-formed. 707 // Check that type parameters are well-formed.
706 chk.validate(tree.typarams, localEnv); 708 chk.validate(tree.typarams, localEnv);
707 709
708 // Check that result type is well-formed. 710 // Check that result type is well-formed.
787 result = tree.type = m.type; 789 result = tree.type = m.type;
788 chk.validateAnnotations(tree.mods.annotations, m); 790 chk.validateAnnotations(tree.mods.annotations, m);
789 } 791 }
790 finally { 792 finally {
791 chk.setLint(prevLint); 793 chk.setLint(prevLint);
794 chk.setMethod(prevMethod);
792 } 795 }
793 } 796 }
794 797
795 public void visitVarDef(JCVariableDecl tree) { 798 public void visitVarDef(JCVariableDecl tree) {
796 // Local variables have not been entered yet, so we need to do it now: 799 // Local variables have not been entered yet, so we need to do it now:
2270 if (sitesym != null && 2273 if (sitesym != null &&
2271 sitesym.kind == VAR && 2274 sitesym.kind == VAR &&
2272 ((VarSymbol)sitesym).isResourceVariable() && 2275 ((VarSymbol)sitesym).isResourceVariable() &&
2273 sym.kind == MTH && 2276 sym.kind == MTH &&
2274 sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true) && 2277 sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true) &&
2275 env.info.lint.isEnabled(Lint.LintCategory.TRY)) { 2278 env.info.lint.isEnabled(LintCategory.TRY)) {
2276 log.warning(Lint.LintCategory.TRY, tree, "try.explicit.close.call"); 2279 log.warning(LintCategory.TRY, tree, "try.explicit.close.call");
2277 } 2280 }
2278 2281
2279 // Disallow selecting a type from an expression 2282 // Disallow selecting a type from an expression
2280 if (isType(sym) && (sitesym==null || (sitesym.kind&(TYP|PCK)) == 0)) { 2283 if (isType(sym) && (sitesym==null || (sitesym.kind&(TYP|PCK)) == 0)) {
2281 tree.type = check(tree.selected, pt, 2284 tree.type = check(tree.selected, pt,
2698 2701
2699 // Compute the identifier's instantiated type. 2702 // Compute the identifier's instantiated type.
2700 // For methods, we need to compute the instance type by 2703 // For methods, we need to compute the instance type by
2701 // Resolve.instantiate from the symbol's type as well as 2704 // Resolve.instantiate from the symbol's type as well as
2702 // any type arguments and value arguments. 2705 // any type arguments and value arguments.
2703 noteWarner.warned = false; 2706 noteWarner.clear();
2704 Type owntype = rs.instantiate(env, 2707 Type owntype = rs.instantiate(env,
2705 site, 2708 site,
2706 sym, 2709 sym,
2707 argtypes, 2710 argtypes,
2708 typeargtypes, 2711 typeargtypes,
2709 true, 2712 true,
2710 useVarargs, 2713 useVarargs,
2711 noteWarner); 2714 noteWarner);
2712 boolean warned = noteWarner.warned; 2715 boolean warned = noteWarner.hasNonSilentLint(LintCategory.UNCHECKED);
2713 2716
2714 // If this fails, something went wrong; we should not have 2717 // If this fails, something went wrong; we should not have
2715 // found the identifier in the first place. 2718 // found the identifier in the first place.
2716 if (owntype == null) { 2719 if (owntype == null) {
2717 if (!pt.isErroneous()) 2720 if (!pt.isErroneous())
2732 List<JCExpression> args = argtrees; 2735 List<JCExpression> args = argtrees;
2733 while (formals.head != last) { 2736 while (formals.head != last) {
2734 JCTree arg = args.head; 2737 JCTree arg = args.head;
2735 Warner warn = chk.convertWarner(arg.pos(), arg.type, formals.head); 2738 Warner warn = chk.convertWarner(arg.pos(), arg.type, formals.head);
2736 assertConvertible(arg, arg.type, formals.head, warn); 2739 assertConvertible(arg, arg.type, formals.head, warn);
2737 warned |= warn.warned; 2740 warned |= warn.hasNonSilentLint(LintCategory.UNCHECKED);
2738 args = args.tail; 2741 args = args.tail;
2739 formals = formals.tail; 2742 formals = formals.tail;
2740 } 2743 }
2741 if (useVarargs) { 2744 if (useVarargs) {
2742 Type varArg = types.elemtype(last); 2745 Type varArg = types.elemtype(last);
2743 while (args.tail != null) { 2746 while (args.tail != null) {
2744 JCTree arg = args.head; 2747 JCTree arg = args.head;
2745 Warner warn = chk.convertWarner(arg.pos(), arg.type, varArg); 2748 Warner warn = chk.convertWarner(arg.pos(), arg.type, varArg);
2746 assertConvertible(arg, arg.type, varArg, warn); 2749 assertConvertible(arg, arg.type, varArg, warn);
2747 warned |= warn.warned; 2750 warned |= warn.hasNonSilentLint(LintCategory.UNCHECKED);
2748 args = args.tail; 2751 args = args.tail;
2749 } 2752 }
2750 } else if ((sym.flags() & VARARGS) != 0 && allowVarargs) { 2753 } else if ((sym.flags() & VARARGS) != 0 && allowVarargs) {
2751 // non-varargs call to varargs method 2754 // non-varargs call to varargs method
2752 Type varParam = owntype.getParameterTypes().last(); 2755 Type varParam = owntype.getParameterTypes().last();
2774 } 2777 }
2775 if (useVarargs) { 2778 if (useVarargs) {
2776 JCTree tree = env.tree; 2779 JCTree tree = env.tree;
2777 Type argtype = owntype.getParameterTypes().last(); 2780 Type argtype = owntype.getParameterTypes().last();
2778 if (owntype.getReturnType().tag != FORALL || warned) { 2781 if (owntype.getReturnType().tag != FORALL || warned) {
2779 chk.checkVararg(env.tree.pos(), owntype.getParameterTypes(), sym, env); 2782 chk.checkVararg(env.tree.pos(), owntype.getParameterTypes(), sym);
2780 } 2783 }
2781 Type elemtype = types.elemtype(argtype); 2784 Type elemtype = types.elemtype(argtype);
2782 switch (tree.getTag()) { 2785 switch (tree.getTag()) {
2783 case JCTree.APPLY: 2786 case JCTree.APPLY:
2784 ((JCMethodInvocation) tree).varargsElement = elemtype; 2787 ((JCMethodInvocation) tree).varargsElement = elemtype;
3173 3176
3174 // Check for cycles among annotation elements. 3177 // Check for cycles among annotation elements.
3175 chk.checkNonCyclicElements(tree); 3178 chk.checkNonCyclicElements(tree);
3176 3179
3177 // Check for proper use of serialVersionUID 3180 // Check for proper use of serialVersionUID
3178 if (env.info.lint.isEnabled(Lint.LintCategory.SERIAL) && 3181 if (env.info.lint.isEnabled(LintCategory.SERIAL) &&
3179 isSerializable(c) && 3182 isSerializable(c) &&
3180 (c.flags() & Flags.ENUM) == 0 && 3183 (c.flags() & Flags.ENUM) == 0 &&
3181 (c.flags() & ABSTRACT) == 0) { 3184 (c.flags() & ABSTRACT) == 0) {
3182 checkSerialVersionUID(tree, c); 3185 checkSerialVersionUID(tree, c);
3183 } 3186 }
3202 3205
3203 // check for presence of serialVersionUID 3206 // check for presence of serialVersionUID
3204 Scope.Entry e = c.members().lookup(names.serialVersionUID); 3207 Scope.Entry e = c.members().lookup(names.serialVersionUID);
3205 while (e.scope != null && e.sym.kind != VAR) e = e.next(); 3208 while (e.scope != null && e.sym.kind != VAR) e = e.next();
3206 if (e.scope == null) { 3209 if (e.scope == null) {
3207 log.warning(Lint.LintCategory.SERIAL, 3210 log.warning(LintCategory.SERIAL,
3208 tree.pos(), "missing.SVUID", c); 3211 tree.pos(), "missing.SVUID", c);
3209 return; 3212 return;
3210 } 3213 }
3211 3214
3212 // check that it is static final 3215 // check that it is static final
3213 VarSymbol svuid = (VarSymbol)e.sym; 3216 VarSymbol svuid = (VarSymbol)e.sym;
3214 if ((svuid.flags() & (STATIC | FINAL)) != 3217 if ((svuid.flags() & (STATIC | FINAL)) !=
3215 (STATIC | FINAL)) 3218 (STATIC | FINAL))
3216 log.warning(Lint.LintCategory.SERIAL, 3219 log.warning(LintCategory.SERIAL,
3217 TreeInfo.diagnosticPositionFor(svuid, tree), "improper.SVUID", c); 3220 TreeInfo.diagnosticPositionFor(svuid, tree), "improper.SVUID", c);
3218 3221
3219 // check that it is long 3222 // check that it is long
3220 else if (svuid.type.tag != TypeTags.LONG) 3223 else if (svuid.type.tag != TypeTags.LONG)
3221 log.warning(Lint.LintCategory.SERIAL, 3224 log.warning(LintCategory.SERIAL,
3222 TreeInfo.diagnosticPositionFor(svuid, tree), "long.SVUID", c); 3225 TreeInfo.diagnosticPositionFor(svuid, tree), "long.SVUID", c);
3223 3226
3224 // check constant 3227 // check constant
3225 else if (svuid.getConstValue() == null) 3228 else if (svuid.getConstValue() == null)
3226 log.warning(Lint.LintCategory.SERIAL, 3229 log.warning(LintCategory.SERIAL,
3227 TreeInfo.diagnosticPositionFor(svuid, tree), "constant.SVUID", c); 3230 TreeInfo.diagnosticPositionFor(svuid, tree), "constant.SVUID", c);
3228 } 3231 }
3229 3232
3230 private Type capture(Type type) { 3233 private Type capture(Type type) {
3231 return types.capture(type); 3234 return types.capture(type);

mercurial