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

changeset 1970
2068190f8ac2
parent 1945
f7f271bd74a2
child 2000
4a6acc42c3a1
equal deleted inserted replaced
1969:7de231613e4a 1970:2068190f8ac2
1857 } catch (CompletionFailure ex) { 1857 } catch (CompletionFailure ex) {
1858 return typeNotFound; 1858 return typeNotFound;
1859 } 1859 }
1860 } 1860 }
1861 1861
1862 /** Find qualified member type. 1862
1863 /**
1864 * Find a type declared in a scope (not inherited). Return null
1865 * if none is found.
1863 * @param env The current environment. 1866 * @param env The current environment.
1864 * @param site The original type from where the selection takes 1867 * @param site The original type from where the selection takes
1865 * place. 1868 * place.
1866 * @param name The type's name. 1869 * @param name The type's name.
1867 * @param c The class to search for the member type. This is 1870 * @param c The class to search for the member type. This is
1868 * always a superclass or implemented interface of 1871 * always a superclass or implemented interface of
1869 * site's class. 1872 * site's class.
1870 */ 1873 */
1871 Symbol findMemberType(Env<AttrContext> env, 1874 Symbol findImmediateMemberType(Env<AttrContext> env,
1872 Type site, 1875 Type site,
1873 Name name, 1876 Name name,
1874 TypeSymbol c) { 1877 TypeSymbol c) {
1875 Symbol bestSoFar = typeNotFound;
1876 Symbol sym;
1877 Scope.Entry e = c.members().lookup(name); 1878 Scope.Entry e = c.members().lookup(name);
1878 while (e.scope != null) { 1879 while (e.scope != null) {
1879 if (e.sym.kind == TYP) { 1880 if (e.sym.kind == TYP) {
1880 return isAccessible(env, site, e.sym) 1881 return isAccessible(env, site, e.sym)
1881 ? e.sym 1882 ? e.sym
1882 : new AccessError(env, site, e.sym); 1883 : new AccessError(env, site, e.sym);
1883 } 1884 }
1884 e = e.next(); 1885 e = e.next();
1885 } 1886 }
1887 return typeNotFound;
1888 }
1889
1890 /** Find a member type inherited from a superclass or interface.
1891 * @param env The current environment.
1892 * @param site The original type from where the selection takes
1893 * place.
1894 * @param name The type's name.
1895 * @param c The class to search for the member type. This is
1896 * always a superclass or implemented interface of
1897 * site's class.
1898 */
1899 Symbol findInheritedMemberType(Env<AttrContext> env,
1900 Type site,
1901 Name name,
1902 TypeSymbol c) {
1903 Symbol bestSoFar = typeNotFound;
1904 Symbol sym;
1886 Type st = types.supertype(c.type); 1905 Type st = types.supertype(c.type);
1887 if (st != null && st.hasTag(CLASS)) { 1906 if (st != null && st.hasTag(CLASS)) {
1888 sym = findMemberType(env, site, name, st.tsym); 1907 sym = findMemberType(env, site, name, st.tsym);
1889 if (sym.kind < bestSoFar.kind) bestSoFar = sym; 1908 if (sym.kind < bestSoFar.kind) bestSoFar = sym;
1890 } 1909 }
1899 bestSoFar = sym; 1918 bestSoFar = sym;
1900 } 1919 }
1901 return bestSoFar; 1920 return bestSoFar;
1902 } 1921 }
1903 1922
1923 /** Find qualified member type.
1924 * @param env The current environment.
1925 * @param site The original type from where the selection takes
1926 * place.
1927 * @param name The type's name.
1928 * @param c The class to search for the member type. This is
1929 * always a superclass or implemented interface of
1930 * site's class.
1931 */
1932 Symbol findMemberType(Env<AttrContext> env,
1933 Type site,
1934 Name name,
1935 TypeSymbol c) {
1936 Symbol sym = findImmediateMemberType(env, site, name, c);
1937
1938 if (sym != typeNotFound)
1939 return sym;
1940
1941 return findInheritedMemberType(env, site, name, c);
1942
1943 }
1944
1904 /** Find a global type in given scope and load corresponding class. 1945 /** Find a global type in given scope and load corresponding class.
1905 * @param env The current environment. 1946 * @param env The current environment.
1906 * @param scope The scope in which to look for the type. 1947 * @param scope The scope in which to look for the type.
1907 * @param name The type's name. 1948 * @param name The type's name.
1908 */ 1949 */
1917 bestSoFar = sym; 1958 bestSoFar = sym;
1918 } 1959 }
1919 return bestSoFar; 1960 return bestSoFar;
1920 } 1961 }
1921 1962
1963 Symbol findTypeVar(Env<AttrContext> env, Name name, boolean staticOnly) {
1964 for (Scope.Entry e = env.info.scope.lookup(name);
1965 e.scope != null;
1966 e = e.next()) {
1967 if (e.sym.kind == TYP) {
1968 if (staticOnly &&
1969 e.sym.type.hasTag(TYPEVAR) &&
1970 e.sym.owner.kind == TYP)
1971 return new StaticError(e.sym);
1972 return e.sym;
1973 }
1974 }
1975 return typeNotFound;
1976 }
1977
1922 /** Find an unqualified type symbol. 1978 /** Find an unqualified type symbol.
1923 * @param env The current environment. 1979 * @param env The current environment.
1924 * @param name The type's name. 1980 * @param name The type's name.
1925 */ 1981 */
1926 Symbol findType(Env<AttrContext> env, Name name) { 1982 Symbol findType(Env<AttrContext> env, Name name) {
1927 Symbol bestSoFar = typeNotFound; 1983 Symbol bestSoFar = typeNotFound;
1928 Symbol sym; 1984 Symbol sym;
1929 boolean staticOnly = false; 1985 boolean staticOnly = false;
1930 for (Env<AttrContext> env1 = env; env1.outer != null; env1 = env1.outer) { 1986 for (Env<AttrContext> env1 = env; env1.outer != null; env1 = env1.outer) {
1931 if (isStatic(env1)) staticOnly = true; 1987 if (isStatic(env1)) staticOnly = true;
1932 for (Scope.Entry e = env1.info.scope.lookup(name); 1988 // First, look for a type variable and the first member type
1933 e.scope != null; 1989 final Symbol tyvar = findTypeVar(env1, name, staticOnly);
1934 e = e.next()) { 1990 sym = findImmediateMemberType(env1, env1.enclClass.sym.type,
1935 if (e.sym.kind == TYP) { 1991 name, env1.enclClass.sym);
1936 if (staticOnly && 1992
1937 e.sym.type.hasTag(TYPEVAR) && 1993 // Return the type variable if we have it, and have no
1938 e.sym.owner.kind == TYP) return new StaticError(e.sym); 1994 // immediate member, OR the type variable is for a method.
1939 return e.sym; 1995 if (tyvar != typeNotFound) {
1940 } 1996 if (sym == typeNotFound ||
1941 } 1997 (tyvar.kind == TYP && tyvar.exists() &&
1942 1998 tyvar.owner.kind == MTH))
1943 sym = findMemberType(env1, env1.enclClass.sym.type, name, 1999 return tyvar;
1944 env1.enclClass.sym); 2000 }
2001
2002 // If the environment is a class def, finish up,
2003 // otherwise, do the entire findMemberType
2004 if (sym == typeNotFound)
2005 sym = findInheritedMemberType(env1, env1.enclClass.sym.type,
2006 name, env1.enclClass.sym);
2007
1945 if (staticOnly && sym.kind == TYP && 2008 if (staticOnly && sym.kind == TYP &&
1946 sym.type.hasTag(CLASS) && 2009 sym.type.hasTag(CLASS) &&
1947 sym.type.getEnclosingType().hasTag(CLASS) && 2010 sym.type.getEnclosingType().hasTag(CLASS) &&
1948 env1.enclClass.sym.type.isParameterized() && 2011 env1.enclClass.sym.type.isParameterized() &&
1949 sym.type.getEnclosingType().isParameterized()) 2012 sym.type.getEnclosingType().isParameterized())

mercurial