Skip to content

651: slow operations are prohibited on EDT #862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.jetbrains.annotations.NotNull;

public class CreateAPluginAction extends DumbAwareAction {

public static final String ACTION_NAME = "Create a new Plugin for this method";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Plugin";
private final GetFirstClassOfFile getFirstClassOfFile;
Expand All @@ -47,10 +48,12 @@ public void update(final AnActionEvent event) {
targetClass = null;// NOPMD
targetMethod = null;// NOPMD
final Project project = event.getData(PlatformDataKeys.PROJECT);
if (Settings.isEnabled(project)) {

if (project != null && Settings.isEnabled(project)) {
final Pair<PsiFile, PhpClass> pair = this.findPhpClass(event);
final PsiFile psiFile = pair.getFirst();
final PhpClass phpClass = pair.getSecond();

if (phpClass == null
|| !(psiFile instanceof PhpFile)
|| phpClass.isFinal()
Expand All @@ -74,16 +77,21 @@ private void setStatus(final AnActionEvent event, final boolean status) {
}

@Override
public void actionPerformed(@NotNull final AnActionEvent event) {
CreateAPluginDialog.open(event.getProject(), this.targetMethod, this.targetClass);
public void actionPerformed(final @NotNull AnActionEvent event) {
final Project project = event.getProject();

if (project == null) {
return;
}
CreateAPluginDialog.open(project, this.targetMethod, this.targetClass);
}

@Override
public boolean isDumbAware() {
return false;
}

private Pair<PsiFile, PhpClass> findPhpClass(@NotNull final AnActionEvent event) {
private Pair<PsiFile, PhpClass> findPhpClass(final @NotNull AnActionEvent event) {
final PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);

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

private void fetchTargetMethod(
@NotNull final AnActionEvent event,
final @NotNull AnActionEvent event,
final PsiFile psiFile,
final PhpClass phpClass
) {
final Caret caret = event.getData(PlatformDataKeys.CARET);

if (caret == null) {
return;
}
final int offset = caret.getOffset();
final PsiElement element = psiFile.findElementAt(offset);

if (element == null) {
return;
}
if (element instanceof Method && element.getParent()
== phpClass && IsPluginAllowedForMethodUtil.check((Method) element)) {

if (element instanceof Method && element.getParent().equals(phpClass)
&& IsPluginAllowedForMethodUtil.check((Method) element)) {
this.targetMethod = (Method) element;
return;
}
final PsiElement parent = element.getParent();
if (parent instanceof Method && parent.getParent()
== phpClass && IsPluginAllowedForMethodUtil.check((Method) parent)) {

if (parent instanceof Method && parent.getParent().equals(phpClass)
&& IsPluginAllowedForMethodUtil.check((Method) parent)) {
this.targetMethod = (Method) parent;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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

import com.intellij.util.SlowOperations;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import com.magento.idea.magento2plugin.magento.files.Plugin;
import org.jetbrains.annotations.NotNull;
Expand All @@ -17,15 +18,20 @@ private PhpClassImplementsNoninterceptableInterfaceUtil() {}
* Check whether class implements NoninterceptableInterface.
*
* @param phpClass PhpClass
*
* @return bool
*/
public static boolean execute(final @NotNull PhpClass phpClass) {
final PhpClass[] interfaces = phpClass.getImplementedInterfaces();
final PhpClass[] interfaces = SlowOperations.allowSlowOperations(
phpClass::getImplementedInterfaces
);

if (interfaces.length == 0) {
return false;
}

for (final PhpClass targetInterfaceClass: interfaces) {
if (targetInterfaceClass.getFQN().equals(Plugin.NON_INTERCEPTABLE_FQN)) {
if (Plugin.NON_INTERCEPTABLE_FQN.equals(targetInterfaceClass.getFQN())) {
return true;
}
}
Expand Down