2121import org .jetbrains .annotations .Nullable ;
2222
2323public class CopyMagentoPath extends CopyPathProvider {
24+
2425 public static final String PHTML_EXTENSION = "phtml" ;
2526 public static final String JS_EXTENSION = "js" ;
2627 public static final String CSS_EXTENSION = "css" ;
@@ -56,23 +57,23 @@ private boolean isNotValidFile(final VirtualFile virtualFile) {
5657 || virtualFile != null && !acceptedTypes .contains (virtualFile .getExtension ());
5758 }
5859
59- @ Nullable
6060 @ 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
6565 ) {
6666 if (virtualFile == null ) {
6767 return null ;
6868 }
69- final PsiFile file
70- = PsiManager . getInstance ( project ). findFile ( virtualFile );
69+ final PsiFile file = PsiManager . getInstance ( project ). findFile ( virtualFile );
70+
7171 if (file == null ) {
7272 return null ;
7373 }
7474 final PsiDirectory directory = file .getContainingDirectory ();
7575 final String moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
76+
7677 if (moduleName == null ) {
7778 return null ;
7879 }
@@ -89,15 +90,30 @@ public String getPathToElement(
8990 } else {
9091 return fullPath .toString ();
9192 }
93+ int endIndex ;
9294
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+ }
94101 final int offset = paths [index ].length ();
95102
96103 fullPath .replace (0 , endIndex + offset , "" );
97104
98105 return moduleName + SEPARATOR + fullPath ;
99106 }
100107
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+ */
101117 private int getIndexOf (final String [] paths , final StringBuilder fullPath , final String path ) {
102118 return fullPath .lastIndexOf (path ) == -1
103119 ? getIndexOf (paths , fullPath , paths [++index ])
0 commit comments