32 import com.sun.tools.javac.jvm.*;
33 import com.sun.tools.javac.tree.*;
34 import com.sun.tools.javac.tree.JCTree.*;
35 import com.sun.tools.javac.util.*;
36 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
37 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
38 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
39
40 import java.util.Arrays;
41 import java.util.Collection;
42 import java.util.EnumSet;
43 import java.util.HashMap;
44 import java.util.HashSet;
45 import java.util.LinkedHashMap;
46 import java.util.Map;
47 import java.util.Set;
48
49 import javax.lang.model.element.ElementVisitor;
50
51 import static com.sun.tools.javac.code.Flags.*;
52 import static com.sun.tools.javac.code.Kinds.*;
53 import static com.sun.tools.javac.code.TypeTags.*;
54 import static com.sun.tools.javac.comp.Resolve.MethodResolutionPhase.*;
55
56 /** Helper class for name resolution, used mostly by the attribution phase.
57 *
58 * <p><b>This is NOT part of any supported API.
59 * If you write code that depends on this, you do so at your own risk.
60 * This code and its internal interfaces are subject to change or
61 * deletion without notice.</b>
62 */
63 public class Resolve {
64 protected static final Context.Key<Resolve> resolveKey =
65 new Context.Key<Resolve>();
66
67 Names names;
68 Log log;
69 Symtab syms;
70 Check chk;
71 Infer infer;
72 ClassReader reader;
73 TreeInfo treeinfo;
74 Types types;
1252 return e.sym;
1253 }
1254 }
1255
1256 sym = findMemberType(env1, env1.enclClass.sym.type, name,
1257 env1.enclClass.sym);
1258 if (staticOnly && sym.kind == TYP &&
1259 sym.type.tag == CLASS &&
1260 sym.type.getEnclosingType().tag == CLASS &&
1261 env1.enclClass.sym.type.isParameterized() &&
1262 sym.type.getEnclosingType().isParameterized())
1263 return new StaticError(sym);
1264 else if (sym.exists()) return sym;
1265 else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
1266
1267 JCClassDecl encl = env1.baseClause ? (JCClassDecl)env1.tree : env1.enclClass;
1268 if ((encl.sym.flags() & STATIC) != 0)
1269 staticOnly = true;
1270 }
1271
1272 if (env.tree.getTag() != JCTree.IMPORT) {
1273 sym = findGlobalType(env, env.toplevel.namedImportScope, name);
1274 if (sym.exists()) return sym;
1275 else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
1276
1277 sym = findGlobalType(env, env.toplevel.packge.members(), name);
1278 if (sym.exists()) return sym;
1279 else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
1280
1281 sym = findGlobalType(env, env.toplevel.starImportScope, name);
1282 if (sym.exists()) return sym;
1283 else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
1284 }
1285
1286 return bestSoFar;
1287 }
1288
1289 /** Find an unqualified identifier which matches a specified kind set.
1290 * @param env The current environment.
1291 * @param name The indentifier's name.
1292 * @param kind Indicates the possible symbol kinds
1779 * @param argtypes The types of the invocation's value arguments.
1780 * @param typeargtypes The types of the invocation's type arguments.
1781 */
1782 public MethodSymbol resolveInternalConstructor(DiagnosticPosition pos, Env<AttrContext> env,
1783 Type site,
1784 List<Type> argtypes,
1785 List<Type> typeargtypes) {
1786 Symbol sym = resolveConstructor(
1787 pos, env, site, argtypes, typeargtypes);
1788 if (sym.kind == MTH) return (MethodSymbol)sym;
1789 else throw new FatalError(
1790 diags.fragment("fatal.err.cant.locate.ctor", site));
1791 }
1792
1793 /** Resolve operator.
1794 * @param pos The position to use for error reporting.
1795 * @param optag The tag of the operation tree.
1796 * @param env The environment current at the operation.
1797 * @param argtypes The types of the operands.
1798 */
1799 Symbol resolveOperator(DiagnosticPosition pos, int optag,
1800 Env<AttrContext> env, List<Type> argtypes) {
1801 startResolution();
1802 Name name = treeinfo.operatorName(optag);
1803 Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes,
1804 null, false, false, true);
1805 if (boxingEnabled && sym.kind >= WRONG_MTHS)
1806 sym = findMethod(env, syms.predefClass.type, name, argtypes,
1807 null, true, false, true);
1808 return access(sym, pos, env.enclClass.sym.type, name,
1809 false, argtypes, null);
1810 }
1811
1812 /** Resolve operator.
1813 * @param pos The position to use for error reporting.
1814 * @param optag The tag of the operation tree.
1815 * @param env The environment current at the operation.
1816 * @param arg The type of the operand.
1817 */
1818 Symbol resolveUnaryOperator(DiagnosticPosition pos, int optag, Env<AttrContext> env, Type arg) {
1819 return resolveOperator(pos, optag, env, List.of(arg));
1820 }
1821
1822 /** Resolve binary operator.
1823 * @param pos The position to use for error reporting.
1824 * @param optag The tag of the operation tree.
1825 * @param env The environment current at the operation.
1826 * @param left The types of the left operand.
1827 * @param right The types of the right operand.
1828 */
1829 Symbol resolveBinaryOperator(DiagnosticPosition pos,
1830 int optag,
1831 Env<AttrContext> env,
1832 Type left,
1833 Type right) {
1834 return resolveOperator(pos, optag, env, List.of(left, right));
1835 }
1836
1837 /**
1838 * Resolve `c.name' where name == this or name == super.
1839 * @param pos The position to use for error reporting.
1840 * @param env The environment current at the expression.
1841 * @param c The qualifier.
1842 * @param name The identifier's name.
1843 */
1844 Symbol resolveSelf(DiagnosticPosition pos,
1845 Env<AttrContext> env,
1846 TypeSymbol c,
1847 Name name) {
1848 Env<AttrContext> env1 = env;
1849 boolean staticOnly = false;
1850 while (env1.outer != null) {
|
32 import com.sun.tools.javac.jvm.*;
33 import com.sun.tools.javac.tree.*;
34 import com.sun.tools.javac.tree.JCTree.*;
35 import com.sun.tools.javac.util.*;
36 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
37 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
38 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
39
40 import java.util.Arrays;
41 import java.util.Collection;
42 import java.util.EnumSet;
43 import java.util.HashMap;
44 import java.util.HashSet;
45 import java.util.LinkedHashMap;
46 import java.util.Map;
47 import java.util.Set;
48
49 import javax.lang.model.element.ElementVisitor;
50
51 import static com.sun.tools.javac.code.Flags.*;
52 import static com.sun.tools.javac.code.Flags.BLOCK;
53 import static com.sun.tools.javac.code.Kinds.*;
54 import static com.sun.tools.javac.code.Kinds.ERRONEOUS;
55 import static com.sun.tools.javac.code.TypeTags.*;
56 import static com.sun.tools.javac.comp.Resolve.MethodResolutionPhase.*;
57 import static com.sun.tools.javac.tree.JCTree.Tag.*;
58
59 /** Helper class for name resolution, used mostly by the attribution phase.
60 *
61 * <p><b>This is NOT part of any supported API.
62 * If you write code that depends on this, you do so at your own risk.
63 * This code and its internal interfaces are subject to change or
64 * deletion without notice.</b>
65 */
66 public class Resolve {
67 protected static final Context.Key<Resolve> resolveKey =
68 new Context.Key<Resolve>();
69
70 Names names;
71 Log log;
72 Symtab syms;
73 Check chk;
74 Infer infer;
75 ClassReader reader;
76 TreeInfo treeinfo;
77 Types types;
1255 return e.sym;
1256 }
1257 }
1258
1259 sym = findMemberType(env1, env1.enclClass.sym.type, name,
1260 env1.enclClass.sym);
1261 if (staticOnly && sym.kind == TYP &&
1262 sym.type.tag == CLASS &&
1263 sym.type.getEnclosingType().tag == CLASS &&
1264 env1.enclClass.sym.type.isParameterized() &&
1265 sym.type.getEnclosingType().isParameterized())
1266 return new StaticError(sym);
1267 else if (sym.exists()) return sym;
1268 else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
1269
1270 JCClassDecl encl = env1.baseClause ? (JCClassDecl)env1.tree : env1.enclClass;
1271 if ((encl.sym.flags() & STATIC) != 0)
1272 staticOnly = true;
1273 }
1274
1275 if (!env.tree.hasTag(IMPORT)) {
1276 sym = findGlobalType(env, env.toplevel.namedImportScope, name);
1277 if (sym.exists()) return sym;
1278 else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
1279
1280 sym = findGlobalType(env, env.toplevel.packge.members(), name);
1281 if (sym.exists()) return sym;
1282 else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
1283
1284 sym = findGlobalType(env, env.toplevel.starImportScope, name);
1285 if (sym.exists()) return sym;
1286 else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
1287 }
1288
1289 return bestSoFar;
1290 }
1291
1292 /** Find an unqualified identifier which matches a specified kind set.
1293 * @param env The current environment.
1294 * @param name The indentifier's name.
1295 * @param kind Indicates the possible symbol kinds
1782 * @param argtypes The types of the invocation's value arguments.
1783 * @param typeargtypes The types of the invocation's type arguments.
1784 */
1785 public MethodSymbol resolveInternalConstructor(DiagnosticPosition pos, Env<AttrContext> env,
1786 Type site,
1787 List<Type> argtypes,
1788 List<Type> typeargtypes) {
1789 Symbol sym = resolveConstructor(
1790 pos, env, site, argtypes, typeargtypes);
1791 if (sym.kind == MTH) return (MethodSymbol)sym;
1792 else throw new FatalError(
1793 diags.fragment("fatal.err.cant.locate.ctor", site));
1794 }
1795
1796 /** Resolve operator.
1797 * @param pos The position to use for error reporting.
1798 * @param optag The tag of the operation tree.
1799 * @param env The environment current at the operation.
1800 * @param argtypes The types of the operands.
1801 */
1802 Symbol resolveOperator(DiagnosticPosition pos, JCTree.Tag optag,
1803 Env<AttrContext> env, List<Type> argtypes) {
1804 startResolution();
1805 Name name = treeinfo.operatorName(optag);
1806 Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes,
1807 null, false, false, true);
1808 if (boxingEnabled && sym.kind >= WRONG_MTHS)
1809 sym = findMethod(env, syms.predefClass.type, name, argtypes,
1810 null, true, false, true);
1811 return access(sym, pos, env.enclClass.sym.type, name,
1812 false, argtypes, null);
1813 }
1814
1815 /** Resolve operator.
1816 * @param pos The position to use for error reporting.
1817 * @param optag The tag of the operation tree.
1818 * @param env The environment current at the operation.
1819 * @param arg The type of the operand.
1820 */
1821 Symbol resolveUnaryOperator(DiagnosticPosition pos, JCTree.Tag optag, Env<AttrContext> env, Type arg) {
1822 return resolveOperator(pos, optag, env, List.of(arg));
1823 }
1824
1825 /** Resolve binary operator.
1826 * @param pos The position to use for error reporting.
1827 * @param optag The tag of the operation tree.
1828 * @param env The environment current at the operation.
1829 * @param left The types of the left operand.
1830 * @param right The types of the right operand.
1831 */
1832 Symbol resolveBinaryOperator(DiagnosticPosition pos,
1833 JCTree.Tag optag,
1834 Env<AttrContext> env,
1835 Type left,
1836 Type right) {
1837 return resolveOperator(pos, optag, env, List.of(left, right));
1838 }
1839
1840 /**
1841 * Resolve `c.name' where name == this or name == super.
1842 * @param pos The position to use for error reporting.
1843 * @param env The environment current at the expression.
1844 * @param c The qualifier.
1845 * @param name The identifier's name.
1846 */
1847 Symbol resolveSelf(DiagnosticPosition pos,
1848 Env<AttrContext> env,
1849 TypeSymbol c,
1850 Name name) {
1851 Env<AttrContext> env1 = env;
1852 boolean staticOnly = false;
1853 while (env1.outer != null) {
|