forked from eclipse-jdt/eclipse.jdt.core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[23] DOM support for JEP 476: Module Import Declarations (Preview)
+ parser to record modifier start position of imports + avoid code duplication in SourceElementParser + new list ImportDeclaration.modifiers() + at 23 even 'static' is represented in that list + existing accessors may scan that list if present fixes eclipse-jdt#2834
- Loading branch information
1 parent
9b33f16
commit a922863
Showing
11 changed files
with
308 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_23Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 GK Software SE and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* This is an implementation of an early-draft specification developed under the Java | ||
* Community Process (JCP) and is made available for testing and evaluation purposes | ||
* only. The code is not compatible with any specification of the JCP. | ||
* | ||
* Contributors: | ||
* Stephan Herrmann - Initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.core.tests.dom; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.jdt.core.ICompilationUnit; | ||
import org.eclipse.jdt.core.JavaCore; | ||
import org.eclipse.jdt.core.dom.AST; | ||
import org.eclipse.jdt.core.dom.ASTNode; | ||
import org.eclipse.jdt.core.dom.CompilationUnit; | ||
import org.eclipse.jdt.core.dom.ImportDeclaration; | ||
import org.eclipse.jdt.core.dom.Modifier; | ||
|
||
import junit.framework.Test; | ||
|
||
public class ASTConverter_23Test extends ConverterTestSetup { | ||
|
||
ICompilationUnit workingCopy; | ||
|
||
public void setUpSuite() throws Exception { | ||
super.setUpSuite(); | ||
this.ast = AST.newAST(getAST23(), false); | ||
this.currentProject = getJavaProject("Converter_23"); | ||
this.currentProject.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_23); | ||
this.currentProject.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_23); | ||
this.currentProject.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_23); | ||
this.currentProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); | ||
this.currentProject.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE); | ||
} | ||
|
||
public ASTConverter_23Test(String name) { | ||
super(name); | ||
} | ||
|
||
public static Test suite() { | ||
return buildModelTestSuite(ASTConverter_23Test.class); | ||
} | ||
|
||
static int getAST23() { | ||
return AST.JLS23; | ||
} | ||
protected void tearDown() throws Exception { | ||
super.tearDown(); | ||
if (this.workingCopy != null) { | ||
this.workingCopy.discardWorkingCopy(); | ||
this.workingCopy = null; | ||
} | ||
} | ||
|
||
|
||
public void test001() throws CoreException { | ||
String contents = """ | ||
package p; | ||
import module java.base; | ||
import static java.lang.System.out; | ||
class X { | ||
void m() { | ||
out.println(Map.class.toString()); | ||
} | ||
} | ||
"""; | ||
this.workingCopy = getWorkingCopy("/Converter_23/src/p/X.java", true/*resolve*/); | ||
ASTNode node = buildAST( | ||
contents, | ||
this.workingCopy); | ||
assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); | ||
CompilationUnit compilationUnit = (CompilationUnit) node; | ||
assertProblemsSize(compilationUnit, 0); | ||
List<ImportDeclaration> imports = compilationUnit.imports(); | ||
assertEquals("Incorrect no of imports", 2, imports.size()); | ||
|
||
{ | ||
ImportDeclaration imp = imports.get(0); | ||
assertEquals("Incorrect modifier bits", Modifier.MODULE, imp.getModifiers()); | ||
assertEquals("Incorrect no of modifiers", 1, imp.modifiers().size()); | ||
Modifier mod = (Modifier) imp.modifiers().get(0); | ||
assertEquals("Incorrect modifier", "module", mod.getKeyword().toString()); | ||
assertEquals("Incorrect modifier", Modifier.ModifierKeyword.MODULE_KEYWORD, mod.getKeyword()); | ||
assertEquals("Incorrect position", 18, mod.getStartPosition()); | ||
assertEquals("Incorrect content", "module", contents.substring(mod.getStartPosition(), mod.getStartPosition()+6)); | ||
assertEquals("Incorrect name", "java.base", imp.getName().toString()); | ||
} | ||
{ | ||
ImportDeclaration imp = imports.get(1); | ||
assertEquals("Incorrect modifier bits", Modifier.STATIC, imp.getModifiers()); | ||
assertEquals("Incorrect no of modifiers", 1, imp.modifiers().size()); | ||
Modifier mod = (Modifier) imp.modifiers().get(0); | ||
assertEquals("Incorrect modifier", "static", mod.getKeyword().toString()); | ||
assertEquals("Incorrect modifier", Modifier.ModifierKeyword.STATIC_KEYWORD, mod.getKeyword()); | ||
assertEquals("Incorrect position", 43, mod.getStartPosition()); | ||
assertEquals("Incorrect content", "static", contents.substring(mod.getStartPosition(), mod.getStartPosition()+6)); | ||
assertEquals("Incorrect name", "java.lang.System.out", imp.getName().toString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
org.eclipse.jdt.core.tests.model/workspace/Converter_23/.classpath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="var" path="CONVERTER_JCL_21_LIB" sourcepath="CONVERTER_JCL_21_SRC" rootpath="CONVERTER_JCL_SRCROOT"/> | ||
<classpathentry kind="var" path="CONVERTER_JCL_22_LIB" sourcepath="CONVERTER_JCL_22_SRC" rootpath="CONVERTER_JCL_SRCROOT"> | ||
<attributes> | ||
<attribute name="module" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.