diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/completion/ServicePropertyInsertUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/completion/ServicePropertyInsertUtil.java index bdad60956..86cceb1ee 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/completion/ServicePropertyInsertUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/completion/ServicePropertyInsertUtil.java @@ -90,29 +90,12 @@ public static List getInjectionService(@NotNull Project project, @NotNul ); } - HashSet objects = new HashSet<>(); + HashSet classes = new HashSet<>(); - objects.addAll(PhpIndex.getInstance(project).getAllClassFqns(PrefixMatcher.ALWAYS_TRUE)); - objects.addAll(PhpIndex.getInstance(project).getAllInterfacesFqns(PrefixMatcher.ALWAYS_TRUE)); + classes.addAll(PhpIndex.getInstance(project).getAllClassFqns(NonGarbageClassPrefixMatcher.INSTANCE)); + classes.addAll(PhpIndex.getInstance(project).getAllInterfacesFqns(NonGarbageClassPrefixMatcher.INSTANCE)); - Set collect = objects.stream().filter(s -> { - int i = s.lastIndexOf("\\"); - if (i > 0) { - if (s.toLowerCase().contains("\\test\\")) { - return false; - } - - s = s.substring(i); - } - - return !s.endsWith("Test") - && !s.toLowerCase().contains("_phpstan_") - && !s.toLowerCase().contains("ecsprefix") - && !s.toLowerCase().contains("_humbugbox") - && !s.toLowerCase().contains("rectorprefix"); - }).collect(Collectors.toSet()); - - for (String fqn : collect) { + for (String fqn : classes) { // Bar\Foo => Foo int i = fqn.lastIndexOf("\\"); String classPropertyNameRaw = i > 0 @@ -177,6 +160,37 @@ public static List getInjectionService(@NotNull Project project, @NotNul .collect(Collectors.toList()); } + /** + * Filter some invalid classes fqn + * - RectorPrefix2... + * - _PHPStan_f12ae... + */ + private static class NonGarbageClassPrefixMatcher extends PrefixMatcher { + private static final NonGarbageClassPrefixMatcher INSTANCE = new NonGarbageClassPrefixMatcher(); + + private NonGarbageClassPrefixMatcher() { + super(""); + } + + @Override + public boolean prefixMatches(@NotNull String fqn) { + if (fqn.contains("\\") && fqn.toLowerCase().contains("\\test\\")) { + return false; + } + + return !fqn.endsWith("Test") + && !fqn.toLowerCase().contains("_phpstan_") + && !fqn.toLowerCase().contains("ecsprefix") + && !fqn.toLowerCase().contains("_humbugbox") + && !fqn.toLowerCase().contains("rectorprefix"); + } + + @Override + public @NotNull PrefixMatcher cloneWithPrefix(@NotNull String prefix) { + return new NonGarbageClassPrefixMatcher(); + } + } + private static class Match { private final String fqn; private int weight = 0;