7033677: potential cast error in MemberEnter
Reviewed-by: vromero, jlahoda
This commit is contained in:
parent
6120319afd
commit
a917fb3fcf
src/jdk.compiler/share/classes/com/sun/tools/javac
comp
parser
tree
test/langtools/jdk/javadoc/tool/sampleapi/lib/sampleapi/generator
@ -393,7 +393,7 @@ public class Attr extends JCTree.Visitor {
|
||||
|
||||
public Type attribImportQualifier(JCImport tree, Env<AttrContext> env) {
|
||||
// Attribute qualifying package or class.
|
||||
JCFieldAccess s = (JCFieldAccess)tree.qualid;
|
||||
JCFieldAccess s = tree.qualid;
|
||||
return attribTree(s.selected, env,
|
||||
new ResultInfo(tree.staticImport ?
|
||||
KindSelector.TYP : KindSelector.TYP_PCK,
|
||||
|
@ -4068,7 +4068,7 @@ public class Check {
|
||||
for (final JCImport imp : toplevel.getImports()) {
|
||||
if (!imp.staticImport || !imp.qualid.hasTag(SELECT))
|
||||
continue;
|
||||
final JCFieldAccess select = (JCFieldAccess) imp.qualid;
|
||||
final JCFieldAccess select = imp.qualid;
|
||||
final Symbol origin;
|
||||
if (select.name == names.asterisk || (origin = TreeInfo.symbol(select.selected)) == null || origin.kind != TYP)
|
||||
continue;
|
||||
@ -4091,7 +4091,7 @@ public class Check {
|
||||
public void checkImportedPackagesObservable(final JCCompilationUnit toplevel) {
|
||||
OUTER: for (JCImport imp : toplevel.getImports()) {
|
||||
if (!imp.staticImport && TreeInfo.name(imp.qualid) == names.asterisk) {
|
||||
TypeSymbol tsym = ((JCFieldAccess)imp.qualid).selected.type.tsym;
|
||||
TypeSymbol tsym = imp.qualid.selected.type.tsym;
|
||||
if (tsym.kind == PCK && tsym.members().isEmpty() &&
|
||||
!(Feature.IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES.allowedInSource(source) && tsym.exists())) {
|
||||
log.error(DiagnosticFlag.RESOLVE_ERROR, imp.pos, Errors.DoesntExist(tsym));
|
||||
|
@ -353,7 +353,8 @@ public class TypeEnter implements Completer {
|
||||
log.error(Errors.NoJavaLang);
|
||||
throw new Abort();
|
||||
}
|
||||
importAll(make.at(tree.pos()).Import(make.QualIdent(javaLang), false), javaLang, env);
|
||||
importAll(make.at(tree.pos()).Import(make.Select(make.QualIdent(javaLang.owner), javaLang), false),
|
||||
javaLang, env);
|
||||
|
||||
JCModuleDecl decl = tree.getModuleDecl();
|
||||
|
||||
@ -406,7 +407,7 @@ public class TypeEnter implements Completer {
|
||||
}
|
||||
|
||||
private void doImport(JCImport tree) {
|
||||
JCFieldAccess imp = (JCFieldAccess)tree.qualid;
|
||||
JCFieldAccess imp = tree.qualid;
|
||||
Name name = TreeInfo.name(imp);
|
||||
|
||||
// Create a local environment pointing to this tree to disable
|
||||
|
@ -4020,7 +4020,7 @@ public class JavacParser implements Parser {
|
||||
}
|
||||
} while (token.kind == DOT);
|
||||
accept(SEMI);
|
||||
return toP(F.at(pos).Import(pid, importStatic));
|
||||
return toP(F.at(pos).Import((JCFieldAccess)pid, importStatic));
|
||||
}
|
||||
|
||||
/** TypeDeclaration = ClassOrInterfaceOrEnumDeclaration
|
||||
|
@ -667,9 +667,9 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
|
||||
public static class JCImport extends JCTree implements ImportTree {
|
||||
public boolean staticImport;
|
||||
/** The imported class(es). */
|
||||
public JCTree qualid;
|
||||
public JCFieldAccess qualid;
|
||||
public com.sun.tools.javac.code.Scope importScope;
|
||||
protected JCImport(JCTree qualid, boolean importStatic) {
|
||||
protected JCImport(JCFieldAccess qualid, boolean importStatic) {
|
||||
this.qualid = qualid;
|
||||
this.staticImport = importStatic;
|
||||
}
|
||||
@ -679,7 +679,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
|
||||
@DefinedBy(Api.COMPILER_TREE)
|
||||
public boolean isStatic() { return staticImport; }
|
||||
@DefinedBy(Api.COMPILER_TREE)
|
||||
public JCTree getQualifiedIdentifier() { return qualid; }
|
||||
public JCFieldAccess getQualifiedIdentifier() { return qualid; }
|
||||
|
||||
@DefinedBy(Api.COMPILER_TREE)
|
||||
public Kind getKind() { return Kind.IMPORT; }
|
||||
@ -3403,7 +3403,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
|
||||
JCCompilationUnit TopLevel(List<JCTree> defs);
|
||||
JCPackageDecl PackageDecl(List<JCAnnotation> annotations,
|
||||
JCExpression pid);
|
||||
JCImport Import(JCTree qualid, boolean staticImport);
|
||||
JCImport Import(JCFieldAccess qualid, boolean staticImport);
|
||||
JCClassDecl ClassDef(JCModifiers mods,
|
||||
Name name,
|
||||
List<JCTypeParameter> typarams,
|
||||
|
@ -257,7 +257,7 @@ public class TreeCopier<P> implements TreeVisitor<JCTree,P> {
|
||||
@DefinedBy(Api.COMPILER_TREE)
|
||||
public JCTree visitImport(ImportTree node, P p) {
|
||||
JCImport t = (JCImport) node;
|
||||
JCTree qualid = copy(t.qualid, p);
|
||||
JCFieldAccess qualid = copy(t.qualid, p);
|
||||
return M.at(t.pos).Import(qualid, t.staticImport);
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ public class TreeMaker implements JCTree.Factory {
|
||||
return tree;
|
||||
}
|
||||
|
||||
public JCImport Import(JCTree qualid, boolean importStatic) {
|
||||
public JCImport Import(JCFieldAccess qualid, boolean importStatic) {
|
||||
JCImport tree = new JCImport(qualid, importStatic);
|
||||
tree.pos = pos;
|
||||
return tree;
|
||||
@ -723,8 +723,8 @@ public class TreeMaker implements JCTree.Factory {
|
||||
/** Create a selection node from a qualifier tree and a symbol.
|
||||
* @param base The qualifier tree.
|
||||
*/
|
||||
public JCExpression Select(JCExpression base, Symbol sym) {
|
||||
return new JCFieldAccess(base, sym.name, sym).setPos(pos).setType(sym.type);
|
||||
public JCFieldAccess Select(JCExpression base, Symbol sym) {
|
||||
return (JCFieldAccess)new JCFieldAccess(base, sym.name, sym).setPos(pos).setType(sym.type);
|
||||
}
|
||||
|
||||
/** Create a qualified identifier from a symbol, adding enough qualifications
|
||||
|
@ -275,10 +275,15 @@ public class PackageGenerator {
|
||||
}
|
||||
break;
|
||||
case "import":
|
||||
imports.append(
|
||||
make.Import(
|
||||
make.Ident(names.fromString(element.getTextContent())),
|
||||
false));
|
||||
String[] idents = element.getTextContent().split("\\.");
|
||||
if (idents.length < 2)
|
||||
throw new IllegalStateException("Invalid import: " + element.getTextContent());
|
||||
JCFieldAccess select = make.Select(
|
||||
make.Ident(names.fromString(idents[0])), names.fromString(idents[1]));
|
||||
for (int j = 2; j < idents.length; j++)
|
||||
select = make.Select(select, names.fromString(idents[j]));
|
||||
imports.append(make.Import(select, false));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user