Skip to content

Commit b537b45

Browse files
authored
Merge pull request #862 from bohdan-harniuk/651-slow-operations-are-prohibited-on-EDT
651: slow operations are prohibited on EDT
2 parents 10718a0 + 1aafc53 commit b537b45

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

src/com/magento/idea/magento2plugin/actions/generation/CreateAPluginAction.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.jetbrains.annotations.NotNull;
2626

2727
public class CreateAPluginAction extends DumbAwareAction {
28+
2829
public static final String ACTION_NAME = "Create a new Plugin for this method";
2930
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Plugin";
3031
private final GetFirstClassOfFile getFirstClassOfFile;
@@ -47,10 +48,12 @@ public void update(final AnActionEvent event) {
4748
targetClass = null;// NOPMD
4849
targetMethod = null;// NOPMD
4950
final Project project = event.getData(PlatformDataKeys.PROJECT);
50-
if (Settings.isEnabled(project)) {
51+
52+
if (project != null && Settings.isEnabled(project)) {
5153
final Pair<PsiFile, PhpClass> pair = this.findPhpClass(event);
5254
final PsiFile psiFile = pair.getFirst();
5355
final PhpClass phpClass = pair.getSecond();
56+
5457
if (phpClass == null
5558
|| !(psiFile instanceof PhpFile)
5659
|| phpClass.isFinal()
@@ -74,16 +77,21 @@ private void setStatus(final AnActionEvent event, final boolean status) {
7477
}
7578

7679
@Override
77-
public void actionPerformed(@NotNull final AnActionEvent event) {
78-
CreateAPluginDialog.open(event.getProject(), this.targetMethod, this.targetClass);
80+
public void actionPerformed(final @NotNull AnActionEvent event) {
81+
final Project project = event.getProject();
82+
83+
if (project == null) {
84+
return;
85+
}
86+
CreateAPluginDialog.open(project, this.targetMethod, this.targetClass);
7987
}
8088

8189
@Override
8290
public boolean isDumbAware() {
8391
return false;
8492
}
8593

86-
private Pair<PsiFile, PhpClass> findPhpClass(@NotNull final AnActionEvent event) {
94+
private Pair<PsiFile, PhpClass> findPhpClass(final @NotNull AnActionEvent event) {
8795
final PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
8896

8997
PhpClass phpClass = null;
@@ -96,27 +104,31 @@ private Pair<PsiFile, PhpClass> findPhpClass(@NotNull final AnActionEvent event)
96104
}
97105

98106
private void fetchTargetMethod(
99-
@NotNull final AnActionEvent event,
107+
final @NotNull AnActionEvent event,
100108
final PsiFile psiFile,
101109
final PhpClass phpClass
102110
) {
103111
final Caret caret = event.getData(PlatformDataKeys.CARET);
112+
104113
if (caret == null) {
105114
return;
106115
}
107116
final int offset = caret.getOffset();
108117
final PsiElement element = psiFile.findElementAt(offset);
118+
109119
if (element == null) {
110120
return;
111121
}
112-
if (element instanceof Method && element.getParent()
113-
== phpClass && IsPluginAllowedForMethodUtil.check((Method) element)) {
122+
123+
if (element instanceof Method && element.getParent().equals(phpClass)
124+
&& IsPluginAllowedForMethodUtil.check((Method) element)) {
114125
this.targetMethod = (Method) element;
115126
return;
116127
}
117128
final PsiElement parent = element.getParent();
118-
if (parent instanceof Method && parent.getParent()
119-
== phpClass && IsPluginAllowedForMethodUtil.check((Method) parent)) {
129+
130+
if (parent instanceof Method && parent.getParent().equals(phpClass)
131+
&& IsPluginAllowedForMethodUtil.check((Method) parent)) {
120132
this.targetMethod = (Method) parent;
121133
}
122134
}

src/com/magento/idea/magento2plugin/inspections/php/util/PhpClassImplementsNoninterceptableInterfaceUtil.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package com.magento.idea.magento2plugin.inspections.php.util;
77

8+
import com.intellij.util.SlowOperations;
89
import com.jetbrains.php.lang.psi.elements.PhpClass;
910
import com.magento.idea.magento2plugin.magento.files.Plugin;
1011
import org.jetbrains.annotations.NotNull;
@@ -17,15 +18,20 @@ private PhpClassImplementsNoninterceptableInterfaceUtil() {}
1718
* Check whether class implements NoninterceptableInterface.
1819
*
1920
* @param phpClass PhpClass
21+
*
2022
* @return bool
2123
*/
2224
public static boolean execute(final @NotNull PhpClass phpClass) {
23-
final PhpClass[] interfaces = phpClass.getImplementedInterfaces();
25+
final PhpClass[] interfaces = SlowOperations.allowSlowOperations(
26+
phpClass::getImplementedInterfaces
27+
);
28+
2429
if (interfaces.length == 0) {
2530
return false;
2631
}
32+
2733
for (final PhpClass targetInterfaceClass: interfaces) {
28-
if (targetInterfaceClass.getFQN().equals(Plugin.NON_INTERCEPTABLE_FQN)) {
34+
if (Plugin.NON_INTERCEPTABLE_FQN.equals(targetInterfaceClass.getFQN())) {
2935
return true;
3036
}
3137
}

0 commit comments

Comments
 (0)