Search in sources :

Example 1 with DartComponentType

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

the class DartIndexUtil method indexFileRoots.

private static DartFileIndexData indexFileRoots(PsiFile psiFile) {
    DartFileIndexData result = new DartFileIndexData();
    result.setLibraryName(DartResolveUtil.getLibraryName(psiFile));
    result.setIsPart(PsiTreeUtil.getChildOfType(psiFile, DartPartOfStatement.class) != null);
    for (PsiElement rootElement : DartResolveUtil.findDartRoots(psiFile)) {
        PsiElement[] children = rootElement.getChildren();
        for (DartComponentName componentName : DartControlFlowUtil.getSimpleDeclarations(children, null, false)) {
            final String name = componentName.getName();
            if (name == null) {
                continue;
            }
            result.addSymbol(name);
            PsiElement parent = componentName.getParent();
            final DartComponentType type = DartComponentType.typeOf(parent);
            if (type != null) {
                result.addComponentInfo(name, new DartComponentInfo(type, result.getLibraryName()));
            }
            if (parent instanceof DartClass) {
                result.addClassName(name);
                if (((DartClass) parent).isEnum()) {
                    for (DartEnumConstantDeclaration enumConstantDeclaration : ((DartClass) parent).getEnumConstantDeclarationList()) {
                        result.addSymbol(enumConstantDeclaration.getName());
                    }
                } else {
                    for (DartComponent subComponent : DartResolveUtil.getNamedSubComponents((DartClass) parent)) {
                        result.addSymbol(subComponent.getName());
                    }
                }
            }
        }
        for (PsiElement child : children) {
            if (child instanceof DartImportOrExportStatement) {
                processImportOrExportStatement(result, (DartImportOrExportStatement) child);
            }
            if (child instanceof DartPartStatement) {
                result.addPartUri(((DartPartStatement) child).getUriString());
            }
        }
    }
    return result;
}
Also used : DartComponentType(com.jetbrains.lang.dart.DartComponentType) PsiElement(com.intellij.psi.PsiElement)

Example 2 with DartComponentType

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

the class DartInheritorsSearcher method processQuery.

@Override
public void processQuery(@NotNull final DefinitionsScopedSearch.SearchParameters parameters, @NotNull final Processor<PsiElement> consumer) {
    final Ref<VirtualFile> fileRef = Ref.create();
    final Ref<Integer> offsetRef = Ref.create();
    final Ref<DartComponentType> componentTypeRef = Ref.create();
    prepare(parameters, fileRef, offsetRef, componentTypeRef);
    if (fileRef.isNull() || offsetRef.isNull() || componentTypeRef.isNull())
        return;
    ApplicationManager.getApplication().runReadAction(() -> {
        final List<TypeHierarchyItem> hierarchyItems = CachedValuesManager.getCachedValue(parameters.getElement(), () -> {
            final DartAnalysisServerService das = DartAnalysisServerService.getInstance(parameters.getElement().getProject());
            final List<TypeHierarchyItem> items = das.search_getTypeHierarchy(fileRef.get(), offsetRef.get(), false);
            return new CachedValueProvider.Result<>(items, PsiModificationTracker.MODIFICATION_COUNT);
        });
        final List<DartComponent> components = componentTypeRef.get() == DartComponentType.CLASS ? getSubClasses(parameters.getElement().getProject(), parameters.getScope(), hierarchyItems) : getSubMembers(parameters.getElement().getProject(), parameters.getScope(), hierarchyItems);
        for (DartComponent component : components) {
            consumer.process(component);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartComponentType(com.jetbrains.lang.dart.DartComponentType) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)

Example 3 with DartComponentType

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

the class DartInheritorsSearcher method prepare.

private static void prepare(@NotNull final DefinitionsScopedSearch.SearchParameters parameters, @NotNull final Ref<VirtualFile> fileRef, @NotNull final Ref<Integer> offsetRef, @NotNull final Ref<DartComponentType> componentTypeRef) {
    ApplicationManager.getApplication().runReadAction(() -> {
        final PsiElement element = parameters.getElement();
        if (element.getLanguage() != DartLanguage.INSTANCE)
            return;
        final DartComponentType componentType = DartComponentType.typeOf(element);
        if (componentType != DartComponentType.CLASS && componentType != DartComponentType.METHOD && componentType != DartComponentType.OPERATOR) {
            return;
        }
        final DartComponentName componentName = element instanceof DartComponentName ? (DartComponentName) element : element instanceof DartComponent ? ((DartComponent) element).getComponentName() : null;
        final VirtualFile file = componentName == null ? null : DartResolveUtil.getRealVirtualFile(componentName.getContainingFile());
        if (file != null) {
            fileRef.set(file);
            offsetRef.set(componentName.getTextRange().getStartOffset());
            componentTypeRef.set(componentType);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartComponentType(com.jetbrains.lang.dart.DartComponentType) PsiElement(com.intellij.psi.PsiElement)

Example 4 with DartComponentType

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

the class DartParameterInfoHandler method getParametersForLookup.

@Override
public Object[] getParametersForLookup(LookupElement item, ParameterInfoContext context) {
    final Object o = item.getObject();
    if (o instanceof PsiElement) {
        final PsiElement element = (PsiElement) o;
        final DartComponentType type = DartComponentType.typeOf(element.getParent());
        if (type == DartComponentType.METHOD || type == DartComponentType.CONSTRUCTOR) {
            return new Object[] { element.getParent() };
        }
    }
    return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
Also used : DartComponentType(com.jetbrains.lang.dart.DartComponentType) PsiElement(com.intellij.psi.PsiElement)

Example 5 with DartComponentType

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

the class DartComponentInfoExternalizer method save.

@Override
public void save(@NotNull final DataOutput out, @NotNull final DartComponentInfo componentInfo) throws IOException {
    final DartComponentType dartComponentType = componentInfo.getComponentType();
    final int key = dartComponentType == null ? -1 : dartComponentType.getKey();
    DataInputOutputUtil.writeINT(out, key);
    final String libraryName = componentInfo.getLibraryName();
    out.writeBoolean(libraryName != null);
    if (libraryName != null) {
        IOUtil.writeUTF(out, libraryName);
    }
}
Also used : DartComponentType(com.jetbrains.lang.dart.DartComponentType)

Aggregations

DartComponentType (com.jetbrains.lang.dart.DartComponentType)12 PsiElement (com.intellij.psi.PsiElement)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 DartComponent (com.jetbrains.lang.dart.psi.DartComponent)2 Nullable (org.jetbrains.annotations.Nullable)2 HighlightUsagesDescriptionLocation (com.intellij.codeInsight.highlighting.HighlightUsagesDescriptionLocation)1 ItemPresentation (com.intellij.navigation.ItemPresentation)1 RowIcon (com.intellij.ui.RowIcon)1 DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)1 DartComponentName (com.jetbrains.lang.dart.psi.DartComponentName)1 TypeHierarchyItem (org.dartlang.analysis.server.protocol.TypeHierarchyItem)1