|
12 | 12 | import com.intellij.openapi.project.Project;
|
13 | 13 | import com.intellij.psi.PsiElement;
|
14 | 14 | import com.intellij.psi.PsiFile;
|
| 15 | +import com.intellij.psi.PsiReference; |
15 | 16 | import com.intellij.psi.tree.IElementType;
|
16 | 17 | import com.jetbrains.php.lang.lexer.PhpTokenTypes;
|
17 | 18 | import com.jetbrains.php.lang.psi.PhpFile;
|
| 19 | +import com.jetbrains.php.lang.psi.elements.Method; |
18 | 20 | import com.jetbrains.php.lang.psi.elements.MethodReference;
|
19 | 21 | import com.jetbrains.php.lang.psi.elements.ParameterList;
|
| 22 | +import com.jetbrains.php.lang.psi.elements.PhpClass; |
20 | 23 | import com.magento.idea.magento2plugin.MagentoIcons;
|
21 | 24 | import com.magento.idea.magento2plugin.actions.generation.dialog.CreateAnObserverDialog;
|
| 25 | +import com.magento.idea.magento2plugin.magento.files.Observer; |
22 | 26 | import com.magento.idea.magento2plugin.project.Settings;
|
23 | 27 | import org.jetbrains.annotations.NotNull;
|
24 | 28 |
|
25 | 29 | public class CreateAnObserverAction extends DumbAwareAction {
|
26 | 30 | public static final String ACTION_NAME = "Create a Magento Observer...";
|
27 | 31 | static final String ACTION_DESCRIPTION = "Create a new Magento 2 Observer for the event";
|
28 |
| - static final String SIGNATURE_INTERFACE = "#M#C\\Magento\\Framework\\Event\\ManagerInterface.dispatch"; |
29 |
| - static final String SIGNATURE_CONTEXT = "#M#M#C\\Magento\\Framework\\App\\Action\\Context.getEventManager.dispatch"; |
30 | 32 | public String targetEvent;
|
31 | 33 |
|
32 | 34 | public CreateAnObserverAction() {
|
@@ -100,7 +102,23 @@ private boolean checkIsMethodReference(@NotNull PsiElement element) {
|
100 | 102 | }
|
101 | 103 |
|
102 | 104 | private boolean checkIsEventDispatchMethod(MethodReference element) {
|
103 |
| - return element.getSignature().equals(SIGNATURE_INTERFACE) || element.getSignature().equals(SIGNATURE_CONTEXT); |
| 105 | + PsiReference elementReference = element.getReference(); |
| 106 | + if (elementReference == null) { |
| 107 | + return false; |
| 108 | + } |
| 109 | + PsiElement method = elementReference.resolve(); |
| 110 | + if (!(method instanceof Method)) { |
| 111 | + return false; |
| 112 | + } |
| 113 | + if (!((Method) method).getName().equals(Observer.DISPATCH_METHOD)) { |
| 114 | + return false; |
| 115 | + } |
| 116 | + PsiElement phpClass = method.getParent(); |
| 117 | + if (!(phpClass instanceof PhpClass)) { |
| 118 | + return false; |
| 119 | + } |
| 120 | + String fqn = ((PhpClass) phpClass).getPresentableFQN(); |
| 121 | + return fqn.equals(Observer.INTERFACE); |
104 | 122 | }
|
105 | 123 |
|
106 | 124 | private boolean checkIsElementStringLiteral(@NotNull PsiElement element) {
|
|
0 commit comments