2
2
* Copyright © Magento, Inc. All rights reserved.
3
3
* See COPYING.txt for license details.
4
4
*/
5
+
5
6
package com .magento .idea .magento2plugin .linemarker .php ;
6
7
7
8
import com .intellij .codeInsight .daemon .LineMarkerInfo ;
8
9
import com .intellij .codeInsight .daemon .LineMarkerProvider ;
9
10
import com .intellij .codeInsight .navigation .NavigationGutterIconBuilder ;
10
11
import com .intellij .icons .AllIcons ;
11
12
import com .intellij .psi .PsiElement ;
13
+ import com .intellij .psi .util .PsiTreeUtil ;
14
+ import java .util .ArrayList ;
15
+ import java .util .Collection ;
16
+ import java .util .HashMap ;
17
+ import java .util .List ;
18
+ import org .jetbrains .annotations .NotNull ;
19
+ import org .jetbrains .annotations .Nullable ;
12
20
import com .jetbrains .php .PhpIndex ;
13
21
import com .jetbrains .php .lang .psi .elements .Method ;
14
22
import com .jetbrains .php .lang .psi .elements .PhpClass ;
15
23
import com .magento .idea .magento2plugin .magento .files .Plugin ;
16
24
import com .magento .idea .magento2plugin .project .Settings ;
17
- import org .jetbrains .annotations .NotNull ;
18
- import org .jetbrains .annotations .Nullable ;
19
25
import com .magento .idea .magento2plugin .util .magento .plugin .GetTargetClassNamesByPluginClassName ;
20
- import com .intellij .psi .util .PsiTreeUtil ;
21
-
22
- import java .util .*;
23
26
24
27
public class PluginTargetLineMarkerProvider implements LineMarkerProvider {
25
28
@ Nullable
@@ -29,23 +32,28 @@ public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) {
29
32
}
30
33
31
34
@ Override
32
- public void collectSlowLineMarkers (@ NotNull List <PsiElement > psiElements , @ NotNull Collection <LineMarkerInfo > collection ) {
35
+ public void collectSlowLineMarkers (
36
+ @ NotNull List <PsiElement > psiElements ,
37
+ @ NotNull Collection <LineMarkerInfo > collection
38
+ ) {
33
39
if (psiElements .size () > 0 ) {
34
40
if (!Settings .isEnabled (psiElements .get (0 ).getProject ())) {
35
41
return ;
36
42
}
37
43
}
38
44
PluginClassCache pluginClassCache = new PluginClassCache ();
39
- TargetClassesCollector TargetClassesCollector = new TargetClassesCollector (pluginClassCache );
40
- TargetMethodsCollector TargetMethodsCollector = new TargetMethodsCollector (pluginClassCache );
45
+ TargetClassesCollector targetClassesCollector =
46
+ new TargetClassesCollector (pluginClassCache );
47
+ TargetMethodsCollector targetMethodsCollector =
48
+ new TargetMethodsCollector (pluginClassCache );
41
49
42
50
for (PsiElement psiElement : psiElements ) {
43
51
if (psiElement instanceof PhpClass || psiElement instanceof Method ) {
44
52
List <? extends PsiElement > results ;
45
53
46
54
if (psiElement instanceof PhpClass ) {
47
- results = TargetClassesCollector .collect ((PhpClass ) psiElement );
48
- if (results .size () > 0 ) {
55
+ results = targetClassesCollector .collect ((PhpClass ) psiElement );
56
+ if (results .size () > 0 ) {
49
57
collection .add (NavigationGutterIconBuilder
50
58
.create (AllIcons .Nodes .Class )
51
59
.setTargets (results )
@@ -54,8 +62,8 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
54
62
);
55
63
}
56
64
} else {
57
- results = TargetMethodsCollector .collect ((Method ) psiElement );
58
- if (results .size () > 0 ) {
65
+ results = targetMethodsCollector .collect ((Method ) psiElement );
66
+ if (results .size () > 0 ) {
59
67
collection .add (NavigationGutterIconBuilder
60
68
.create (AllIcons .Nodes .Method )
61
69
.setTargets (results )
@@ -70,16 +78,21 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
70
78
}
71
79
72
80
private static class PluginClassCache {
73
- private HashMap <String , List <PhpClass >> pluginClassesMap = new HashMap <String , List <PhpClass >>();
81
+ private HashMap <String , List <PhpClass >> pluginClassesMap =
82
+ new HashMap <String , List <PhpClass >>();
74
83
75
- List <PhpClass > getTargetClassesForPlugin (@ NotNull PhpClass phpClass , @ NotNull String classFQN ) {
84
+ List <PhpClass > getTargetClassesForPlugin (
85
+ @ NotNull PhpClass phpClass ,
86
+ @ NotNull String classFQN
87
+ ) {
76
88
List <PhpClass > results = new ArrayList <>();
77
89
78
90
if (pluginClassesMap .containsKey (classFQN )) {
79
91
return pluginClassesMap .get (classFQN );
80
92
}
81
93
82
- GetTargetClassNamesByPluginClassName targetClassesService = GetTargetClassNamesByPluginClassName .getInstance (phpClass .getProject ());
94
+ GetTargetClassNamesByPluginClassName targetClassesService =
95
+ GetTargetClassNamesByPluginClassName .getInstance (phpClass .getProject ());
83
96
ArrayList <String > targetClassNames = targetClassesService .execute (classFQN );
84
97
85
98
if (targetClassNames .size () == 0 ) {
@@ -103,7 +116,9 @@ List<PhpClass> getTargetClassesForPlugin(@NotNull PhpClass phpClass, @NotNull St
103
116
}
104
117
105
118
List <PhpClass > getTargetClassesForPlugin (@ NotNull PhpClass phpClass ) {
106
- List <PhpClass > classesForPlugin = getTargetClassesForPlugin (phpClass , phpClass .getPresentableFQN ());
119
+ List <PhpClass > classesForPlugin = getTargetClassesForPlugin (
120
+ phpClass , phpClass .getPresentableFQN ()
121
+ );
107
122
for (PhpClass parent : phpClass .getSupers ()) {
108
123
classesForPlugin .addAll (getTargetClassesForPlugin (parent ));
109
124
}
@@ -171,8 +186,7 @@ public List<Method> collect(@NotNull Method pluginMethod) {
171
186
172
187
private String getTargetMethodName (Method pluginMethod , String pluginPrefix ) {
173
188
String pluginMethodName = pluginMethod .getName ();
174
- String targetClassMethodName = pluginMethodName .
175
- replace (pluginPrefix , "" );
189
+ String targetClassMethodName = pluginMethodName .replace (pluginPrefix , "" );
176
190
if (targetClassMethodName .isEmpty ()) {
177
191
return null ;
178
192
}
@@ -181,7 +195,8 @@ private String getTargetMethodName(Method pluginMethod, String pluginPrefix) {
181
195
if (charType == Character .LOWERCASE_LETTER ) {
182
196
return null ;
183
197
}
184
- return Character .toLowerCase (firstCharOfTargetName ) + targetClassMethodName .substring (1 );
198
+ return Character .toLowerCase (firstCharOfTargetName )
199
+ + targetClassMethodName .substring (1 );
185
200
}
186
201
187
202
private String getPluginPrefix (Method pluginMethod ) {
0 commit comments