src/share/classes/com/sun/tools/javac/comp/Resolve.java
Print this page
*** 1782,1815 ****
} catch (CompletionFailure ex) {
return typeNotFound;
}
}
! /** 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 bestSoFar = typeNotFound;
- Symbol sym;
Scope.Entry e = c.members().lookup(name);
while (e.scope != null) {
if (e.sym.kind == TYP) {
return isAccessible(env, site, e.sym)
? e.sym
: new AccessError(env, site, e.sym);
}
e = e.next();
}
Type st = types.supertype(c.type);
if (st != null && st.hasTag(CLASS)) {
sym = findMemberType(env, site, name, st.tsym);
if (sym.kind < bestSoFar.kind) bestSoFar = sym;
}
--- 1782,1834 ----
} catch (CompletionFailure ex) {
return typeNotFound;
}
}
!
! /**
! * Find a type declared in a scope (not inherited). Return null
! * if none is found.
* @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 findImmediateMemberType(Env<AttrContext> env,
Type site,
Name name,
TypeSymbol c) {
Scope.Entry e = c.members().lookup(name);
while (e.scope != null) {
if (e.sym.kind == TYP) {
return isAccessible(env, site, e.sym)
? e.sym
: new AccessError(env, site, e.sym);
}
e = e.next();
}
+ return null;
+ }
+
+ /** 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);
if (st != null && st.hasTag(CLASS)) {
sym = findMemberType(env, site, name, st.tsym);
if (sym.kind < bestSoFar.kind) bestSoFar = sym;
}
*** 1824,1833 ****
--- 1843,1874 ----
bestSoFar = sym;
}
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 != null)
+ return sym;
+
+ return findInheritedMemberType(env, site, name, c);
+
+ }
+
/** Find a global type in given scope and load corresponding class.
* @param env The current environment.
* @param scope The scope in which to look for the type.
* @param name The type's name.
*/
*** 1851,1874 ****
Symbol findType(Env<AttrContext> env, Name name) {
Symbol bestSoFar = typeNotFound;
Symbol sym;
boolean staticOnly = false;
for (Env<AttrContext> env1 = env; env1.outer != null; env1 = env1.outer) {
if (isStatic(env1)) staticOnly = true;
for (Scope.Entry e = env1.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;
}
}
- sym = findMemberType(env1, env1.enclClass.sym.type, name,
- env1.enclClass.sym);
if (staticOnly && sym.kind == TYP &&
sym.type.hasTag(CLASS) &&
sym.type.getEnclosingType().hasTag(CLASS) &&
env1.enclClass.sym.type.isParameterized() &&
sym.type.getEnclosingType().isParameterized())
--- 1892,1922 ----
Symbol findType(Env<AttrContext> env, Name name) {
Symbol bestSoFar = typeNotFound;
Symbol sym;
boolean staticOnly = false;
for (Env<AttrContext> env1 = env; env1.outer != null; env1 = env1.outer) {
+ // First, try the members declared in the class
+ sym = findImmediateMemberType(env1, env1.enclClass.sym.type,
+ name, env1.enclClass.sym);
+ // Then try the type parameters
+ if (sym == null) {
if (isStatic(env1)) staticOnly = true;
for (Scope.Entry e = env1.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;
}
}
+ sym = findInheritedMemberType(env1, env1.enclClass.sym.type,
+ name, env1.enclClass.sym);
+ }
if (staticOnly && sym.kind == TYP &&
sym.type.hasTag(CLASS) &&
sym.type.getEnclosingType().hasTag(CLASS) &&
env1.enclClass.sym.type.isParameterized() &&
sym.type.getEnclosingType().isParameterized())