1414import com .jetbrains .php .lang .psi .elements .StringLiteralExpression ;
1515import com .magento .idea .magento2plugin .magento .files .RegistrationPhp ;
1616import com .magento .idea .magento2plugin .util .RegExUtil ;
17+ import java .util .regex .Matcher ;
18+ import java .util .regex .Pattern ;
1719import org .jetbrains .annotations .Nullable ;
1820
1921public final class GetModuleNameByDirectoryUtil {
20- public static final int THEME_SPLIT_COUNT = 1 ;
21- public static final String THEME_DIRECTORY_REGEX = "app\\ /design\\ /(adminhtml|frontend)\\ /" ;
2222
2323 private GetModuleNameByDirectoryUtil () {}
2424
@@ -34,10 +34,14 @@ public static String execute(
3434 final Project project
3535 ) {
3636 // Check if directory is theme directory and return module name from directory path if yes
37- final String [] splits = psiDirectory .getVirtualFile ().getPath ()
38- .split (THEME_DIRECTORY_REGEX );
39- if (splits .length > THEME_SPLIT_COUNT ) {
40- return splits [1 ].split ("\\ /" )[2 ];
37+ final String path = psiDirectory .getVirtualFile ().getPath ();
38+ final Pattern pattern = Pattern .compile (RegExUtil .CustomTheme .MODULE_NAME );
39+ final Matcher matcher = pattern .matcher (path );
40+ while (matcher .find ()) {
41+ final String moduleNamePath = matcher .group (0 );
42+ if (!moduleNamePath .isEmpty ()) {
43+ return moduleNamePath .split ("/" )[5 ];
44+ }
4145 }
4246
4347 final PhpFile registrationPhp = getRegistrationPhpRecursively (
0 commit comments