8266281: Assign Symbols to the package selector expression

Reviewed-by: vromero
This commit is contained in:
Jan Lahoda 2021-06-02 11:16:10 +00:00
parent a223189b06
commit 19450b9951
5 changed files with 35 additions and 9 deletions

View File

@ -326,6 +326,7 @@ public class Enter extends JCTree.Visitor {
JCPackageDecl pd = tree.getPackage();
if (pd != null) {
tree.packge = pd.packge = syms.enterPackage(tree.modle, TreeInfo.fullName(pd.pid));
setPackageSymbols.scan(pd);
if ( pd.annotations.nonEmpty()
|| pkginfoOpt == PkgInfo.ALWAYS
|| tree.docComments != null) {
@ -389,6 +390,31 @@ public class Enter extends JCTree.Visitor {
log.useSource(prev);
result = null;
}
//where:
//set package Symbols to the package expression:
private final TreeScanner setPackageSymbols = new TreeScanner() {
Symbol currentPackage;
@Override
public void visitIdent(JCIdent tree) {
tree.sym = currentPackage;
tree.type = currentPackage.type;
}
@Override
public void visitSelect(JCFieldAccess tree) {
tree.sym = currentPackage;
tree.type = currentPackage.type;
currentPackage = currentPackage.owner;
super.visitSelect(tree);
}
@Override
public void visitPackageDef(JCPackageDecl tree) {
currentPackage = tree.packge;
scan(tree.pid);
}
};
@Override
public void visitClassDef(JCClassDecl tree) {

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 8012929 8243074
* @bug 8012929 8243074 8266281
* @summary Trees.getElement should work not only for declaration trees, but also for use-trees
* @modules jdk.compiler
* @build TestGetElementReference

View File

@ -21,10 +21,10 @@
* questions.
*/
package test;
/*getElement:PACKAGE:test*/
package test/*getElement:PACKAGE:test*/.nested/*getElement:PACKAGE:test.nested*/;
/*getElement:PACKAGE:test.nested*/
import java.lang.annotation.*;
import static test.TestGetElementReferenceData.Sub.*;
import static test.nested.TestGetElementReferenceData.Sub.*;
public class TestGetElementReferenceData {
@ -33,8 +33,8 @@ public class TestGetElementReferenceData {
sb/*getElement:LOCAL_VARIABLE:sb*/.append/*getElement:METHOD:java.lang.StringBuilder.append(int)*/(0);
sb.reverse( /*getElement:METHOD:java.lang.StringBuilder.reverse()*/);
java.util.List< /*getElement:INTERFACE:java.util.List*/ String> l;
utility/*getElement:METHOD:test.TestGetElementReferenceData.Base.utility()*/();
target(TestGetElementReferenceData :: test/*getElement:METHOD:test.TestGetElementReferenceData.test()*/);
utility/*getElement:METHOD:test.nested.TestGetElementReferenceData.Base.utility()*/();
target(TestGetElementReferenceData :: test/*getElement:METHOD:test.nested.TestGetElementReferenceData.test()*/);
Object/*getElement:CLASS:java.lang.Object*/ o = null;
if (o/*getElement:LOCAL_VARIABLE:o*/ instanceof String/*getElement:CLASS:java.lang.String*/ str/*getElement:BINDING_VARIABLE:str*/) ;
}
@ -42,7 +42,7 @@ public class TestGetElementReferenceData {
public static class Base {
public static void utility() {}
}
public static class Sub extends @TypeAnnotation( /*getElement:ANNOTATION_TYPE:test.TestGetElementReferenceData.TypeAnnotation*/) Base {
public static class Sub extends @TypeAnnotation( /*getElement:ANNOTATION_TYPE:test.nested.TestGetElementReferenceData.TypeAnnotation*/) Base {
}
@Deprecated( /*getElement:ANNOTATION_TYPE:java.lang.Deprecated*/)
public static class TypeParam<TT/*getElement:TYPE_PARAMETER:TT*/> {

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 8240658
* @bug 8240658 8266281
* @summary Verify that broken method invocations with lambdas get type inference done
* @modules jdk.compiler
* @compile --enable-preview -source ${jdk.version} TestGetTypeMirrorReference.java

View File

@ -21,7 +21,7 @@
* questions.
*/
package test;
package test/*getTypeMirror:PACKAGE:test*/;
public class TestGetTypeMirrorReferenceData {