@@ -33,7 +33,8 @@ public class FilePathReferenceProvider extends PsiReferenceProvider {
33
33
"PMD.CognitiveComplexity" ,
34
34
"PMD.CyclomaticComplexity" ,
35
35
"PMD.NPathComplexity" ,
36
- "PMD.AvoidInstantiatingObjectsInLoops"
36
+ "PMD.AvoidInstantiatingObjectsInLoops" ,
37
+ "PMD.AvoidDeeplyNestedIfStmts"
37
38
})
38
39
@ NotNull
39
40
@ Override
@@ -92,14 +93,13 @@ public PsiReference[] getReferencesByElement(
92
93
if (null != psiElement ) {
93
94
final int currentPathIndex = currentPath .lastIndexOf ('/' ) == -1
94
95
? 0 : currentPath .lastIndexOf ('/' ) + 1 ;
96
+ final int startOffset = origValue .indexOf (filePath ) + currentPathIndex ;
97
+ final int endOffset = startOffset + pathPart .length ();
95
98
96
- final TextRange pathRange = new TextRange (
97
- origValue .indexOf (filePath )
98
- + currentPathIndex ,
99
- origValue .indexOf (filePath )
100
- + currentPathIndex
101
- + pathPart .length ()
102
- );
99
+ if (!isProperRange (startOffset , endOffset )) {
100
+ continue ;
101
+ }
102
+ final TextRange pathRange = new TextRange (startOffset , endOffset );
103
103
104
104
if (psiPathElements .containsKey (pathRange )) {
105
105
psiPathElements .get (pathRange ).add (psiElement );
@@ -186,4 +186,8 @@ private Collection<VirtualFile> getFiles(final @NotNull PsiElement element) {
186
186
private boolean isModuleNamePresent (final @ NotNull PsiElement element ) {
187
187
return GetModuleNameUtil .getInstance ().execute (element .getText ()) != null ;
188
188
}
189
+
190
+ private boolean isProperRange (final int startOffset , final int endOffset ) {
191
+ return startOffset <= endOffset && startOffset >= 0 ;
192
+ }
189
193
}
0 commit comments