if ((pkind & TYP) != 0) skind = skind | TYP | PCK;
if ((pkind & (VAL | MTH)) != 0) skind = skind | VAL | TYP;
}
// Attribute the qualifier expression, and determine its symbol (if any).
Type site = attribTree(tree.selected, env, skind, Infer.anyPoly);
if ((pkind & (PCK | TYP)) == 0)
site = capture(site); // Capture field access
// don't allow T.class T[].class, etc
if (skind == TYP) {
Type elt = site;
while (elt.tag == ARRAY)
elt = ((ArrayType)elt).elemtype;
if (elt.tag == TYPEVAR) {
log.error(tree.pos(), "type.var.cant.be.deref");
result = types.createErrorType(tree.type);
return;
}
}
// If qualifier symbol is a type or `super', assert `selectSuper'
// for the selection. This is relevant for determining whether
// protected symbols are accessible.
Symbol sitesym = TreeInfo.symbol(tree.selected);
boolean selectSuperPrev = env.info.selectSuper;
env.info.selectSuper =
sitesym != null &&
sitesym.name == names._super;
// If selected expression is polymorphic, strip
// type parameters and remember in env.info.tvars, so that
// they can be added later (in Attr.checkId and Infer.instantiateMethod).
if (tree.selected.type.tag == FORALL) {
ForAll pstype = (ForAll)tree.selected.type;
env.info.tvars = pstype.tvars;
site = tree.selected.type = pstype.qtype;
}
// Determine the symbol represented by the selection.
env.info.varArgs = false;
Symbol sym = selectSym(tree, sitesym, site, env, pt, pkind);
if (sym.exists() && !isType(sym) && (pkind & (PCK | TYP)) != 0) {
site = capture(site);
sym = selectSym(tree, sitesym, site, env, pt, pkind);
}
boolean varArgs = env.info.varArgs;
tree.sym = sym;
if (site.tag == TYPEVAR && !isType(sym) && sym.kind != ERR) {
while (site.tag == TYPEVAR) site = site.getUpperBound();
site = capture(site);
}
// If that symbol is a variable, ...
if (sym.kind == VAR) {
VarSymbol v = (VarSymbol)sym;
// ..., evaluate its initializer, if it has one, and check for
// illegal forward reference.
checkInit(tree, env, v, true);
// If we are expecting a variable (as opposed to a value), check
// that the variable is assignable in the current environment.
if (pkind == VAR)
checkAssignable(tree.pos(), v, tree.selected, env);
}
if (sitesym != null &&
sitesym.kind == VAR &&
((VarSymbol)sitesym).isResourceVariable() &&
sym.kind == MTH &&
sym.name.equals(names.close) &&
sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true) &&
env.info.lint.isEnabled(LintCategory.TRY)) {
log.warning(LintCategory.TRY, tree, "try.explicit.close.call");
}
// Disallow selecting a type from an expression
if (isType(sym) && (sitesym==null || (sitesym.kind&(TYP|PCK)) == 0)) {
tree.type = check(tree.selected, pt,
sitesym == null ? VAL : sitesym.kind, TYP|PCK, pt);
}
if (isType(sitesym)) {
if (sym.name == names._this) {
// If `C' is the currently compiled class, check that
// C.this' does not appear in a call to a super(...)
if (env.info.isSelfCall &&
site.tsym == env.enclClass.sym) {
chk.earlyRefError(tree.pos(), sym);
}
} else {
// Check if type-qualified fields or methods are static (JLS)
if ((sym.flags() & STATIC) == 0 &&
sym.name != names._super &&
(sym.kind == VAR || sym.kind == MTH)) {
rs.access(rs.new StaticError(sym),
tree.pos(), site, sym.name, true);
}
}
} else if (sym.kind != ERR && (sym.flags() & STATIC) != 0 && sym.name != names._class) {
// If the qualified item is not a type and the selected item is static, report
// a warning. Make allowance for the class of an array type e.g. Object[].class)
chk.warnStatic(tree, "static.not.qualified.by.type", Kinds.kindName(sym.kind), sym.owner);
}
// If we are selecting an instance member via a `super', ...
if (env.info.selectSuper && (sym.flags() & STATIC) == 0) {
// Check that super-qualified symbols are not abstract (JLS)
rs.checkNonAbstract(tree.pos(), sym);
if (site.isRaw()) {
// Determine argument types for site.
Type site1 = types.asSuper(env.enclClass.sym.type, site.tsym);
if (site1 != null) site = site1;
}
}
env.info.selectSuper = selectSuperPrev;