21
21
import org .jetbrains .annotations .Nullable ;
22
22
23
23
public class CopyMagentoPath extends CopyPathProvider {
24
+
24
25
public static final String PHTML_EXTENSION = "phtml" ;
25
26
public static final String JS_EXTENSION = "js" ;
26
27
public static final String CSS_EXTENSION = "css" ;
@@ -56,23 +57,23 @@ private boolean isNotValidFile(final VirtualFile virtualFile) {
56
57
|| virtualFile != null && !acceptedTypes .contains (virtualFile .getExtension ());
57
58
}
58
59
59
- @ Nullable
60
60
@ Override
61
- public String getPathToElement (
62
- @ NotNull final Project project ,
63
- @ Nullable final VirtualFile virtualFile ,
64
- @ Nullable final Editor editor
61
+ public @ Nullable String getPathToElement (
62
+ final @ NotNull Project project ,
63
+ final @ Nullable VirtualFile virtualFile ,
64
+ final @ Nullable Editor editor
65
65
) {
66
66
if (virtualFile == null ) {
67
67
return null ;
68
68
}
69
- final PsiFile file
70
- = PsiManager . getInstance ( project ). findFile ( virtualFile );
69
+ final PsiFile file = PsiManager . getInstance ( project ). findFile ( virtualFile );
70
+
71
71
if (file == null ) {
72
72
return null ;
73
73
}
74
74
final PsiDirectory directory = file .getContainingDirectory ();
75
75
final String moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
76
+
76
77
if (moduleName == null ) {
77
78
return null ;
78
79
}
@@ -89,15 +90,30 @@ public String getPathToElement(
89
90
} else {
90
91
return fullPath .toString ();
91
92
}
93
+ int endIndex ;
92
94
93
- final int endIndex = getIndexOf (paths , fullPath , paths [++index ]);
95
+ try {
96
+ endIndex = getIndexOf (paths , fullPath , paths [++index ]);
97
+ } catch (ArrayIndexOutOfBoundsException exception ) {
98
+ // endIndex could not be found.
99
+ return "" ;
100
+ }
94
101
final int offset = paths [index ].length ();
95
102
96
103
fullPath .replace (0 , endIndex + offset , "" );
97
104
98
105
return moduleName + SEPARATOR + fullPath ;
99
106
}
100
107
108
+ /**
109
+ * Get index where web|template path starts in the fullPath.
110
+ *
111
+ * @param paths String[]
112
+ * @param fullPath StringBuilder
113
+ * @param path String
114
+ *
115
+ * @return int
116
+ */
101
117
private int getIndexOf (final String [] paths , final StringBuilder fullPath , final String path ) {
102
118
return fullPath .lastIndexOf (path ) == -1
103
119
? getIndexOf (paths , fullPath , paths [++index ])
0 commit comments