1010 *******************************************************************************/
1111package org .eclipse .jdt .internal .core .search .matching ;
1212
13+ import org .eclipse .jdt .core .dom .AST ;
1314import org .eclipse .jdt .core .dom .ASTNode ;
1415import org .eclipse .jdt .core .dom .ExportsDirective ;
1516import org .eclipse .jdt .core .dom .IBinding ;
1617import org .eclipse .jdt .core .dom .IModuleBinding ;
18+ import org .eclipse .jdt .core .dom .ImportDeclaration ;
19+ import org .eclipse .jdt .core .dom .Modifier ;
1720import org .eclipse .jdt .core .dom .ModuleDeclaration ;
1821import org .eclipse .jdt .core .dom .Name ;
1922import 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