-
Notifications
You must be signed in to change notification settings - Fork 189
Implement per-source-folder module-info for multi-release compilation #4534
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
Open
laeubi
wants to merge
7
commits into
eclipse-jdt:master
Choose a base branch
from
laeubi:mr_module_support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
011bf7d
Implement per-source-folder module-info for multi-release compilation
laeubi 61274b7
polish:
stephan-herrmann dd7650f
Make codeSelect release-aware for multi-release modular projects
laeubi 7239a5e
Add test for modular reconciling
laeubi 80056ea
Wire release-awareness into editor name-environment paths
laeubi da034db
Try with using problem requestor only from the workingcopy
laeubi a1dc781
Add tests for MR-aware ASTParser.createASTs / type hierarchy resolution
laeubi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
180 changes: 180 additions & 0 deletions
180
...jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ASTParserMultiReleaseTests.java
This file contains hidden or 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,180 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 Christoph Läubrich 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 | ||
| *******************************************************************************/ | ||
| package org.eclipse.jdt.core.tests.model; | ||
|
|
||
| import junit.framework.Test; | ||
| import org.eclipse.core.runtime.NullProgressMonitor; | ||
| import org.eclipse.jdt.core.ICompilationUnit; | ||
| import org.eclipse.jdt.core.IClasspathAttribute; | ||
| import org.eclipse.jdt.core.IClasspathEntry; | ||
| import org.eclipse.jdt.core.IJavaProject; | ||
| import org.eclipse.jdt.core.JavaCore; | ||
| import org.eclipse.jdt.core.dom.AST; | ||
| import org.eclipse.jdt.core.dom.ASTParser; | ||
| import org.eclipse.jdt.core.dom.ASTRequestor; | ||
| import org.eclipse.jdt.core.dom.CompilationUnit; | ||
| import org.eclipse.jdt.core.dom.FieldDeclaration; | ||
| import org.eclipse.jdt.core.dom.ITypeBinding; | ||
| import org.eclipse.jdt.core.dom.TypeDeclaration; | ||
| import org.eclipse.jdt.core.dom.VariableDeclarationFragment; | ||
|
|
||
| /** | ||
| * Tests that {@link ASTParser#createASTs(ICompilationUnit[], String[], ASTRequestor, org.eclipse.core.runtime.IProgressMonitor)} | ||
| * resolves bindings as seen from the release specific source folder the given compilation | ||
| * units live in, honoring a release specific {@code module-info.java}. | ||
| * | ||
| * See https://github.com/eclipse-jdt/eclipse.jdt.core/pull/4534#discussion_r3660872811 | ||
| */ | ||
| public class ASTParserMultiReleaseTests extends AbstractJavaModelTests { | ||
|
|
||
| static { | ||
| // TESTS_NAMES = new String[] { "testResolveWindowInRelease17" }; | ||
| } | ||
|
|
||
| public ASTParserMultiReleaseTests(String name) { | ||
| super(name); | ||
| } | ||
|
|
||
| public static Test suite() { | ||
| return buildModelTestSuite(ASTParserMultiReleaseTests.class); | ||
| } | ||
|
|
||
| @Override | ||
| public void setUpSuite() throws Exception { | ||
| super.setUpSuite(); | ||
| IJavaProject project = createJava9ProjectWithJREAttributes("ASTParserMR", | ||
| new String[] { "src", "src17", "src21" }, null, "21"); | ||
| IClasspathEntry[] classpath = project.getRawClasspath(); | ||
| for (int i = 0; i < classpath.length; i++) { | ||
| IClasspathEntry entry = classpath[i]; | ||
| if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { | ||
| if (entry.getPath().toString().endsWith("src17")) { | ||
| classpath[i] = JavaCore.newSourceEntry(entry.getPath(), null, null, null, | ||
| new IClasspathAttribute[] { | ||
| JavaCore.newClasspathAttribute(IClasspathAttribute.RELEASE, "17") }); | ||
| } else if (entry.getPath().toString().endsWith("src21")) { | ||
| classpath[i] = JavaCore.newSourceEntry(entry.getPath(), null, null, null, | ||
| new IClasspathAttribute[] { | ||
| JavaCore.newClasspathAttribute(IClasspathAttribute.RELEASE, "21") }); | ||
| } | ||
| } | ||
| } | ||
| project.setRawClasspath(classpath, new NullProgressMonitor()); | ||
| project.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED); | ||
|
|
||
| createFolder("/ASTParserMR/src/p"); | ||
| createFolder("/ASTParserMR/src17/p"); | ||
| createFolder("/ASTParserMR/src21/p"); | ||
|
|
||
| // base module requires nothing | ||
| createFile("/ASTParserMR/src/module-info.java", """ | ||
| module MRastparser { | ||
| } | ||
| """); | ||
| createFile("/ASTParserMR/src/p/Test.java", """ | ||
| package p; | ||
| public class Test { | ||
| java.awt.Window w; | ||
| org.w3c.dom.Element element; | ||
| } | ||
| """); | ||
|
|
||
| // release 17 requires java.desktop (which transitively reads java.xml) | ||
| createFile("/ASTParserMR/src17/module-info.java", """ | ||
| module MRastparser { | ||
| requires java.desktop; | ||
| } | ||
| """); | ||
| createFile("/ASTParserMR/src17/p/Test.java", """ | ||
| package p; | ||
| public class Test { | ||
| java.awt.Window w; | ||
| org.w3c.dom.Element element; | ||
| } | ||
| """); | ||
|
|
||
| // release 21 requires java.xml | ||
| createFile("/ASTParserMR/src21/module-info.java", """ | ||
| module MRastparser { | ||
| requires java.xml; | ||
| } | ||
| """); | ||
| createFile("/ASTParserMR/src21/p/Test.java", """ | ||
| package p; | ||
| public class Test { | ||
| java.awt.Window w; | ||
| org.w3c.dom.Element element; | ||
| } | ||
| """); | ||
| } | ||
|
|
||
| @Override | ||
| public void tearDownSuite() throws Exception { | ||
| deleteProject("ASTParserMR"); | ||
| super.tearDownSuite(); | ||
| } | ||
|
|
||
| private ITypeBinding resolveFieldType(String unitPath, String fieldName) throws Exception { | ||
| ICompilationUnit unit = getCompilationUnit(unitPath); | ||
| ASTParser parser = ASTParser.newParser(AST.getJLSLatest()); | ||
| parser.setResolveBindings(true); | ||
| parser.setProject(getJavaProject("ASTParserMR")); | ||
| final ITypeBinding[] result = new ITypeBinding[1]; | ||
| parser.createASTs(new ICompilationUnit[] { unit }, new String[0], new ASTRequestor() { | ||
| @Override | ||
| public void acceptAST(ICompilationUnit source, CompilationUnit ast) { | ||
| TypeDeclaration type = (TypeDeclaration) ast.types().get(0); | ||
| for (Object bodyDecl : type.bodyDeclarations()) { | ||
| if (bodyDecl instanceof FieldDeclaration field) { | ||
| VariableDeclarationFragment fragment = (VariableDeclarationFragment) field.fragments().get(0); | ||
| if (fragment.getName().getIdentifier().equals(fieldName)) { | ||
| result[0] = field.getType().resolveBinding(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, null); | ||
| return result[0]; | ||
| } | ||
|
|
||
| // org.w3c.dom.Element is reachable in src21 via 'requires java.xml': resolving its | ||
| // field type must succeed with a non-recovered binding for exactly that type. | ||
| public void testResolveElementInRelease21() throws Exception { | ||
| ITypeBinding binding = resolveFieldType("/ASTParserMR/src21/p/Test.java", "element"); | ||
| assertNotNull("Field 'element' not resolved", binding); | ||
| assertFalse("Binding should not be recovered/unresolved", binding.isRecovered()); | ||
| assertEquals("org.w3c.dom.Element", binding.getQualifiedName()); | ||
| } | ||
|
|
||
| // java.awt.Window is reachable in src17 via 'requires java.desktop'. | ||
| public void testResolveWindowInRelease17() throws Exception { | ||
| ITypeBinding binding = resolveFieldType("/ASTParserMR/src17/p/Test.java", "w"); | ||
| assertNotNull("Field 'w' not resolved", binding); | ||
| assertFalse("Binding should not be recovered/unresolved", binding.isRecovered()); | ||
| assertEquals("java.awt.Window", binding.getQualifiedName()); | ||
| } | ||
|
|
||
| // java.desktop reads java.xml transitively, so org.w3c.dom.Element is reachable in src17 too. | ||
| public void testResolveElementInRelease17() throws Exception { | ||
| ITypeBinding binding = resolveFieldType("/ASTParserMR/src17/p/Test.java", "element"); | ||
| assertNotNull("Field 'element' not resolved", binding); | ||
| assertFalse("Binding should not be recovered/unresolved", binding.isRecovered()); | ||
| assertEquals("org.w3c.dom.Element", binding.getQualifiedName()); | ||
| } | ||
|
|
||
| // The base module-info requires neither java.desktop nor java.xml, so java.awt.Window | ||
| // is not accessible and its field type must fail to resolve to a proper binding. | ||
| public void testResolveWindowInBaseReleaseIsUnresolved() throws Exception { | ||
| ITypeBinding binding = resolveFieldType("/ASTParserMR/src/p/Test.java", "w"); | ||
| assertTrue("Binding for inaccessible java.awt.Window should not resolve properly", | ||
| binding == null || binding.isRecovered()); | ||
| } | ||
| } |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.