提交 00dab6cc 编写于 作者: E emc

7118412: Shadowing of type-variables vs. member types

4987840: What is the scope of an annotation?
Summary: Fixed issue with shadowing of type names.
Reviewed-by: jjg, abuckley, mcimadamore
上级 ee93ddcf
...@@ -1859,7 +1859,10 @@ public class Resolve { ...@@ -1859,7 +1859,10 @@ public class Resolve {
} }
} }
/** Find qualified member type.
/**
* Find a type declared in a scope (not inherited). Return null
* if none is found.
* @param env The current environment. * @param env The current environment.
* @param site The original type from where the selection takes * @param site The original type from where the selection takes
* place. * place.
...@@ -1868,12 +1871,10 @@ public class Resolve { ...@@ -1868,12 +1871,10 @@ public class Resolve {
* always a superclass or implemented interface of * always a superclass or implemented interface of
* site's class. * site's class.
*/ */
Symbol findMemberType(Env<AttrContext> env, Symbol findImmediateMemberType(Env<AttrContext> env,
Type site, Type site,
Name name, Name name,
TypeSymbol c) { TypeSymbol c) {
Symbol bestSoFar = typeNotFound;
Symbol sym;
Scope.Entry e = c.members().lookup(name); Scope.Entry e = c.members().lookup(name);
while (e.scope != null) { while (e.scope != null) {
if (e.sym.kind == TYP) { if (e.sym.kind == TYP) {
...@@ -1883,6 +1884,24 @@ public class Resolve { ...@@ -1883,6 +1884,24 @@ public class Resolve {
} }
e = e.next(); e = e.next();
} }
return typeNotFound;
}
/** Find a member type inherited from a superclass or interface.
* @param env The current environment.
* @param site The original type from where the selection takes
* place.
* @param name The type's name.
* @param c The class to search for the member type. This is
* always a superclass or implemented interface of
* site's class.
*/
Symbol findInheritedMemberType(Env<AttrContext> env,
Type site,
Name name,
TypeSymbol c) {
Symbol bestSoFar = typeNotFound;
Symbol sym;
Type st = types.supertype(c.type); Type st = types.supertype(c.type);
if (st != null && st.hasTag(CLASS)) { if (st != null && st.hasTag(CLASS)) {
sym = findMemberType(env, site, name, st.tsym); sym = findMemberType(env, site, name, st.tsym);
...@@ -1901,6 +1920,28 @@ public class Resolve { ...@@ -1901,6 +1920,28 @@ public class Resolve {
return bestSoFar; return bestSoFar;
} }
/** Find qualified member type.
* @param env The current environment.
* @param site The original type from where the selection takes
* place.
* @param name The type's name.
* @param c The class to search for the member type. This is
* always a superclass or implemented interface of
* site's class.
*/
Symbol findMemberType(Env<AttrContext> env,
Type site,
Name name,
TypeSymbol c) {
Symbol sym = findImmediateMemberType(env, site, name, c);
if (sym != typeNotFound)
return sym;
return findInheritedMemberType(env, site, name, c);
}
/** Find a global type in given scope and load corresponding class. /** Find a global type in given scope and load corresponding class.
* @param env The current environment. * @param env The current environment.
* @param scope The scope in which to look for the type. * @param scope The scope in which to look for the type.
...@@ -1919,6 +1960,21 @@ public class Resolve { ...@@ -1919,6 +1960,21 @@ public class Resolve {
return bestSoFar; return bestSoFar;
} }
Symbol findTypeVar(Env<AttrContext> env, Name name, boolean staticOnly) {
for (Scope.Entry e = env.info.scope.lookup(name);
e.scope != null;
e = e.next()) {
if (e.sym.kind == TYP) {
if (staticOnly &&
e.sym.type.hasTag(TYPEVAR) &&
e.sym.owner.kind == TYP)
return new StaticError(e.sym);
return e.sym;
}
}
return typeNotFound;
}
/** Find an unqualified type symbol. /** Find an unqualified type symbol.
* @param env The current environment. * @param env The current environment.
* @param name The type's name. * @param name The type's name.
...@@ -1929,19 +1985,26 @@ public class Resolve { ...@@ -1929,19 +1985,26 @@ public class Resolve {
boolean staticOnly = false; boolean staticOnly = false;
for (Env<AttrContext> env1 = env; env1.outer != null; env1 = env1.outer) { for (Env<AttrContext> env1 = env; env1.outer != null; env1 = env1.outer) {
if (isStatic(env1)) staticOnly = true; if (isStatic(env1)) staticOnly = true;
for (Scope.Entry e = env1.info.scope.lookup(name); // First, look for a type variable and the first member type
e.scope != null; final Symbol tyvar = findTypeVar(env1, name, staticOnly);
e = e.next()) { sym = findImmediateMemberType(env1, env1.enclClass.sym.type,
if (e.sym.kind == TYP) { name, env1.enclClass.sym);
if (staticOnly &&
e.sym.type.hasTag(TYPEVAR) && // Return the type variable if we have it, and have no
e.sym.owner.kind == TYP) return new StaticError(e.sym); // immediate member, OR the type variable is for a method.
return e.sym; if (tyvar != typeNotFound) {
} if (sym == typeNotFound ||
(tyvar.kind == TYP && tyvar.exists() &&
tyvar.owner.kind == MTH))
return tyvar;
} }
sym = findMemberType(env1, env1.enclClass.sym.type, name, // If the environment is a class def, finish up,
env1.enclClass.sym); // otherwise, do the entire findMemberType
if (sym == typeNotFound)
sym = findInheritedMemberType(env1, env1.enclClass.sym.type,
name, env1.enclClass.sym);
if (staticOnly && sym.kind == TYP && if (staticOnly && sym.kind == TYP &&
sym.type.hasTag(CLASS) && sym.type.hasTag(CLASS) &&
sym.type.getEnclosingType().hasTag(CLASS) && sym.type.getEnclosingType().hasTag(CLASS) &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册