Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace deprecated "PhpIndex::getAllSubclasses" #2327

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.indexing.FileBasedIndex;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.parser.PhpElementTypes;
import com.jetbrains.php.lang.psi.PhpFile;
import com.jetbrains.php.lang.psi.elements.*;
Expand All @@ -27,6 +26,7 @@
import fr.adrienbrault.idea.symfony2plugin.stubs.indexes.EventAnnotationStubIndex;
import fr.adrienbrault.idea.symfony2plugin.util.EventSubscriberUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PhpIndexUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils;
import fr.adrienbrault.idea.symfony2plugin.util.service.ServiceXmlParserFactory;
import fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper;
Expand Down Expand Up @@ -59,23 +59,18 @@ public static Collection<EventDispatcherSubscribedEvent> getSubscribedEvents(fin

@NotNull
private static Collection<EventDispatcherSubscribedEvent> getSubscribedEventsProxy(@NotNull Project project) {

Collection<EventDispatcherSubscribedEvent> events = new ArrayList<>();

// http://symfony.com/doc/current/components/event_dispatcher/introduction.html
PhpIndex phpIndex = PhpIndex.getInstance(project);
Collection<PhpClass> phpClasses = phpIndex.getAllSubclasses("\\Symfony\\Component\\EventDispatcher\\EventSubscriberInterface");

for(PhpClass phpClass: phpClasses) {

if(PhpElementsUtil.isTestClass(phpClass)) {
for (PhpClass phpClass: PhpIndexUtil.getAllSubclasses(project, "\\Symfony\\Component\\EventDispatcher\\EventSubscriberInterface")) {
if (PhpElementsUtil.isTestClass(phpClass)) {
continue;
}

Method method = phpClass.findMethodByName("getSubscribedEvents");
if(method != null) {
if (method != null) {
PhpReturn phpReturn = PsiTreeUtil.findChildOfType(method, PhpReturn.class);
if(phpReturn != null) {
if (phpReturn != null) {
attachSubscriberEventNames(events, phpClass, phpReturn);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.*;
import com.intellij.util.containers.ContainerUtil;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.psi.elements.*;
import fr.adrienbrault.idea.symfony2plugin.util.FilesystemUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PhpIndexUtil;
import fr.adrienbrault.idea.symfony2plugin.util.ProjectUtil;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -83,7 +83,7 @@ public static Collection<PsiElement> getTreeSignatureTargets(@NotNull Project pr
private static Map<String, Collection<String>> visitTreeSignatures(@NotNull Project project) {
Map<String, Collection<String>> signatures = new HashMap<>();

visitTreeSignatures(PhpIndex.getInstance(project).getAllSubclasses("Symfony\\Component\\Config\\Definition\\ConfigurationInterface"), treeVisitor -> {
visitTreeSignatures(PhpIndexUtil.getAllSubclasses(project, "Symfony\\Component\\Config\\Definition\\ConfigurationInterface"), treeVisitor -> {
if(!signatures.containsKey(treeVisitor.contents)) {
signatures.put(treeVisitor.contents, new HashSet<>());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import com.intellij.openapi.util.Pair;
import com.intellij.psi.PsiElement;
import com.intellij.util.Processor;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import fr.adrienbrault.idea.symfony2plugin.doctrine.metadata.dict.DoctrineManagerEnum;
import fr.adrienbrault.idea.symfony2plugin.doctrine.metadata.util.DoctrineMetadataUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PhpIndexUtil;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
Expand Down Expand Up @@ -60,7 +60,7 @@ private static Collection<String> getAllTypes() {

public static void visitType(@NotNull Project project, @NotNull Collection<String> typeInterfaces, @NotNull Processor<Pair<PhpClass, String>> processor) {
for (String typeInterface : typeInterfaces) {
for (PhpClass phpClass : PhpIndex.getInstance(project).getAllSubclasses(typeInterface)) {
for (PhpClass phpClass : PhpIndexUtil.getAllSubclasses(project, typeInterface)) {
String name = PhpElementsUtil.getMethodReturnAsString(phpClass, "getName");

// non string value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.indexing.FileBasedIndex;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import fr.adrienbrault.idea.symfony2plugin.doctrine.dict.DoctrineModelInterface;
import fr.adrienbrault.idea.symfony2plugin.doctrine.metadata.dict.DoctrineManagerEnum;
Expand All @@ -26,6 +25,7 @@
import fr.adrienbrault.idea.symfony2plugin.stubs.cache.FileIndexCaches;
import fr.adrienbrault.idea.symfony2plugin.stubs.indexes.DoctrineMetadataFileStubIndex;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PhpIndexUtil;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -51,9 +51,10 @@ public class DoctrineMetadataUtil {

@NotNull
public static Collection<LookupElement> getObjectRepositoryLookupElements(@NotNull Project project) {
PhpIndex index = PhpIndex.getInstance(project);
Collection<PhpClass> collection = index.getAllSubclasses("\\Doctrine\\Common\\Persistence\\ObjectRepository");
collection.addAll(index.getAllSubclasses("\\Doctrine\\Persistence\\ObjectRepository"));
Collection<PhpClass> collection = new ArrayList<>();

collection.addAll(PhpIndexUtil.getAllSubclasses(project, "\\Doctrine\\Common\\Persistence\\ObjectRepository"));
collection.addAll(PhpIndexUtil.getAllSubclasses(project, "\\Doctrine\\Persistence\\ObjectRepository"));

return new ArrayList<>(DoctrineRepositoryLookupElement.create(collection));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.PsiElement;
import com.intellij.util.ProcessingContext;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.psi.elements.ConstantReference;
import com.jetbrains.php.lang.psi.elements.MethodReference;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PhpIndexUtil;
import org.jetbrains.annotations.NotNull;

/**
Expand Down Expand Up @@ -41,7 +41,7 @@ protected void addCompletions(@NotNull CompletionParameters completionParameters
return;
}

for (PhpClass phpClass : PhpIndex.getInstance(psiElement.getProject()).getAllSubclasses("\\Symfony\\Component\\Form\\FormTypeInterface")) {
for (PhpClass phpClass : PhpIndexUtil.getAllSubclasses(psiElement.getProject(), "\\Symfony\\Component\\Form\\FormTypeInterface")) {
if (phpClass.isAbstract() || phpClass.isInterface()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import fr.adrienbrault.idea.symfony2plugin.form.visitor.FormOptionLookupVisitor;
import fr.adrienbrault.idea.symfony2plugin.form.visitor.FormOptionVisitor;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PhpIndexUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils;
import fr.adrienbrault.idea.symfony2plugin.util.service.ServiceXmlParserFactory;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -81,7 +82,7 @@ private static Set<PhpClass> getFormTypeExtensionClassNames(@NotNull Project pro
);
}

for(PhpClass phpClass: PhpIndex.getInstance(project).getAllSubclasses(FormUtil.FORM_EXTENSION_INTERFACE)) {
for(PhpClass phpClass: PhpIndexUtil.getAllSubclasses(project, FormUtil.FORM_EXTENSION_INTERFACE)) {
if(!FormUtil.isValidFormPhpClass(phpClass)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import fr.adrienbrault.idea.symfony2plugin.form.dict.FormTypeServiceParser;
import fr.adrienbrault.idea.symfony2plugin.util.MethodMatcher;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PhpIndexUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils;
import fr.adrienbrault.idea.symfony2plugin.util.psi.PsiElementAssertUtil;
import fr.adrienbrault.idea.symfony2plugin.util.service.ServiceXmlParserFactory;
Expand Down Expand Up @@ -381,7 +382,7 @@ public static Map<String, FormTypeClass> getFormTypeClasses(@NotNull Project pro
public @NotNull Result<Collection<String[]>> compute() {
Collection<String[]> items = new ArrayList<>();

for (PhpClass phpClass : PhpIndex.getInstance(project).getAllSubclasses(ABSTRACT_FORM_INTERFACE)) {
for (PhpClass phpClass : PhpIndexUtil.getAllSubclasses(project, ABSTRACT_FORM_INTERFACE)) {
if (!isValidFormPhpClass(phpClass)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.*;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.lexer.PhpTokenTypes;
import com.jetbrains.php.lang.parser.PhpElementTypes;
import com.jetbrains.php.lang.psi.elements.*;
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PhpIndexUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils;
import fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -73,7 +73,7 @@ public static Collection<LookupElement> getVoterAttributeLookupElements(@NotNull
}

public static void visitAttribute(@NotNull Project project, @NotNull Consumer<Pair<String, PsiElement>> consumer) {
for (PhpClass phpClass : PhpIndex.getInstance(project).getAllSubclasses("Symfony\\Component\\Security\\Core\\Authorization\\Voter\\Voter")) {
for (PhpClass phpClass : PhpIndexUtil.getAllSubclasses(project, "Symfony\\Component\\Security\\Core\\Authorization\\Voter\\Voter")) {
Method supports = phpClass.findMethodByName("supports");
if(supports != null) {
visitAttribute(supports, consumer);
Expand All @@ -85,7 +85,7 @@ public static void visitAttribute(@NotNull Project project, @NotNull Consumer<Pa
}
}

for (PhpClass phpClass : PhpIndex.getInstance(project).getAllSubclasses("Symfony\\Component\\Security\\Core\\Authorization\\Voter\\VoterInterface")) {
for (PhpClass phpClass : PhpIndexUtil.getAllSubclasses(project, "Symfony\\Component\\Security\\Core\\Authorization\\Voter\\VoterInterface")) {
Method vote = phpClass.findMethodByName("vote");
if(vote != null) {
visitAttributeForeach(vote, consumer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import fr.adrienbrault.idea.symfony2plugin.templating.variable.resolver.FormVarsResolver;
import fr.adrienbrault.idea.symfony2plugin.templating.variable.resolver.TwigTypeResolver;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PhpIndexUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils;
import fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -482,8 +483,8 @@ private static Collection<TwigTypeContainer> resolveTwigMethodName(Collection<Tw
*/
@NotNull
private static Collection<TwigTypeContainer> getApplicationUserImplementations(@NotNull Project project) {
return PhpIndex.getInstance(project)
.getAllSubclasses("\\Symfony\\Component\\Security\\Core\\User\\UserInterface")
return PhpIndexUtil
.getAllSubclasses(project, "\\Symfony\\Component\\Security\\Core\\User\\UserInterface")
.stream()
.filter(phpClass -> !phpClass.isInterface()) // filter out implementation like AdvancedUserInterface
.map(TwigTypeContainer::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2562,10 +2562,10 @@ public static Collection<PhpClass> getTwigExtensionClasses(@NotNull Project proj
Collection<PhpClass> allSubclasses = new HashSet<>();

// Twig 1
allSubclasses.addAll(PhpIndex.getInstance(project).getAllSubclasses("\\Twig_ExtensionInterface"));
allSubclasses.addAll(PhpIndexUtil.getAllSubclasses(project, "\\Twig_ExtensionInterface"));

// Twig 2+
allSubclasses.addAll(PhpIndex.getInstance(project).getAllSubclasses("\\Twig\\Extension\\ExtensionInterface"));
allSubclasses.addAll(PhpIndexUtil.getAllSubclasses(project, "\\Twig\\Extension\\ExtensionInterface"));

// Filter units tests and use HashSet as interfaces are nested for BC
return allSubclasses.stream()
Expand Down Expand Up @@ -2661,10 +2661,8 @@ public static DomainScope getTwigFileDomainScope(@NotNull PsiElement psiElement)
public static void visitTokenParsers(@NotNull Project project, @NotNull Consumer<Triple<String, PsiElement, Method>> consumer) {
Set<PhpClass> allSubclasses = new HashSet<>();

PhpIndex phpIndex = PhpIndex.getInstance(project);

allSubclasses.addAll(phpIndex.getAllSubclasses("\\Twig_TokenParserInterface"));
allSubclasses.addAll(phpIndex.getAllSubclasses("\\Twig\\TokenParser\\TokenParserInterface"));
allSubclasses.addAll(PhpIndexUtil.getAllSubclasses(project, "\\Twig_TokenParserInterface"));
allSubclasses.addAll(PhpIndexUtil.getAllSubclasses(project, "\\Twig\\TokenParser\\TokenParserInterface"));

for (PhpClass allSubclass : allSubclasses) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class CommandUtil {
public static Map<String, String> getCommandHelper(@NotNull Project project) {

Map<String, String> map = new HashMap<>();
for(PhpClass phpClass: PhpIndex.getInstance(project).getAllSubclasses("\\Symfony\\Component\\Console\\Helper\\HelperInterface")) {
for(PhpClass phpClass: PhpIndexUtil.getAllSubclasses(project, "\\Symfony\\Component\\Console\\Helper\\HelperInterface")) {
String helperName = PhpElementsUtil.getMethodReturnAsString(phpClass, "getName");
if(helperName != null) {
map.put(helperName, phpClass.getPresentableFQN());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import com.intellij.codeInsight.completion.PrefixMatcher;
import com.intellij.openapi.project.Project;
import com.intellij.util.Processor;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import com.jetbrains.php.util.PhpContractUtil;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -30,6 +32,18 @@ public static Collection<PhpClass> getPhpClassInsideNamespace(@NotNull Project p
return getPhpClassInsideNamespace(PhpIndex.getInstance(project), namespaceName, 10);
}

public static Collection<PhpClass> getAllSubclasses(@NotNull Project project, @NotNull String clazz) {
Collection<PhpClass> phpClasses = new ArrayList<>();

PhpIndex.getInstance(project).processAllSubclasses(clazz, phpClass -> {
phpClasses.add(phpClass);
return true;
});

return phpClasses;
}


@NotNull
private static Collection<PhpClass> getPhpClassInsideNamespace(@NotNull PhpIndex phpIndex, @NotNull String namespaceName, int maxDeep) {
PhpContractUtil.assertFqn(namespaceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ public Collection<SymfonyBundle> getBundles() {

symfonyBundles = new ArrayList<>();

Collection<PhpClass> phpClasses = PhpIndex.getInstance(project).getAllSubclasses("\\Symfony\\Component\\HttpKernel\\Bundle\\Bundle");

for (PhpClass phpClass : phpClasses) {
for (PhpClass phpClass : PhpIndexUtil.getAllSubclasses(project, "\\Symfony\\Component\\HttpKernel\\Bundle\\Bundle")) {
symfonyBundles.add(new SymfonyBundle(phpClass));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import fr.adrienbrault.idea.symfony2plugin.util.dict.SymfonyCommand;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
* @author Daniel Espendiller <[email protected]>
Expand All @@ -28,7 +31,7 @@ public static Collection<SymfonyCommand> getCommands(@NotNull Project project) {
() -> {
Map<String, String> symfonyCommands = new HashMap<>();

for (PhpClass phpClass : PhpIndex.getInstance(project).getAllSubclasses("\\Symfony\\Component\\Console\\Command\\Command")) {
for (PhpClass phpClass : PhpIndexUtil.getAllSubclasses(project, "\\Symfony\\Component\\Console\\Command\\Command")) {
if (PhpElementsUtil.isTestClass(phpClass)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import fr.adrienbrault.idea.symfony2plugin.stubs.indexes.ServicesTagStubIndex;
import fr.adrienbrault.idea.symfony2plugin.util.IdeHelper;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PhpIndexUtil;
import fr.adrienbrault.idea.symfony2plugin.util.service.ServiceXmlParserFactory;
import fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -617,7 +618,7 @@ private static Collection<String> getParameterParametersInner(@NotNull Project p

Collection<PhpClass> phpClasses = new HashSet<>() {{
addAll(PhpIndex.getInstance(project).getAnyByFQN("Symfony\\Component\\HttpKernel\\Kernel"));
addAll(PhpIndex.getInstance(project).getAllSubclasses("Symfony\\Component\\HttpKernel\\Kernel"));
addAll(PhpIndexUtil.getAllSubclasses(project, "Symfony\\Component\\HttpKernel\\Kernel"));
}};

for (PhpClass phpClass : phpClasses) {
Expand Down
Loading