Skip to content

Commit 9cd4136

Browse files
committed
Match import module
1 parent 0b98db7 commit 9cd4136

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/core/search/matching/DOMModuleLocator.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
*******************************************************************************/
1111
package org.eclipse.jdt.internal.core.search.matching;
1212

13+
import org.eclipse.jdt.core.dom.AST;
1314
import org.eclipse.jdt.core.dom.ASTNode;
1415
import org.eclipse.jdt.core.dom.ExportsDirective;
1516
import org.eclipse.jdt.core.dom.IBinding;
1617
import org.eclipse.jdt.core.dom.IModuleBinding;
18+
import org.eclipse.jdt.core.dom.ImportDeclaration;
19+
import org.eclipse.jdt.core.dom.Modifier;
1720
import org.eclipse.jdt.core.dom.ModuleDeclaration;
1821
import org.eclipse.jdt.core.dom.Name;
1922
import org.eclipse.jdt.core.dom.OpensDirective;
@@ -40,15 +43,28 @@ public LocatorResponse match(ModuleDeclaration node, NodeSetWrapper nodeSet, Mat
4043
@Override
4144
public LocatorResponse match(Name name, NodeSetWrapper nodeSet, MatchLocator locator) {
4245
if (pattern.findReferences
43-
&& (name.getLocationInParent() == RequiresDirective.NAME_PROPERTY
44-
|| name.getLocationInParent() == ExportsDirective.MODULES_PROPERTY
45-
|| name.getLocationInParent() == OpensDirective.MODULES_PROPERTY)
46+
&& isValidLocationForModuleNameReference(name)
4647
&& matchesName(name.toString().toCharArray(), pattern.name)) {
4748
return toResponse(POSSIBLE_MATCH);
4849
}
4950
return toResponse(IMPOSSIBLE_MATCH);
5051
}
5152

53+
private boolean isValidLocationForModuleNameReference(ASTNode name) {
54+
if (name.getLocationInParent() == RequiresDirective.NAME_PROPERTY
55+
|| name.getLocationInParent() == ExportsDirective.MODULES_PROPERTY
56+
|| name.getLocationInParent() == OpensDirective.MODULES_PROPERTY) {
57+
return true;
58+
}
59+
if (name.getAST().apiLevel() >= AST.JLS23 &&
60+
name.getLocationInParent() == ImportDeclaration.NAME_PROPERTY &&
61+
name.getParent() instanceof ImportDeclaration importDecl &&
62+
Modifier.isModule(importDecl.getModifiers())) {
63+
return true;
64+
}
65+
return false;
66+
}
67+
5268
@Override
5369
public LocatorResponse resolveLevel(ASTNode node, IBinding binding, MatchLocator locator) {
5470
if (binding instanceof IModuleBinding mod && matchesName(pattern.name, mod.getName().toCharArray())) {

0 commit comments

Comments
 (0)