10
10
import com .intellij .psi .PsiDirectory ;
11
11
import com .intellij .psi .PsiElement ;
12
12
import com .intellij .psi .PsiFile ;
13
- import com .intellij .psi .PsiManager ;
14
13
import com .intellij .psi .search .GlobalSearchScope ;
15
14
import com .intellij .psi .util .CachedValueProvider ;
16
15
import com .intellij .psi .util .CachedValuesManager ;
@@ -48,31 +47,6 @@ public class FileResourceUtil {
48
47
*/
49
48
private static final String [] GLOB_DETECTION_CHARS = {"*" , "?" , "{" , "[" };
50
49
51
- /**
52
- * Search for files refers to given file
53
- */
54
- @ NotNull
55
- public static Collection <VirtualFile > getFileResourceRefers (@ NotNull Project project , @ NotNull VirtualFile virtualFile ) {
56
- String bundleLocateName = getBundleLocateName (project , virtualFile );
57
- if (bundleLocateName == null ) {
58
- return Collections .emptyList ();
59
- }
60
-
61
- return getFileResourceRefers (project , bundleLocateName );
62
- }
63
-
64
- /**
65
- * Search for files refers to given file
66
- */
67
- @ NotNull
68
- private static Collection <VirtualFile > getFileResourceRefers (@ NotNull Project project , @ NotNull String bundleLocateName ) {
69
- return FileBasedIndex .getInstance ().getContainingFiles (
70
- FileResourcesIndex .KEY ,
71
- bundleLocateName ,
72
- GlobalSearchScope .allScope (project )
73
- );
74
- }
75
-
76
50
/**
77
51
* Search for files refers to given file
78
52
*/
@@ -217,43 +191,6 @@ public static Collection<Pair<VirtualFile, String>> getFileResources(@NotNull Pr
217
191
return files ;
218
192
}
219
193
220
- @ Nullable
221
- public static String getBundleLocateName (@ NotNull Project project , @ NotNull VirtualFile virtualFile ) {
222
- SymfonyBundle containingBundle = new SymfonyBundleUtil (project ).getContainingBundle (virtualFile );
223
- if (containingBundle == null ) {
224
- return null ;
225
- }
226
-
227
- String relativePath = containingBundle .getRelativePath (virtualFile );
228
- if (relativePath == null ) {
229
- return null ;
230
- }
231
-
232
- return "@" + containingBundle .getName () + "/" + relativePath ;
233
- }
234
-
235
- /**
236
- * Search for line definition of "@FooBundle/foo.xml"
237
- */
238
- @ NotNull
239
- private static Collection <PsiElement > getBundleLocateStringDefinitions (@ NotNull Project project , final @ NotNull String bundleFileName ) {
240
- final Collection <PsiElement > psiElements = new HashSet <>();
241
- for (VirtualFile refVirtualFile : getFileResourceRefers (project , bundleFileName )) {
242
- PsiFile psiFile = PsiManager .getInstance (project ).findFile (refVirtualFile );
243
- if (psiFile == null ) {
244
- continue ;
245
- }
246
-
247
- FileResourceVisitorUtil .visitFile (psiFile , consumer -> {
248
- if (bundleFileName .equals (consumer .getResource ())) {
249
- psiElements .add (consumer .getPsiElement ());
250
- }
251
- });
252
- }
253
-
254
- return psiElements ;
255
- }
256
-
257
194
@ Nullable
258
195
public static RelatedItemLineMarkerInfo <PsiElement > getFileImplementsLineMarker (@ NotNull PsiFile psiFile ) {
259
196
final Project project = psiFile .getProject ();
@@ -263,15 +200,6 @@ public static RelatedItemLineMarkerInfo<PsiElement> getFileImplementsLineMarker(
263
200
return null ;
264
201
}
265
202
266
- String bundleLocateName = FileResourceUtil .getBundleLocateName (project , virtualFile );
267
- if (bundleLocateName != null && FileResourceUtil .getFileResourceRefers (project , bundleLocateName ).size () > 0 ) {
268
- NavigationGutterIconBuilder <PsiElement > builder = NavigationGutterIconBuilder .create (PhpIcons .IMPLEMENTS )
269
- .setTargets (NotNullLazyValue .lazy (new FileResourceBundleNotNullLazyValue (project , bundleLocateName )))
270
- .setTooltipText ("Navigate to resource" );
271
-
272
- return builder .createLineMarkerInfo (psiFile );
273
- }
274
-
275
203
if (hasFileResources (project , psiFile )) {
276
204
NavigationGutterIconBuilder <PsiElement > builder = NavigationGutterIconBuilder .create (PhpIcons .IMPLEMENTS )
277
205
.setTargets (NotNullLazyValue .lazy (new FileResourceNotNullLazyValue (project , virtualFile )))
@@ -288,69 +216,22 @@ public static RelatedItemLineMarkerInfo<PsiElement> getFileImplementsLineMarker(
288
216
*/
289
217
@ Nullable
290
218
public static RelatedItemLineMarkerInfo <PsiElement > getFileImplementsLineMarkerInFolderScope (@ NotNull PsiFile psiFile ) {
291
- VirtualFile virtualFile = psiFile .getVirtualFile ();
292
- if (virtualFile == null ) {
293
- return null ;
294
- }
295
-
296
- final Project project = psiFile .getProject ();
297
- String bundleLocateName = FileResourceUtil .getBundleLocateName (project , virtualFile );
298
- if (bundleLocateName == null ) {
219
+ if (!hasFileResources (psiFile .getProject (), psiFile )) {
299
220
return null ;
300
221
}
301
222
302
- Set <String > names = new HashSet <>();
303
- names .add (bundleLocateName );
304
-
305
- // strip filename
306
- int i = bundleLocateName .lastIndexOf ("/" );
307
- if (i > 0 ) {
308
- names .add (bundleLocateName .substring (0 , i ));
309
- }
310
-
311
- int targets = 0 ;
312
- for (String name : names ) {
313
- targets += FileResourceUtil .getFileResourceRefers (project , name ).size ();
314
- }
315
-
316
- if (targets == 0 ) {
223
+ VirtualFile virtualFile = psiFile .getVirtualFile ();
224
+ if (virtualFile == null ) {
317
225
return null ;
318
226
}
319
227
320
228
NavigationGutterIconBuilder <PsiElement > builder = NavigationGutterIconBuilder .create (PlatformIcons .ANNOTATION_TYPE_ICON )
321
- .setTargets (NotNullLazyValue .lazy (new FileResourceBundleNotNullLazyValue ( project , names )))
229
+ .setTargets (NotNullLazyValue .lazy (new FileResourceNotNullLazyValue ( psiFile . getProject (), virtualFile )))
322
230
.setTooltipText ("Symfony: <a href=\" https://symfony.com/doc/current/routing.html#creating-routes-as-annotations\" >Annotation Routing</a>" );
323
231
324
232
return builder .createLineMarkerInfo (psiFile );
325
233
}
326
234
327
- private static class FileResourceBundleNotNullLazyValue implements Supplier <Collection <? extends PsiElement >> {
328
-
329
- private final Collection <String > resources ;
330
- private final Project project ;
331
-
332
- public FileResourceBundleNotNullLazyValue (@ NotNull Project project , @ NotNull Collection <String > resource ) {
333
- this .resources = resource ;
334
- this .project = project ;
335
- }
336
-
337
- public FileResourceBundleNotNullLazyValue (@ NotNull Project project , @ NotNull String resource ) {
338
- this .resources = Collections .singleton (resource );
339
- this .project = project ;
340
- }
341
-
342
- @ Override
343
- public Collection <? extends PsiElement > get () {
344
- Collection <PsiElement > psiElements = new HashSet <>();
345
-
346
- for (String resource : this .resources ) {
347
- psiElements .addAll (getBundleLocateStringDefinitions (project , resource ));
348
- }
349
-
350
- return psiElements ;
351
- }
352
- }
353
-
354
235
/**
355
236
* Gives targets to files on Bundle locate syntax. "@FooBundle/.../foo.yml"
356
237
*/
@@ -474,7 +355,7 @@ private static class FileResourceNotNullLazyValue implements Supplier<Collection
474
355
private final Project project ;
475
356
private final VirtualFile virtualFile ;
476
357
477
- public FileResourceNotNullLazyValue (Project project , VirtualFile virtualFile ) {
358
+ public FileResourceNotNullLazyValue (@ NotNull Project project , @ NotNull VirtualFile virtualFile ) {
478
359
this .project = project ;
479
360
this .virtualFile = virtualFile ;
480
361
}
0 commit comments