Java Code Examples for com.jetbrains.php.PhpIndex#getClassesByFQN()

The following examples show how to use com.jetbrains.php.PhpIndex#getClassesByFQN() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RouteHelper.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@NotNull
private static PsiElement[] getTargetMethods(@NotNull Project project, @NotNull String routeName) {
    List<PsiElement> result = new ArrayList<>();
    List<RouteStub> values = FileBasedIndex.getInstance().getValues(RouteIndex.KEY, routeName, GlobalSearchScope.allScope(project));
    PhpIndex phpIndex = PhpIndex.getInstance(project);

    for (RouteStub routeStub : values) {
        String fqn = routeStub.getController();

        Collection<PhpClass> classesByFQN = phpIndex.getClassesByFQN(fqn);
        classesByFQN.forEach(c -> {
            if (c.findMethodByName(routeStub.getMethod()) != null) {
                result.add(c.findMethodByName(routeStub.getMethod()));
            }
        });
    }

    return result.toArray(new PsiElement[0]);
}
 
Example 2
Source File: PhpElementsUtil.java    From yiistorm with MIT License 6 votes vote down vote up
static public List<ResolveResult> getClassInterfaceResolveResult(Project project, String FQNClassOrInterfaceName) {

        PhpIndex phpIndex = PhpIndex.getInstance(project);
        Collection<PhpClass> phpClasses = phpIndex.getClassesByFQN(FQNClassOrInterfaceName);
        Collection<PhpClass> phpInterfaces = phpIndex.getInterfacesByFQN(FQNClassOrInterfaceName);

        List<ResolveResult> results = new ArrayList<ResolveResult>();
        for (PhpClass phpClass : phpClasses) {
            results.add(new PsiElementResolveResult(phpClass));
        }
        for (PhpClass phpInterface : phpInterfaces) {
            results.add(new PsiElementResolveResult(phpInterface));
        }

        return results;
    }
 
Example 3
Source File: PhpElementsUtil.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public static List<PhpClass> allExtendedClasses(PhpClass phpClass) {
    List<PhpClass> classReferences = new ArrayList<>();
    PhpIndex index = PhpIndex.getInstance(phpClass.getProject());

    List<ClassReference> referenceElements = phpClass.getExtendsList().getReferenceElements();
    for (ClassReference reference : referenceElements) {
        Collection<PhpClass> classesByFQN = index.getClassesByFQN(reference.getFQN());
        for (PhpClass phpClass1 : classesByFQN) {
            classReferences.add(phpClass);
            classReferences.addAll(allExtendedClasses(phpClass1));
        }
    }

    return classReferences;
}
 
Example 4
Source File: PimplePhpTypeProvider.java    From silex-idea-plugin with MIT License 5 votes vote down vote up
@Override
public Collection<? extends PhpNamedElement> getBySignature(String expression, Project project) {

    PhpIndex phpIndex = PhpIndex.getInstance(project);
    Signature signature = new Signature(expression);

    // try to resolve service type
    if(ProjectComponent.isEnabled(project) && signature.hasParameter()) {
        ArrayList<String> parameters = new ArrayList<String>();
        if (Utils.findPimpleContainer(phpIndex, expression, parameters)) {
            return phpIndex.getClassesByFQN(getClassNameFromParameters(phpIndex, project, parameters));
        }
    }

    // if it's not a service try to get original type
    Collection<? extends PhpNamedElement> collection = phpIndex.getBySignature(signature.base, null, 0);
    if (collection.size() == 0) {
        return Collections.emptySet();
    }

    // original type can be array (#C\ClassType[]) resolve to proper value type
    PhpNamedElement element = collection.iterator().next();

    for (String type : element.getType().getTypes()) {
        if (type.endsWith("[]")) {
            Collection<? extends PhpNamedElement> result = phpIndex.getClassesByFQN(type.substring(0, type.length() - 2));
            if (result.size() != 0) {
                return result;
            }
        }
    }

    return collection;
}
 
Example 5
Source File: TCAUtil.java    From idea-php-typo3-plugin with MIT License 4 votes vote down vote up
private static Set<PsiElement> findAvailableRenderTypes(Project project) {
    PhpIndex phpIndex = PhpIndex.getInstance(project);
    PsiFile[] extLocalConfFiles = FilenameIndex.getFilesByName(project, EXT_LOCALCONF_FILENAME, GlobalSearchScope.allScope(project));
    Collection<PhpClass> nodeRegistries = phpIndex.getClassesByFQN(NODE_FACTORY_CLASS);

    Set<PsiElement> elements = new HashSet<>();

    for (PhpClass registry : nodeRegistries) {
        Collections.addAll(
            elements,
            PsiTreeUtil.collectElements(registry, element -> PlatformPatterns
                .psiElement(StringLiteralExpression.class)
                .withParent(
                    PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
                        .withAncestor(
                            3,
                            PlatformPatterns.psiElement(PhpElementTypes.CLASS_FIELD).withName("nodeTypes")
                        )
                )
                .accepts(element)
            )
        );
    }

    for (PsiFile file : extLocalConfFiles) {
        Collections.addAll(
            elements,
            PsiTreeUtil.collectElements(file, element -> PlatformPatterns
                .psiElement(StringLiteralExpression.class)
                .withParent(
                    PlatformPatterns
                        .psiElement(PhpElementTypes.ARRAY_VALUE)
                        .withParent(
                            PlatformPatterns
                                .psiElement(PhpElementTypes.HASH_ARRAY_ELEMENT)
                                .withChild(
                                    PlatformPatterns
                                        .psiElement(PhpElementTypes.ARRAY_KEY)
                                        .withText("'nodeName'")
                                )
                        )
                ).accepts(element))
        );
    }

    return elements;
}
 
Example 6
Source File: Utils.java    From silex-idea-plugin with MIT License 4 votes vote down vote up
private static Boolean findPimpleContainer(PhpIndex phpIndex, String expression, ArrayList<String> parameters, int depth) {

        if (++depth > 5) {
            return false;
        }

        Signature signature = new Signature(expression);
        Collection<? extends PhpNamedElement> collection;

        if (expression.startsWith("#")) {
            collection = phpIndex.getBySignature(signature.base, null, 0);
        } else {
            collection = phpIndex.getClassesByFQN(signature.base);
        }

        if (collection.size() == 0) {
            return false;
        }

        PhpNamedElement element = collection.iterator().next();

        if (element instanceof PhpClass) {
            if (Utils.isPimpleContainerClass((PhpClass) element)) {
                if (signature.hasParameter()) {
                    parameters.add(signature.parameter);
                }
                return true;
            }
        }

        for (String type : element.getType().getTypes()) {

            if (findPimpleContainer(phpIndex, type, parameters, depth)) {
                if (signature.hasParameter()) {
                    parameters.add(signature.parameter);
                }
                return true;
            }
        }

        return false;
    }
 
Example 7
Source File: PhpElementsUtil.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@Nullable
static public PhpClass getClass(PhpIndex phpIndex, String className) {
    Collection<PhpClass> classes = phpIndex.getClassesByFQN(className);
    return classes.isEmpty() ? null : classes.iterator().next();
}
 
Example 8
Source File: PhpElementsUtil.java    From yiistorm with MIT License 4 votes vote down vote up
@Nullable
static public PhpClass getClass(PhpIndex phpIndex, String className) {
    Collection<PhpClass> classes = phpIndex.getClassesByFQN(className);
    return classes.isEmpty() ? null : classes.iterator().next();
}