Search in sources :

Example 1 with DartComponentName

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

the class DartServerOverrideMarkerProvider method tryCreateOverrideMarker.

@Nullable
private static LineMarkerInfo tryCreateOverrideMarker(@NotNull final DartComponentName componentName, @Nullable final DartComponent superclassComponent, @NotNull final List<DartComponent> interfaceComponents) {
    if (superclassComponent == null && interfaceComponents.isEmpty()) {
        return null;
    }
    final String name = componentName.getName();
    final boolean overrides;
    final DartComponent superComponent;
    if (superclassComponent != null) {
        overrides = true;
        superComponent = superclassComponent;
    } else {
        overrides = false;
        superComponent = interfaceComponents.iterator().next();
    }
    final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
    return new LineMarkerInfo<>(componentName, componentName.getTextRange(), icon, Pass.LINE_MARKERS, element -> {
        final DartClass superClass = PsiTreeUtil.getParentOfType(superComponent, DartClass.class);
        if (superClass == null)
            return "null";
        if (overrides) {
            return DartBundle.message(superclassComponent.isOperator() ? "overrides.operator.in" : "overrides.method.in", name, superClass.getName());
        }
        return DartBundle.message("implements.method.in", name, superClass.getName());
    }, (GutterIconNavigationHandler<PsiElement>) (e, elt) -> {
        List<DartComponent> superComponents = Lists.newArrayList();
        if (superclassComponent != null) {
            superComponents.add(superclassComponent);
        }
        superComponents.addAll(interfaceComponents);
        PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(superComponents), DaemonBundle.message("navigation.title.super.method", name), DaemonBundle.message("navigation.findUsages.title.super.method", name), new DefaultPsiElementCellRenderer());
    }, GutterIconRenderer.Alignment.LEFT);
}
Also used : DartResolveUtil(com.jetbrains.lang.dart.util.DartResolveUtil) DartClass(com.jetbrains.lang.dart.psi.DartClass) AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) Lists(com.google.common.collect.Lists) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DartHierarchyUtil(com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) DartServerData(com.jetbrains.lang.dart.analyzer.DartServerData) PsiElementListNavigator(com.intellij.codeInsight.daemon.impl.PsiElementListNavigator) OverriddenMember(org.dartlang.analysis.server.protocol.OverriddenMember) Collection(java.util.Collection) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartBundle(com.jetbrains.lang.dart.DartBundle) Pass(com.intellij.codeHighlighting.Pass) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) Nullable(org.jetbrains.annotations.Nullable) DaemonBundle(com.intellij.codeInsight.daemon.DaemonBundle) List(java.util.List) GutterIconNavigationHandler(com.intellij.codeInsight.daemon.GutterIconNavigationHandler) LineMarkerProvider(com.intellij.codeInsight.daemon.LineMarkerProvider) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartClass(com.jetbrains.lang.dart.psi.DartClass) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with DartComponentName

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

the class DartCalleeTreeStructure method getCallees.

private static void getCallees(@NotNull PsiElement element, @NotNull List<PsiElement> results) {
    DartComponentName name = (DartComponentName) element;
    DartComponent decl = (DartComponent) name.getParent();
    PsiFile file = decl.getContainingFile();
    if (file == null)
        return;
    VirtualFile vFile = file.getVirtualFile();
    List<DartNavigationRegion> navRegions = DartAnalysisServerService.getInstance(element.getProject()).analysis_getNavigation(vFile, decl.getTextOffset(), decl.getTextLength());
    if (navRegions == null)
        return;
    resolveReferences(decl, navRegions, results);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartNavigationRegion(com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion) PsiFile(com.intellij.psi.PsiFile)

Example 3 with DartComponentName

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

the class DartFilterByClassMacro method calculateResult.

@Override
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
    final PsiElement at = context.getPsiElementAtStartOffset();
    final Set<DartComponentName> variables = DartRefactoringUtil.collectUsedComponents(at);
    final List<DartComponentName> filtered = ContainerUtil.filter(variables, name -> {
        final PsiElement nameParent = name.getParent();
        if (nameParent instanceof DartClass) {
            return false;
        }
        final DartClassResolveResult result = DartResolveUtil.getDartClassResolveResult(nameParent);
        final DartClass dartClass = result.getDartClass();
        return dartClass != null && filter(dartClass);
    });
    return filtered.isEmpty() ? null : new PsiElementResult(filtered.iterator().next());
}
Also used : DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartClass(com.jetbrains.lang.dart.psi.DartClass) DartClassResolveResult(com.jetbrains.lang.dart.util.DartClassResolveResult) PsiElement(com.intellij.psi.PsiElement)

Example 4 with DartComponentName

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

the class DartSymbolContributor method getItemsByName.

@NotNull
@Override
public NavigationItem[] getItemsByName(@NotNull final String name, @NotNull final String pattern, @NotNull final Project project, final boolean includeNonProjectItems) {
    final GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
    final Collection<DartComponentName> result = DartSymbolIndex.getItemsByName(name, project, scope);
    return result.toArray(new NavigationItem[result.size()]);
}
Also used : DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with DartComponentName

use of com.jetbrains.lang.dart.psi.DartComponentName 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)

Aggregations

DartComponentName (com.jetbrains.lang.dart.psi.DartComponentName)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 PsiElement (com.intellij.psi.PsiElement)8 DartClass (com.jetbrains.lang.dart.psi.DartClass)6 DartComponent (com.jetbrains.lang.dart.psi.DartComponent)6 NotNull (org.jetbrains.annotations.NotNull)6 Project (com.intellij.openapi.project.Project)4 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 Pass (com.intellij.codeHighlighting.Pass)3 DaemonBundle (com.intellij.codeInsight.daemon.DaemonBundle)3 GutterIconNavigationHandler (com.intellij.codeInsight.daemon.GutterIconNavigationHandler)3 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)3 LineMarkerProvider (com.intellij.codeInsight.daemon.LineMarkerProvider)3 PsiElementListNavigator (com.intellij.codeInsight.daemon.impl.PsiElementListNavigator)3 AllIcons (com.intellij.icons.AllIcons)3 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)3 GutterIconRenderer (com.intellij.openapi.editor.markup.GutterIconRenderer)3 DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)3 DartServerData (com.jetbrains.lang.dart.analyzer.DartServerData)3 DartResolveUtil (com.jetbrains.lang.dart.util.DartResolveUtil)3