@@ -33,7 +33,8 @@ public class FilePathReferenceProvider extends PsiReferenceProvider {
3333 "PMD.CognitiveComplexity" ,
3434 "PMD.CyclomaticComplexity" ,
3535 "PMD.NPathComplexity" ,
36- "PMD.AvoidInstantiatingObjectsInLoops"
36+ "PMD.AvoidInstantiatingObjectsInLoops" ,
37+ "PMD.AvoidDeeplyNestedIfStmts"
3738 })
3839 @ NotNull
3940 @ Override
@@ -92,14 +93,13 @@ public PsiReference[] getReferencesByElement(
9293 if (null != psiElement ) {
9394 final int currentPathIndex = currentPath .lastIndexOf ('/' ) == -1
9495 ? 0 : currentPath .lastIndexOf ('/' ) + 1 ;
96+ final int startOffset = origValue .indexOf (filePath ) + currentPathIndex ;
97+ final int endOffset = startOffset + pathPart .length ();
9598
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 );
103103
104104 if (psiPathElements .containsKey (pathRange )) {
105105 psiPathElements .get (pathRange ).add (psiElement );
@@ -186,4 +186,8 @@ private Collection<VirtualFile> getFiles(final @NotNull PsiElement element) {
186186 private boolean isModuleNamePresent (final @ NotNull PsiElement element ) {
187187 return GetModuleNameUtil .getInstance ().execute (element .getText ()) != null ;
188188 }
189+
190+ private boolean isProperRange (final int startOffset , final int endOffset ) {
191+ return startOffset <= endOffset && startOffset >= 0 ;
192+ }
189193}
0 commit comments