2727public class PluginTargetLineMarkerProvider implements LineMarkerProvider {
2828 @ Nullable
2929 @ Override
30- public LineMarkerInfo getLineMarkerInfo (@ NotNull PsiElement psiElement ) {
30+ public LineMarkerInfo getLineMarkerInfo (@ NotNull final PsiElement psiElement ) {
3131 return null ;
3232 }
3333
3434 @ Override
3535 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
3838 ) {
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 ;
4341 }
44- PluginClassCache pluginClassCache = new PluginClassCache ();
45- TargetClassesCollector targetClassesCollector =
42+ final PluginClassCache pluginClassCache = new PluginClassCache ();
43+ final TargetClassesCollector targetClassesCollector =
4644 new TargetClassesCollector (pluginClassCache );
47- TargetMethodsCollector targetMethodsCollector =
45+ final TargetMethodsCollector targetMethodsCollector =
4846 new TargetMethodsCollector (pluginClassCache );
4947
50- for (PsiElement psiElement : psiElements ) {
48+ for (final PsiElement psiElement : psiElements ) {
5149 if (psiElement instanceof PhpClass || psiElement instanceof Method ) {
5250 List <? extends PsiElement > results ;
5351
5452 if (psiElement instanceof PhpClass ) {
5553 results = targetClassesCollector .collect ((PhpClass ) psiElement );
56- if (results .size () > 0 ) {
54+ if (! results .isEmpty () ) {
5755 collection .add (NavigationGutterIconBuilder
5856 .create (AllIcons .Nodes .Class )
5957 .setTargets (results )
@@ -63,7 +61,7 @@ public void collectSlowLineMarkers(
6361 }
6462 } else {
6563 results = targetMethodsCollector .collect ((Method ) psiElement );
66- if (results .size () > 0 ) {
64+ if (! results .isEmpty () ) {
6765 collection .add (NavigationGutterIconBuilder
6866 .create (AllIcons .Nodes .Method )
6967 .setTargets (results )
@@ -78,35 +76,36 @@ public void collectSlowLineMarkers(
7876 }
7977
8078 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 <>();
8381
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
8785 ) {
88- List <PhpClass > results = new ArrayList <>();
8986
9087 if (pluginClassesMap .containsKey (classFQN )) {
9188 return pluginClassesMap .get (classFQN );
9289 }
9390
94- GetTargetClassNamesByPluginClassName targetClassesService =
91+ final GetTargetClassNamesByPluginClassName targetClassesService =
9592 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 <>();
9796
98- if (targetClassNames .size () == 0 ) {
97+ if (targetClassNames .isEmpty () ) {
9998 pluginClassesMap .put (classFQN , results );
10099 return results ;
101100 }
102101
103- PhpIndex phpIndex = PhpIndex .getInstance (phpClass .getProject ());
102+ final PhpIndex phpIndex = PhpIndex .getInstance (phpClass .getProject ());
104103
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 );
107106
108107 if (targets .isEmpty ()) {
109- targets = phpIndex .getInterfacesByFQN (targetClassName );
108+ targets = phpIndex .getClassesByFQN (targetClassName );
110109 }
111110
112111 results .addAll (targets );
@@ -115,11 +114,11 @@ List<PhpClass> getTargetClassesForPlugin(
115114 return results ;
116115 }
117116
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 (
120119 phpClass , phpClass .getPresentableFQN ()
121120 );
122- for (PhpClass parent : phpClass .getSupers ()) {
121+ for (final PhpClass parent : phpClass .getSupers ()) {
123122 classesForPlugin .addAll (getTargetClassesForPlugin (parent ));
124123 }
125124
@@ -128,52 +127,59 @@ List<PhpClass> getTargetClassesForPlugin(@NotNull PhpClass phpClass) {
128127 }
129128
130129 private static class TargetClassesCollector implements Collector <PhpClass , PhpClass > {
131- private PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache ;
130+ private final PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache ;
132131
133- TargetClassesCollector (PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache ) {
132+ TargetClassesCollector (
133+ final PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache
134+ ) {
134135 this .pluginClassCache = pluginClassCache ;
135136 }
136137
137138 @ Override
138- public List <PhpClass > collect (@ NotNull PhpClass psiElement ) {
139+ public List <PhpClass > collect (@ NotNull final PhpClass psiElement ) {
139140 return pluginClassCache .getTargetClassesForPlugin (psiElement );
140141 }
141142 }
142143
143144 private static class TargetMethodsCollector implements Collector <Method , Method > {
144- private PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache ;
145+ private final PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache ;
145146
146- TargetMethodsCollector (PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache ) {
147+ TargetMethodsCollector (
148+ final PluginTargetLineMarkerProvider .PluginClassCache pluginClassCache
149+ ) {
147150 this .pluginClassCache = pluginClassCache ;
148151 }
149152
150153 @ 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 <>();
153156
154157 /* Check if the method is a plugin */
155158 if (null == getPluginPrefix (pluginMethod )) {
156159 return results ;
157160 }
158161
159- PhpClass pluginClass = pluginMethod .getContainingClass ();
162+ final PhpClass pluginClass = pluginMethod .getContainingClass ();
160163 if (pluginClass == null ) {
161164 return results ;
162165 }
163166
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 ()) {
166170 return results ;
167171 }
168172
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+ );
172178 if (targetClassMethodName == null ) {
173179 continue ;
174180 }
175181
176- Method targetMethod = targetClass .findMethodByName (targetClassMethodName );
182+ final Method targetMethod = targetClass .findMethodByName (targetClassMethodName );
177183 if (targetMethod == null ) {
178184 continue ;
179185 }
@@ -184,23 +190,21 @@ public List<Method> collect(@NotNull Method pluginMethod) {
184190 return results ;
185191 }
186192
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 , "" );
190195 if (targetClassMethodName .isEmpty ()) {
191196 return null ;
192197 }
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 ) {
196200 return null ;
197201 }
198202 return Character .toLowerCase (firstCharOfTargetName )
199203 + targetClassMethodName .substring (1 );
200204 }
201205
202- private String getPluginPrefix (Method pluginMethod ) {
203- String pluginMethodName = pluginMethod .getName ();
206+ private String getPluginPrefix (final Method pluginMethod ) {
207+ final String pluginMethodName = pluginMethod .getName ();
204208 if (pluginMethodName .startsWith (Plugin .PluginType .around .toString ())) {
205209 return Plugin .PluginType .around .toString ();
206210 }
0 commit comments