Skip to content

Commit f370aa2

Browse files
committed
Catch situation where Path contains no slashes
1 parent 98f89a2 commit f370aa2

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/main/java/com/cedricziel/idea/typo3/codeInsight/navigation/PathResourceGotoDeclarationHandler.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.intellij.psi.PsiFile;
88
import com.intellij.psi.search.FilenameIndex;
99
import com.intellij.psi.search.GlobalSearchScope;
10+
import org.jetbrains.annotations.NotNull;
1011
import org.jetbrains.annotations.Nullable;
1112

1213
import java.util.Arrays;
@@ -19,12 +20,17 @@ public class PathResourceGotoDeclarationHandler implements GotoDeclarationHandle
1920
@Override
2021
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement sourceElement, int offset, Editor editor) {
2122
if (!isExtResourcePath(sourceElement)) {
22-
return new PsiElement[0];
23+
return emptyPsiElementArray();
2324
}
2425

2526
if (sourceElement != null) {
2627
String text = sourceElement.getText();
27-
String fileName = text.split("/")[text.split("/").length - 1];
28+
String[] strings = text.split("/");
29+
if (strings.length == 0) {
30+
return emptyPsiElementArray();
31+
}
32+
33+
String fileName = strings[strings.length - 1];
2834
String relativePath = text.replaceFirst("EXT:", "");
2935

3036
List<PsiFile> psiFiles = Arrays.asList(
@@ -40,6 +46,11 @@ public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement sourceElement
4046
.toArray(PsiElement[]::new);
4147
}
4248

49+
return emptyPsiElementArray();
50+
}
51+
52+
@NotNull
53+
private PsiElement[] emptyPsiElementArray() {
4354
return new PsiElement[0];
4455
}
4556

0 commit comments

Comments
 (0)