Search in sources :

Example 1 with ComponentNameScopeProcessor

use of com.jetbrains.lang.dart.resolve.ComponentNameScopeProcessor in project intellij-plugins by JetBrains.

the class DartRefactoringUtil method collectUsedComponents.

public static Set<DartComponentName> collectUsedComponents(PsiElement context) {
    final Set<DartComponentName> usedComponentNames = new THashSet<>();
    PsiTreeUtil.treeWalkUp(new ComponentNameScopeProcessor(usedComponentNames), context, null, ResolveState.initial());
    return usedComponentNames;
}
Also used : ComponentNameScopeProcessor(com.jetbrains.lang.dart.resolve.ComponentNameScopeProcessor) THashSet(gnu.trove.THashSet)

Example 2 with ComponentNameScopeProcessor

use of com.jetbrains.lang.dart.resolve.ComponentNameScopeProcessor in project intellij-plugins by JetBrains.

the class DartStructureViewElement method getChildrenBase.

@NotNull
@Override
public Collection<StructureViewTreeElement> getChildrenBase() {
    final NavigatablePsiElement element = getElement();
    final List<StructureViewTreeElement> result = new ArrayList<>();
    if (element instanceof DartFile || element instanceof DartEmbeddedContent) {
        THashSet<DartComponentName> componentNames = new THashSet<>();
        DartPsiCompositeElementImpl.processDeclarationsImpl(element, new ComponentNameScopeProcessor(componentNames), ResolveState.initial(), null);
        for (DartComponentName componentName : componentNames) {
            PsiElement parent = componentName.getParent();
            if (parent instanceof DartComponent) {
                result.add(new DartStructureViewElement((DartComponent) parent));
            }
        }
    } else if (element instanceof DartClass) {
        for (DartComponent subNamedComponent : DartResolveUtil.getNamedSubComponents((DartClass) element)) {
            result.add(new DartStructureViewElement(subNamedComponent));
        }
    }
    Collections.sort(result, (o1, o2) -> {
        PsiElement element1, element2;
        if (o1 instanceof DartStructureViewElement && o2 instanceof DartStructureViewElement && (element1 = ((DartStructureViewElement) o1).getElement()) != null && (element2 = ((DartStructureViewElement) o2).getElement()) != null) {
            return element1.getTextRange().getStartOffset() - element2.getTextRange().getStartOffset();
        }
        return 0;
    });
    return result;
}
Also used : THashSet(gnu.trove.THashSet) ComponentNameScopeProcessor(com.jetbrains.lang.dart.resolve.ComponentNameScopeProcessor) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) PsiElement(com.intellij.psi.PsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ComponentNameScopeProcessor (com.jetbrains.lang.dart.resolve.ComponentNameScopeProcessor)2 THashSet (gnu.trove.THashSet)2 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)1 PsiElement (com.intellij.psi.PsiElement)1 NotNull (org.jetbrains.annotations.NotNull)1