com.intellij.psi.impl.source.tree.CompositePsiElement Java Examples

The following examples show how to use com.intellij.psi.impl.source.tree.CompositePsiElement. 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: MethodReferenceDiagramDataModel.java    From intellij-reference-diagram with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
protected IncrementableSet<SourceTargetPair> resolveRelationships() {
    PsiElement psiElement = getBaseElement();
    IncrementableSet<SourceTargetPair> incrementableSet = new IncrementableSet<>();

    for (DiagramNode<PsiElement> node : getNodes()) {
        PsiElement callee = node.getIdentifyingElement();

        Collection<PsiReference> all = ReferencesSearch.search(callee, new LocalSearchScope
                (psiElement)).findAll();

        for (PsiReference psiReference : all) {
            if (!(psiReference instanceof CompositePsiElement)) {
                continue;
            }
            PsiElement caller = PsiUtils.getRootPsiElement((PsiClass) psiElement, (CompositePsiElement) psiReference);

            if (caller == null) {
                continue;
            }

            incrementableSet.increment(new SourceTargetPair(caller, callee));
        }
    }
    return incrementableSet;
}
 
Example #2
Source File: References.java    From intellij-reference-diagram with Apache License 2.0 4 votes vote down vote up
public IncrementableSet<SourceTargetPair> createRelationships(Collection<? extends DiagramNode<PsiElement>> nodes, Project project) {
    IncrementableSet<SourceTargetPair> incrementableSet = new IncrementableSet<>();

    for (DiagramNode<PsiElement> node : nodes) {
        PsiElement callee = node.getIdentifyingElement();


        if (callee instanceof PsiJavaFile) {
            PsiClass[] classes = ((PsiJavaFile) callee).getClasses();
            for (PsiClass psiClass : classes) {
                Collection<PsiReference> references = ReferencesSearch.search(psiClass, GlobalSearchScope.projectScope(project)).findAll();

                for (PsiReference psiReference : references) {
                    if (!(psiReference instanceof CompositePsiElement)) {
                        continue;
                    }
                    if (((CompositePsiElement) psiReference).getParent() instanceof PsiImportStatement) {
                        // don't count import statements
                        continue;
                    }
                    PsiElement caller = ((CompositePsiElement) psiReference).getContainingFile();

                    if (caller == null) {
                        continue;
                    }

                    FQN callerFqn = PsiUtils.getFqn(caller);

                    if (callerFqn instanceof Hierarchically) {
                        Hierarchically calleeH = (Hierarchically) PsiUtils.getFqn(callee);
                        Hierarchically callerH = (Hierarchically) callerFqn;
                        if (calleeH.samePackage(callerH)) {
                            incrementableSet.increment(new SourceTargetPair(caller, callee));
                        } else if (callerH.sameHierarchy(calleeH)) {
                            String accumulationPackage = calleeH.getNextHierarchyTowards(callerH);
                            PsiElement accumulator = PsiUtils.getPsiJavaDirectory(accumulationPackage, project);
                            incrementableSet.increment(new SourceTargetPair(accumulator, callee));
                        }
                    }
                }

            }
        }
    }
    return incrementableSet;
}
 
Example #3
Source File: PsiUtils.java    From intellij-reference-diagram with Apache License 2.0 4 votes vote down vote up
@Nullable
public static PsiElement getRootPsiElement(PsiClass psiClass, CompositePsiElement psiElement) {
    return getRootPsiElementWithStack(psiClass, psiElement, new LinkedList<PsiElement>());
}