com.jetbrains.php.lang.psi.elements.PhpNamespace Java Examples

The following examples show how to use com.jetbrains.php.lang.psi.elements.PhpNamespace. 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: PhpIndexUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
private static Collection<PhpClass> getPhpClassInsideNamespace(@NotNull Project project, @NotNull PhpIndex phpIndex, @NotNull String namespaceName, int maxDeep) {

    final Collection<PhpClass> phpClasses = new ArrayList<>();

    if(maxDeep-- <= 0) {
        return phpClasses;
    }

    for (PhpNamespace phpNamespace : phpIndex.getNamespacesByName(namespaceName.toLowerCase())) {
        phpClasses.addAll(PsiTreeUtil.getChildrenOfTypeAsList(phpNamespace.getStatements(), PhpClass.class));
    }

    for(String ns: phpIndex.getChildNamespacesByParentName(namespaceName + "\\")) {
        phpClasses.addAll(getPhpClassInsideNamespace(project, phpIndex, namespaceName + "\\" + ns, maxDeep));
    }

    return phpClasses;
}
 
Example #2
Source File: AnnotationInspectionUtil.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Nullable
public String getNamespace() {
    if (hasNamespace) {
        return this.namespace;
    }

    PhpPsiElement scope = PhpCodeInsightUtil.findScopeForUseOperator(psiElement);

    if (scope instanceof PhpNamespace) {
        String namespaceFqn = ((PhpNamespace) scope).getFQN();
        if (PhpLangUtil.isFqn(namespaceFqn) && !PhpLangUtil.isGlobalNamespaceFQN(namespaceFqn)) {
            hasNamespace = true;
            return this.namespace = namespaceFqn;
        }
    }

    return this.namespace = null;
}
 
Example #3
Source File: PhpIndexUtil.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
private static Collection<PhpClass> getPhpClassInsideNamespace(Project project, PhpIndex phpIndex, String namespaceName, int maxDeep) {

        final Collection<PhpClass> phpClasses = new ArrayList<>();

        if(maxDeep-- <= 0) {
            return phpClasses;
        }

        StubIndex.getInstance().processElements(PhpNamespaceIndex.KEY, namespaceName.toLowerCase(), project, phpIndex.getSearchScope(), PhpNamespace.class, phpNamespace -> {
            phpClasses.addAll(PsiTreeUtil.getChildrenOfTypeAsList(phpNamespace.getStatements(), PhpClass.class));
            return true;
        });

        for(String ns: phpIndex.getChildNamespacesByParentName(namespaceName + "\\")) {
            phpClasses.addAll(getPhpClassInsideNamespace(project, phpIndex, namespaceName + "\\" + ns, maxDeep));
        }

        return phpClasses;
    }
 
Example #4
Source File: PhpFunctionCompletionContributor.java    From idea-php-advanced-autocomplete with MIT License 6 votes vote down vote up
private String[] collectMetaArgumentsSets(PsiElement position) {
    Collection<String> argumentsSets = new ArrayList<>();

    PhpNamespace root = PsiTreeUtil.getParentOfType(position, PhpNamespace.class);
    if (root == null || !"PHPSTORM_META".equals(root.getName())) {
        return new String[0];
    }

    Collection<ParameterList> arguments = PsiTreeUtil.findChildrenOfType(root, ParameterList.class);
    for (ParameterList args : arguments) {
        PsiElement parent = args.getParent();
        if (!(parent instanceof FunctionReference) || !"registerArgumentsSet".equals(((FunctionReference)parent).getName())) {
            continue;
        }

        StringLiteralExpression arg0 = PsiTreeUtil.findChildOfType(args, StringLiteralExpression.class);
        if (arg0 == null) {
            continue;
        }

        argumentsSets.add(arg0.getContents());
    }

    return argumentsSets.toArray(new String[0]);
}
 
Example #5
Source File: LatteNamespaceReference.java    From intellij-latte with MIT License 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean b) {
    List<ResolveResult> results = new ArrayList<>();
    Project project = getElement().getProject();
    for (PhpNamespace phpNamespace : LattePhpUtil.getNamespacesByName(project, namespaceName)) {
        results.add(new PsiElementResolveResult(phpNamespace));
    }

    //for (LattePhpNamespaceReference namespaceReference : LatteUtil.findNamespaceReferences(project, namespaceName)) {
    //    results.add(new PsiElementResolveResult(namespaceReference));
    //}

    return results.toArray(new ResolveResult[0]);
}
 
Example #6
Source File: LatteNamespaceReference.java    From intellij-latte with MIT License 5 votes vote down vote up
@Override
public boolean isReferenceTo(@NotNull PsiElement element) {
    if (element instanceof LattePhpNamespaceReference) {
        return namespaceName.equals(((LattePhpNamespaceReference) element).getNamespaceName());
    }

    if (!(element instanceof PhpNamespace)) {
        return false;
    }
    String namespace = ((PhpNamespace) element).getParentNamespaceName() + ((PhpNamespace) element).getName();
    return namespace.equals(namespaceName);
}
 
Example #7
Source File: LattePhpClassReference.java    From intellij-latte with MIT License 4 votes vote down vote up
@Override
public boolean isReferenceTo(@NotNull PsiElement element) {
    if (element instanceof LattePhpClassUsage) {
        return className.equals(((LattePhpClassUsage) element).getClassName());
    }
    /*if (element instanceof LattePhpClassUsage) {
        Collection<PhpClass> originalClasses = ((LattePhpClassUsage) element).getPhpType().getPhpClasses(element.getProject());
        if (originalClasses.size() > 0) {
            for (ResolveResult result : multiResolve(false)) {
                if (!(result.getElement() instanceof LattePhpClassUsage)) {
                    continue;
                }

                Collection<PhpClass> targetClasses = ((LattePhpClassUsage) result.getElement()).getPhpType().getPhpClasses(element.getProject());
                if (targetClasses.size() == 0) {
                    continue;
                }

                for (PhpClass targetClass : targetClasses) {
                    String targetFqn = targetClass.getFQN();
                    for (PhpClass originalClass : originalClasses) {
                        if (originalClass.getFQN().equals(targetFqn)) {
                            return true;
                        }
                    }
                }
            }

            for (PhpClass originalClass : originalClasses) {
                if (LattePhpUtil.isReferenceTo(originalClass, multiResolve(false), element, ((LattePhpClassUsage) element).getClassName())) {
                    return true;
                }
            }
        }
    }*/

    if (element instanceof PhpClass) {
        return LattePhpUtil.isReferenceTo((PhpClass) element, multiResolve(false), element, ((PhpClass) element).getFQN());
    }

    if (!(element instanceof PhpNamespace)) {
        return false;
    }
    String namespace = ((PhpNamespace) element).getParentNamespaceName() + ((PhpNamespace) element).getName();
    return namespace.equals(className);
}