Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[23] ECJ rejects 'module' as top level package in an import statement #2610

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2759,6 +2759,11 @@ protected boolean areRestrictedModuleKeywordsActive() {
return this.scanContext != null && this.scanContext != ScanContext.INACTIVE;
}
void updateScanContext(int token) {
if (this.scanContext == ScanContext.AFTER_IMPORT && !isInModuleDeclaration()) {
this.scanContext = ScanContext.INACTIVE; // end temporary use of scanContext to disambiguate module imports
return;
}

switch (token) {
case TerminalTokens.TokenNameSEMICOLON: // next could be a KEYWORD
case TerminalTokens.TokenNameRBRACE:
Expand Down Expand Up @@ -3536,10 +3541,14 @@ else if ((data[index] == 'o')
&& (data[++index] == 'p')
&& (data[++index] == 'o')
&& (data[++index] == 'r')
&& (data[++index] == 't'))
&& (data[++index] == 't')) {
// initialize scanContext, because we need disambiguation when the next token is 'module':
if (this.scanContext == null || this.scanContext == ScanContext.INACTIVE)
this.scanContext = ScanContext.EXPECTING_IDENTIFIER;
return TokenNameimport;
else
} else {
return TokenNameIdentifier;
}
case 9 :
if ((data[++index] == 'n')
&& (data[++index] == 't')
Expand Down Expand Up @@ -3596,8 +3605,7 @@ else if ((data[index] == 'o')
case 'm': //module
switch (length) {
case 6 :
if ((areRestrictedModuleKeywordsActive()
|| this.lookBack[1] == TokenNameimport) // JEP 467: import module
if ((areRestrictedModuleKeywordsActive()) // JEP 467: import module
&& (data[++index] == 'o')
&& (data[++index] == 'd')
&& (data[++index] == 'u')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static Class<?> testClass() {
@Override
protected StringBuilder trimJavacLog(StringBuilder log) {
// suppress preview warnings from javac:
if (log.substring(0, 6).equals("Note: ")) {
if (log.length() > 6 && log.substring(0, 6).equals("Note: ")) {
StringBuilder filtered = new StringBuilder();
filtered.append(
log.toString().lines()
Expand Down Expand Up @@ -710,4 +710,40 @@ public class X {
"",
true);
}

public void test014_moduleAsPackageName_regular() {
List<String> files = new ArrayList<>();
writeFileCollecting(files, OUTPUT_DIR + File.separator + "module", "Z.java",
"""
package module;
public class Z {}
""");
writeFileCollecting(files, OUTPUT_DIR + File.separator + "test", "X.java",
"""
package test;
import module.Z;
public class X extends Z {}
""");
StringBuilder commandLine = new StringBuilder(" -23 --enable-preview");
runConformModuleTest(files, commandLine, "", "");
}


public void test014_moduleAsPackageName_moduleInfo() {
List<String> files = new ArrayList<>();
writeFileCollecting(files, OUTPUT_DIR + File.separator + "module", "Z.java",
"""
package module;
public class Z {}
""");
writeFileCollecting(files, OUTPUT_DIR, "module-info.java",
"""
import module.Z;
module one {
uses Z;
}
""");
StringBuilder commandLine = new StringBuilder(" -23 --enable-preview");
runConformModuleTest(files, commandLine, "", "");
}
}
Loading