Search in sources :

Example 6 with DartComponentName

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

the class DartClassContributor method getItemsByName.

@NotNull
@Override
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
    final GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
    final Collection<DartComponentName> result = DartClassIndex.getItemsByName(name, project, scope);
    if (result.size() == 0) {
        return NavigationItem.EMPTY_NAVIGATION_ITEM_ARRAY;
    }
    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 7 with DartComponentName

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

the class DartServerImplementationsMarkerProvider method createMarkerMember.

@NotNull
private static LineMarkerInfo createMarkerMember(@NotNull final DartComponentName name) {
    final VirtualFile file = name.getContainingFile().getVirtualFile();
    final int nameOffset = name.getTextRange().getStartOffset();
    return new LineMarkerInfo<>(name, name.getTextRange(), AllIcons.Gutter.OverridenMethod, Pass.LINE_MARKERS, element -> DaemonBundle.message("method.is.overridden.too.many"), (GutterIconNavigationHandler<PsiElement>) (e, elt) -> {
        final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(name.getProject()).search_getTypeHierarchy(file, nameOffset, false);
        if (items.isEmpty()) {
            return;
        }
        final List<DartComponent> components = DartInheritorsSearcher.getSubMembers(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
        PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), DaemonBundle.message("navigation.title.overrider.method", name.getName(), components.size()), "Overriding methods of " + name.getName(), new DefaultPsiElementCellRenderer());
    }, GutterIconRenderer.Alignment.RIGHT);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartResolveUtil(com.jetbrains.lang.dart.util.DartResolveUtil) AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) DartInheritorsSearcher(com.jetbrains.lang.dart.ide.actions.DartInheritorsSearcher) VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) DartServerData(com.jetbrains.lang.dart.analyzer.DartServerData) PsiElementListNavigator(com.intellij.codeInsight.daemon.impl.PsiElementListNavigator) Collection(java.util.Collection) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) 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) PsiElement(com.intellij.psi.PsiElement) LineMarkerProvider(com.intellij.codeInsight.daemon.LineMarkerProvider) NotNull(org.jetbrains.annotations.NotNull) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with DartComponentName

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

the class DartServerImplementationsMarkerProvider method createMarkerClass.

@NotNull
private static LineMarkerInfo createMarkerClass(@NotNull final DartComponentName name) {
    final VirtualFile file = name.getContainingFile().getVirtualFile();
    final int nameOffset = name.getTextRange().getStartOffset();
    return new LineMarkerInfo<>(name, name.getTextRange(), AllIcons.Gutter.OverridenMethod, Pass.LINE_MARKERS, element -> DaemonBundle.message("class.is.subclassed.too.many"), (GutterIconNavigationHandler<PsiElement>) (e, elt) -> {
        final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(name.getProject()).search_getTypeHierarchy(file, nameOffset, false);
        if (items.isEmpty()) {
            return;
        }
        final List<DartComponent> components = DartInheritorsSearcher.getSubClasses(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
        PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), DaemonBundle.message("navigation.title.subclass", name.getName(), components.size(), ""), "Subclasses of " + name.getName(), new DefaultPsiElementCellRenderer());
    }, GutterIconRenderer.Alignment.RIGHT);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartResolveUtil(com.jetbrains.lang.dart.util.DartResolveUtil) AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) DartInheritorsSearcher(com.jetbrains.lang.dart.ide.actions.DartInheritorsSearcher) VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) DartServerData(com.jetbrains.lang.dart.analyzer.DartServerData) PsiElementListNavigator(com.intellij.codeInsight.daemon.impl.PsiElementListNavigator) Collection(java.util.Collection) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) 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) PsiElement(com.intellij.psi.PsiElement) LineMarkerProvider(com.intellij.codeInsight.daemon.LineMarkerProvider) NotNull(org.jetbrains.annotations.NotNull) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with DartComponentName

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

the class DartClassIndex method getItemsByName.

public static List<DartComponentName> getItemsByName(String name, Project project, GlobalSearchScope searchScope) {
    final Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(DART_CLASS_INDEX, name, searchScope);
    final Set<DartComponentName> result = new THashSet<>();
    for (VirtualFile vFile : files) {
        final PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
        for (PsiElement root : DartResolveUtil.findDartRoots(psiFile)) {
            for (DartClass component : DartResolveUtil.getClassDeclarations(root)) {
                if (name.equals(component.getName())) {
                    result.add(component.getComponentName());
                }
            }
        }
    }
    return new ArrayList<>(result);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartClass(com.jetbrains.lang.dart.psi.DartClass) PsiFile(com.intellij.psi.PsiFile) THashSet(gnu.trove.THashSet) PsiElement(com.intellij.psi.PsiElement)

Example 10 with DartComponentName

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

the class DartServerResolverTest method getPresentableElementPosition.

@NotNull
private static String getPresentableElementPosition(@NotNull final CodeInsightTestFixture fixture, @Nullable final PsiElement element) {
    if (element == null)
        return "";
    final StringBuilder buf = new StringBuilder(element.getText());
    DartComponent component = PsiTreeUtil.getParentOfType(element, DartComponent.class);
    while (component != null) {
        final DartComponentName componentName = component.getComponentName();
        if (componentName != null && componentName != element) {
            buf.insert(0, component.getName() + " -> ");
        }
        component = PsiTreeUtil.getParentOfType(component, DartComponent.class);
    }
    String path = element instanceof PsiDirectoryImpl ? ((PsiDirectoryImpl) element).getVirtualFile().getPath() : element.getContainingFile().getVirtualFile().getPath();
    final String contentRoot = ModuleRootManager.getInstance(fixture.getModule()).getContentRoots()[0].getPath();
    if (path.equals(contentRoot))
        path = "[content root]";
    final String contentRootWithSlash = contentRoot + "/";
    path = StringUtil.trimStart(path, contentRootWithSlash);
    final DartSdk sdk = DartSdk.getDartSdk(element.getProject());
    if (sdk != null && path.startsWith(sdk.getHomePath()))
        path = "[Dart SDK]" + path.substring(sdk.getHomePath().length());
    if (buf.length() > 0)
        buf.insert(0, " -> ");
    buf.insert(0, path);
    return buf.toString();
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) PsiDirectoryImpl(com.intellij.psi.impl.file.PsiDirectoryImpl) NotNull(org.jetbrains.annotations.NotNull)

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