langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
equal
deleted
inserted
replaced
45 import java.util.LinkedHashSet; |
45 import java.util.LinkedHashSet; |
46 import java.util.Map; |
46 import java.util.Map; |
47 import java.util.Set; |
47 import java.util.Set; |
48 import java.util.WeakHashMap; |
48 import java.util.WeakHashMap; |
49 |
49 |
50 import static com.sun.tools.javac.code.Kinds.VAL; |
|
51 import static com.sun.tools.javac.code.TypeTag.*; |
50 import static com.sun.tools.javac.code.TypeTag.*; |
52 import static com.sun.tools.javac.tree.JCTree.Tag.*; |
51 import static com.sun.tools.javac.tree.JCTree.Tag.*; |
|
52 import static com.sun.tools.javac.code.Kinds.*; |
|
53 import static com.sun.tools.javac.code.Kinds.Kind.*; |
53 |
54 |
54 /** |
55 /** |
55 * This is an helper class that is used to perform deferred type-analysis. |
56 * This is an helper class that is used to perform deferred type-analysis. |
56 * Each time a poly expression occurs in argument position, javac attributes it |
57 * Each time a poly expression occurs in argument position, javac attributes it |
57 * with a temporary 'deferred type' that is checked (possibly multiple times) |
58 * with a temporary 'deferred type' that is checked (possibly multiple times) |
698 |
699 |
699 /* set pt to Type.noType to avoid generating any bound |
700 /* set pt to Type.noType to avoid generating any bound |
700 * which may happen if lambda's return type is an |
701 * which may happen if lambda's return type is an |
701 * inference variable |
702 * inference variable |
702 */ |
703 */ |
703 Attr.ResultInfo bodyResultInfo = attr.new ResultInfo(VAL, Type.noType); |
704 Attr.ResultInfo bodyResultInfo = attr.new ResultInfo(KindSelector.VAL, Type.noType); |
704 localEnv.info.returnResult = bodyResultInfo; |
705 localEnv.info.returnResult = bodyResultInfo; |
705 |
706 |
706 // discard any log output |
707 // discard any log output |
707 Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log); |
708 Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log); |
708 try { |
709 try { |
766 rs.resolveMemberReferenceByArity(localEnv, mref2, exprTree.type, |
767 rs.resolveMemberReferenceByArity(localEnv, mref2, exprTree.type, |
767 tree.name, argtypes.toList(), inferenceContext); |
768 tree.name, argtypes.toList(), inferenceContext); |
768 switch (lookupSym.kind) { |
769 switch (lookupSym.kind) { |
769 //note: as argtypes are erroneous types, type-errors must |
770 //note: as argtypes are erroneous types, type-errors must |
770 //have been caused by arity mismatch |
771 //have been caused by arity mismatch |
771 case Kinds.ABSENT_MTH: |
772 case ABSENT_MTH: |
772 case Kinds.WRONG_MTH: |
773 case WRONG_MTH: |
773 case Kinds.WRONG_MTHS: |
774 case WRONG_MTHS: |
774 case Kinds.WRONG_STATICNESS: |
775 case WRONG_STATICNESS: |
775 checkContext.report(tree, diags.fragment("incompatible.arg.types.in.mref")); |
776 checkContext.report(tree, diags.fragment("incompatible.arg.types.in.mref")); |
776 } |
777 } |
777 } |
778 } |
778 } |
779 } |
779 } |
780 } |
1183 mref2.expr = exprTree; |
1184 mref2.expr = exprTree; |
1184 Symbol res = |
1185 Symbol res = |
1185 rs.getMemberReference(tree, localEnv, mref2, |
1186 rs.getMemberReference(tree, localEnv, mref2, |
1186 exprTree.type, tree.name); |
1187 exprTree.type, tree.name); |
1187 tree.sym = res; |
1188 tree.sym = res; |
1188 if (res.kind >= Kinds.ERRONEOUS || |
1189 if (res.kind.isOverloadError() || |
1189 res.type.hasTag(FORALL) || |
1190 res.type.hasTag(FORALL) || |
1190 (res.flags() & Flags.VARARGS) != 0 || |
1191 (res.flags() & Flags.VARARGS) != 0 || |
1191 (TreeInfo.isStaticSelector(exprTree, tree.name.table.names) && |
1192 (TreeInfo.isStaticSelector(exprTree, tree.name.table.names) && |
1192 exprTree.type.isRaw())) { |
1193 exprTree.type.isRaw())) { |
1193 tree.overloadKind = JCMemberReference.OverloadKind.OVERLOADED; |
1194 tree.overloadKind = JCMemberReference.OverloadKind.OVERLOADED; |
1378 * reduced using MethodAnalyzer.reduce (using defaultValue as the first value over which |
1379 * reduced using MethodAnalyzer.reduce (using defaultValue as the first value over which |
1379 * the reduction runs). MethodAnalyzer.shouldStop can be used to stop the inspection early. |
1380 * the reduction runs). MethodAnalyzer.shouldStop can be used to stop the inspection early. |
1380 */ |
1381 */ |
1381 <E> E analyzeCandidateMethods(Symbol sym, E defaultValue, MethodAnalyzer<E> analyzer) { |
1382 <E> E analyzeCandidateMethods(Symbol sym, E defaultValue, MethodAnalyzer<E> analyzer) { |
1382 switch (sym.kind) { |
1383 switch (sym.kind) { |
1383 case Kinds.MTH: |
1384 case MTH: |
1384 return analyzer.process((MethodSymbol) sym); |
1385 return analyzer.process((MethodSymbol) sym); |
1385 case Kinds.AMBIGUOUS: |
1386 case AMBIGUOUS: |
1386 Resolve.AmbiguityError err = (Resolve.AmbiguityError)sym.baseSymbol(); |
1387 Resolve.AmbiguityError err = (Resolve.AmbiguityError)sym.baseSymbol(); |
1387 E res = defaultValue; |
1388 E res = defaultValue; |
1388 for (Symbol s : err.ambiguousSyms) { |
1389 for (Symbol s : err.ambiguousSyms) { |
1389 if (s.kind == Kinds.MTH) { |
1390 if (s.kind == MTH) { |
1390 res = analyzer.reduce(res, analyzer.process((MethodSymbol) s)); |
1391 res = analyzer.reduce(res, analyzer.process((MethodSymbol) s)); |
1391 if (analyzer.shouldStop(res)) |
1392 if (analyzer.shouldStop(res)) |
1392 return res; |
1393 return res; |
1393 } |
1394 } |
1394 } |
1395 } |