27
27
public class PluginTargetLineMarkerProvider implements LineMarkerProvider {
28
28
@ Nullable
29
29
@ Override
30
- public LineMarkerInfo getLineMarkerInfo (@ NotNull PsiElement psiElement ) {
30
+ public LineMarkerInfo getLineMarkerInfo (@ NotNull final PsiElement psiElement ) {
31
31
return null ;
32
32
}
33
33
34
34
@ Override
35
35
public void collectSlowLineMarkers (
36
- @ NotNull List <PsiElement > psiElements ,
37
- @ NotNull Collection <LineMarkerInfo > collection
36
+ @ NotNull final List <PsiElement > psiElements ,
37
+ @ NotNull final Collection <LineMarkerInfo > collection
38
38
) {
39
- if (psiElements .size () > 0 ) {
40
- if (!Settings .isEnabled (psiElements .get (0 ).getProject ())) {
41
- return ;
42
- }
39
+ if (!psiElements .isEmpty () && !Settings .isEnabled (psiElements .get (0 ).getProject ())) {
40
+ return ;
43
41
}
44
- PluginClassCache pluginClassCache = new PluginClassCache ();
45
- TargetClassesCollector targetClassesCollector =
42
+ final PluginClassCache pluginClassCache = new PluginClassCache ();
43
+ final TargetClassesCollector targetClassesCollector =
46
44
new TargetClassesCollector (pluginClassCache );
47
- TargetMethodsCollector targetMethodsCollector =
45
+ final TargetMethodsCollector targetMethodsCollector =
48
46
new TargetMethodsCollector (pluginClassCache );
49
47
50
- for (PsiElement psiElement : psiElements ) {
48
+ for (final PsiElement psiElement : psiElements ) {
51
49
if (psiElement instanceof PhpClass || psiElement instanceof Method ) {
52
50
List <? extends PsiElement > results ;
53
51
54
52
if (psiElement instanceof PhpClass ) {
55
53
results = targetClassesCollector .collect ((PhpClass ) psiElement );
56
- if (results .size () > 0 ) {
54
+ if (! results .isEmpty () ) {
57
55
collection .add (NavigationGutterIconBuilder
58
56
.create (AllIcons .Nodes .Class )
59
57
.setTargets (results )
@@ -63,7 +61,7 @@ public void collectSlowLineMarkers(
63
61
}
64
62
} else {
65
63
results = targetMethodsCollector .collect ((Method ) psiElement );
66
- if (results .size () > 0 ) {
64
+ if (! results .isEmpty () ) {
67
65
collection .add (NavigationGutterIconBuilder
68
66
.create (AllIcons .Nodes .Method )
69
67
.setTargets (results )
@@ -78,35 +76,36 @@ public void collectSlowLineMarkers(
78
76
}
79
77
80
78
private static class PluginClassCache {
81
- private HashMap <String , List <PhpClass >> pluginClassesMap =
82
- new HashMap <String , List < PhpClass > >();
79
+ private final HashMap <String , List <PhpClass >> pluginClassesMap =
80
+ new HashMap <>();
83
81
84
- List <PhpClass > getTargetClassesForPlugin (
85
- @ NotNull PhpClass phpClass ,
86
- @ NotNull String classFQN
82
+ private List <PhpClass > getTargetClassesForPlugin (
83
+ @ NotNull final PhpClass phpClass ,
84
+ @ NotNull final String classFQN
87
85
) {
88
- List <PhpClass > results = new ArrayList <>();
89
86
90
87
if (pluginClassesMap .containsKey (classFQN )) {
91
88
return pluginClassesMap .get (classFQN );
92
89
}
93
90
94
- GetTargetClassNamesByPluginClassName targetClassesService =
91
+ final GetTargetClassNamesByPluginClassName targetClassesService =
95
92
GetTargetClassNamesByPluginClassName .getInstance (phpClass .getProject ());
96
- ArrayList <String > targetClassNames = targetClassesService .execute (classFQN );
93
+ final ArrayList <String > targetClassNames = targetClassesService .execute (classFQN );
94
+
95
+ final List <PhpClass > results = new ArrayList <>();
97
96
98
- if (targetClassNames .size () == 0 ) {
97
+ if (targetClassNames .isEmpty () ) {
99
98
pluginClassesMap .put (classFQN , results );
100
99
return results ;
101
100
}
102
101
103
- PhpIndex phpIndex = PhpIndex .getInstance (phpClass .getProject ());
102
+ final PhpIndex phpIndex = PhpIndex .getInstance (phpClass .getProject ());
104
103
105
- for (String targetClassName : targetClassNames ) {
106
- Collection <PhpClass > targets = phpIndex .getClassesByFQN (targetClassName );
104
+ for (final String targetClassName : targetClassNames ) {
105
+ Collection <PhpClass > targets = phpIndex .getInterfacesByFQN (targetClassName );
107
106
108
107
if (targets .isEmpty ()) {
109
- targets = phpIndex .getInterfacesByFQN (targetClassName );
108
+ targets = phpIndex .getClassesByFQN (targetClassName );
110
109
}
111
110
112
111
results .addAll (targets );
@@ -115,11 +114,11 @@ List<PhpClass> getTargetClassesForPlugin(
115
114
return results ;
116
115
}
117
116
118
- List <PhpClass > getTargetClassesForPlugin (@ NotNull PhpClass phpClass ) {
119
- List <PhpClass > classesForPlugin = getTargetClassesForPlugin (
117
+ protected List <PhpClass > getTargetClassesForPlugin (@ NotNull final PhpClass phpClass ) {
118
+ final List <PhpClass > classesForPlugin = getTargetClassesForPlugin (
120
119
phpClass , phpClass .getPresentableFQN ()
121
120
);
122
- for (PhpClass parent : phpClass .getSupers ()) {
121
+ for (final PhpClass parent : phpClass .getSupers ()) {
123
122
classesForPlugin .addAll (getTargetClassesForPlugin (parent ));
124
123
}
125
124
@@ -128,52 +127,59 @@ List<PhpClass> getTargetClassesForPlugin(@NotNull PhpClass phpClass) {
128
127
}
129
128
130
129
private static class TargetClassesCollector implements Collector <PhpClass , PhpClass > {
131
- private PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache ;
130
+ private final PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache ;
132
131
133
- TargetClassesCollector (PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache ) {
132
+ TargetClassesCollector (
133
+ final PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache
134
+ ) {
134
135
this .pluginClassCache = pluginClassCache ;
135
136
}
136
137
137
138
@ Override
138
- public List <PhpClass > collect (@ NotNull PhpClass psiElement ) {
139
+ public List <PhpClass > collect (@ NotNull final PhpClass psiElement ) {
139
140
return pluginClassCache .getTargetClassesForPlugin (psiElement );
140
141
}
141
142
}
142
143
143
144
private static class TargetMethodsCollector implements Collector <Method , Method > {
144
- private PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache ;
145
+ private final PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache ;
145
146
146
- TargetMethodsCollector (PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache ) {
147
+ TargetMethodsCollector (
148
+ final PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache
149
+ ) {
147
150
this .pluginClassCache = pluginClassCache ;
148
151
}
149
152
150
153
@ Override
151
- public List <Method > collect (@ NotNull Method pluginMethod ) {
152
- List <Method > results = new ArrayList <>();
154
+ public List <Method > collect (@ NotNull final Method pluginMethod ) {
155
+ final List <Method > results = new ArrayList <>();
153
156
154
157
/* Check if the method is a plugin */
155
158
if (null == getPluginPrefix (pluginMethod )) {
156
159
return results ;
157
160
}
158
161
159
- PhpClass pluginClass = pluginMethod .getContainingClass ();
162
+ final PhpClass pluginClass = pluginMethod .getContainingClass ();
160
163
if (pluginClass == null ) {
161
164
return results ;
162
165
}
163
166
164
- List <PhpClass > targetClasses = pluginClassCache .getTargetClassesForPlugin (pluginClass );
165
- if (targetClasses .size () == 0 ) {
167
+ final List <PhpClass > targetClasses
168
+ = pluginClassCache .getTargetClassesForPlugin (pluginClass );
169
+ if (targetClasses .isEmpty ()) {
166
170
return results ;
167
171
}
168
172
169
- for (PhpClass targetClass : targetClasses ) {
170
- String pluginPrefix = getPluginPrefix (pluginMethod );
171
- String targetClassMethodName = getTargetMethodName (pluginMethod , pluginPrefix );
173
+ for (final PhpClass targetClass : targetClasses ) {
174
+ final String pluginPrefix = getPluginPrefix (pluginMethod );
175
+ final String targetClassMethodName = getTargetMethodName (
176
+ pluginMethod , pluginPrefix
177
+ );
172
178
if (targetClassMethodName == null ) {
173
179
continue ;
174
180
}
175
181
176
- Method targetMethod = targetClass .findMethodByName (targetClassMethodName );
182
+ final Method targetMethod = targetClass .findMethodByName (targetClassMethodName );
177
183
if (targetMethod == null ) {
178
184
continue ;
179
185
}
@@ -184,23 +190,21 @@ public List<Method> collect(@NotNull Method pluginMethod) {
184
190
return results ;
185
191
}
186
192
187
- private String getTargetMethodName (Method pluginMethod , String pluginPrefix ) {
188
- String pluginMethodName = pluginMethod .getName ();
189
- String targetClassMethodName = pluginMethodName .replace (pluginPrefix , "" );
193
+ private String getTargetMethodName (final Method pluginMethod , final String pluginPrefix ) {
194
+ final String targetClassMethodName = pluginMethod .getName ().replace (pluginPrefix , "" );
190
195
if (targetClassMethodName .isEmpty ()) {
191
196
return null ;
192
197
}
193
- char firstCharOfTargetName = targetClassMethodName .charAt (0 );
194
- int charType = Character .getType (firstCharOfTargetName );
195
- if (charType == Character .LOWERCASE_LETTER ) {
198
+ final char firstCharOfTargetName = targetClassMethodName .charAt (0 );
199
+ if (Character .getType (firstCharOfTargetName ) == Character .LOWERCASE_LETTER ) {
196
200
return null ;
197
201
}
198
202
return Character .toLowerCase (firstCharOfTargetName )
199
203
+ targetClassMethodName .substring (1 );
200
204
}
201
205
202
- private String getPluginPrefix (Method pluginMethod ) {
203
- String pluginMethodName = pluginMethod .getName ();
206
+ private String getPluginPrefix (final Method pluginMethod ) {
207
+ final String pluginMethodName = pluginMethod .getName ();
204
208
if (pluginMethodName .startsWith (Plugin .PluginType .around .toString ())) {
205
209
return Plugin .PluginType .around .toString ();
206
210
}
0 commit comments