Search in sources :

Example 1 with DartComponent

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

the class DartServerOverrideMarkerProvider method createOverrideMarker.

@Nullable
private static LineMarkerInfo createOverrideMarker(DartComponentName componentName) {
    final VirtualFile virtualFile = componentName.getContainingFile().getVirtualFile();
    if (virtualFile == null || !virtualFile.isInLocalFileSystem()) {
        return null;
    }
    final List<DartServerData.DartOverrideMember> overrideMembers = DartAnalysisServerService.getInstance(componentName.getProject()).getOverrideMembers(virtualFile);
    final Project project = componentName.getProject();
    final int nameOffset = componentName.getTextRange().getStartOffset();
    DartComponent superclassComponent = null;
    List<DartComponent> interfaceComponents = Lists.newArrayList();
    for (DartServerData.DartOverrideMember overrideMember : overrideMembers) {
        if (overrideMember.getOffset() == nameOffset) {
            final OverriddenMember member = overrideMember.getSuperclassMember();
            superclassComponent = member == null ? null : DartHierarchyUtil.findDartComponent(project, member.getElement().getLocation());
            if (overrideMember.getInterfaceMembers() != null) {
                for (OverriddenMember overriddenMember : overrideMember.getInterfaceMembers()) {
                    addDartComponent(interfaceComponents, project, overriddenMember);
                }
            }
        }
    }
    return tryCreateOverrideMarker(componentName, superclassComponent, interfaceComponents);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartServerData(com.jetbrains.lang.dart.analyzer.DartServerData) OverriddenMember(org.dartlang.analysis.server.protocol.OverriddenMember) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with DartComponent

use of com.jetbrains.lang.dart.psi.DartComponent 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 3 with DartComponent

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

the class BaseCreateMethodsFix method getElementsToProcess.

@NotNull
public Set<T> getElementsToProcess() {
    //noinspection unchecked,SuspiciousToArrayCall
    final T[] objects = (T[]) elementsToProcess.toArray(new DartComponent[elementsToProcess.size()]);
    final Comparator<T> tComparator = Comparator.comparingInt(o -> o.getTextRange().getStartOffset());
    final int size = elementsToProcess.size();
    final LinkedHashSet<T> result = new LinkedHashSet<>(size);
    final List<T> objectsFromSameFile = new ArrayList<>();
    PsiFile containingFile = null;
    for (int i = 0; i < size; ++i) {
        final T object = objects[i];
        final PsiFile currentContainingFile = object.getContainingFile();
        if (currentContainingFile != containingFile) {
            if (containingFile != null) {
                Collections.sort(objectsFromSameFile, tComparator);
                result.addAll(objectsFromSameFile);
                objectsFromSameFile.clear();
            }
            containingFile = currentContainingFile;
        }
        objectsFromSameFile.add(object);
    }
    Collections.sort(objectsFromSameFile, tComparator);
    result.addAll(objectsFromSameFile);
    elementsToProcess.clear();
    elementsToProcess.addAll(result);
    return elementsToProcess;
}
Also used : DartComponent(com.jetbrains.lang.dart.psi.DartComponent) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with DartComponent

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

the class BaseDartGenerateHandler method invoke.

public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file, final int offset) {
    final DartClass dartClass = PsiTreeUtil.getParentOfType(file.findElementAt(offset), DartClassDefinition.class);
    if (dartClass == null)
        return;
    final List<DartComponent> candidates = new ArrayList<>();
    collectCandidates(dartClass, candidates);
    List<DartNamedElementNode> selectedElements = Collections.emptyList();
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        selectedElements = ContainerUtil.map(candidates, DartNamedElementNode::new);
    } else if (!candidates.isEmpty()) {
        final MemberChooser<DartNamedElementNode> chooser = createMemberChooserDialog(project, dartClass, candidates, getTitle());
        chooser.show();
        if (chooser.getExitCode() != DialogWrapper.OK_EXIT_CODE)
            return;
        selectedElements = chooser.getSelectedElements();
    }
    doInvoke(project, editor, file, selectedElements, createFix(dartClass));
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartNamedElementNode(com.jetbrains.lang.dart.ide.DartNamedElementNode) MemberChooser(com.intellij.ide.util.MemberChooser)

Example 5 with DartComponent

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

Aggregations

DartComponent (com.jetbrains.lang.dart.psi.DartComponent)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 PsiElement (com.intellij.psi.PsiElement)8 DartClass (com.jetbrains.lang.dart.psi.DartClass)8 NotNull (org.jetbrains.annotations.NotNull)8 TypeHierarchyItem (org.dartlang.analysis.server.protocol.TypeHierarchyItem)7 DartComponentName (com.jetbrains.lang.dart.psi.DartComponentName)6 Template (com.intellij.codeInsight.template.Template)4 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)4 DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)4 DartServerData (com.jetbrains.lang.dart.analyzer.DartServerData)4 DartResolveUtil (com.jetbrains.lang.dart.util.DartResolveUtil)4 List (java.util.List)4 Nullable (org.jetbrains.annotations.Nullable)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