Search in sources :

Example 6 with DartComponent

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

the class CreateConstructorFix method buildFunctionsText.

protected Template buildFunctionsText(TemplateManager templateManager, Set<DartComponent> elementsToProcess) {
    final Template template = templateManager.createTemplate(getClass().getName(), DART_TEMPLATE_GROUP);
    template.setToReformat(true);
    //noinspection ConstantConditions
    template.addTextSegment(myDartClass.getName());
    template.addTextSegment("(");
    for (Iterator<DartComponent> iterator = elementsToProcess.iterator(); iterator.hasNext(); ) {
        DartComponent component = iterator.next();
        template.addTextSegment("this.");
        //noinspection ConstantConditions
        template.addTextSegment(component.getName());
        if (iterator.hasNext()) {
            template.addTextSegment(",");
        }
    }
    template.addTextSegment(");");
    template.addEndVariable();
    // trailing space is removed when auto-reformatting, but it helps to enter line break if needed
    template.addTextSegment(" ");
    return template;
}
Also used : DartComponent(com.jetbrains.lang.dart.psi.DartComponent) Template(com.intellij.codeInsight.template.Template)

Example 7 with DartComponent

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

the class CreateEqualsAndHashcodeFix method buildFunctionsText.

protected Template buildFunctionsText(TemplateManager templateManager, @NotNull Set<DartComponent> elementsToProcess) {
    final Template template = templateManager.createTemplate(getClass().getName(), DART_TEMPLATE_GROUP);
    template.setToReformat(true);
    final boolean doInsertOverrideAnnotation = CodeStyleSettingsManager.getSettings(myDartClass.getProject()).INSERT_OVERRIDE_ANNOTATION;
    if (doInsertOverrideAnnotation) {
        template.addTextSegment("@override\n");
    }
    template.addTextSegment("bool operator==(Object other) =>\nidentical(this, other) ||\n");
    if (mySuperclassOverridesEqualEqualAndHashCode) {
        template.addTextSegment("super == other &&\n");
    }
    template.addTextSegment("other is " + myDartClass.getName() + " &&\n");
    template.addTextSegment("runtimeType == other.runtimeType");
    for (DartComponent component : elementsToProcess) {
        template.addTextSegment(" &&\n");
        template.addTextSegment(component.getName() + " == other." + component.getName());
    }
    template.addTextSegment(";\n");
    if (doInsertOverrideAnnotation) {
        template.addTextSegment("@override\n");
    }
    template.addTextSegment("int get hashCode => ");
    boolean firstItem = true;
    if (mySuperclassOverridesEqualEqualAndHashCode) {
        template.addTextSegment("\nsuper.hashCode");
        firstItem = false;
    }
    for (DartComponent component : elementsToProcess) {
        if (!firstItem) {
            template.addTextSegment(" ^\n");
        }
        template.addTextSegment(component.getName() + ".hashCode");
        firstItem = false;
    }
    if (!mySuperclassOverridesEqualEqualAndHashCode && elementsToProcess.isEmpty()) {
        template.addTextSegment("0");
    }
    template.addTextSegment(";\n");
    template.addEndVariable();
    // trailing space is removed when auto-reformatting, but it helps to enter line break if needed
    template.addTextSegment(" ");
    return template;
}
Also used : DartComponent(com.jetbrains.lang.dart.psi.DartComponent) Template(com.intellij.codeInsight.template.Template)

Example 8 with DartComponent

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

the class DartServerGotoSuperHandler method addSuperComponent.

private static void addSuperComponent(@NotNull Project project, List<DartComponent> supers, boolean isInClass, TypeHierarchyItem item) {
    // prepare Element for the current item
    final Element itemElement = isInClass ? item.getClassElement() : item.getMemberElement();
    if (itemElement == null) {
        return;
    }
    // ignore Object
    if (ElementKind.CLASS.equals(itemElement.getKind()) && "Object".equals(itemElement.getName())) {
        return;
    }
    // find the DartComponent
    final Location itemLocation = itemElement.getLocation();
    final DartComponent itemComponent = DartHierarchyUtil.findDartComponent(project, itemLocation);
    if (itemComponent != null) {
        supers.add(itemComponent);
    }
}
Also used : DartComponent(com.jetbrains.lang.dart.psi.DartComponent) PsiElement(com.intellij.psi.PsiElement) Element(org.dartlang.analysis.server.protocol.Element) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) Location(org.dartlang.analysis.server.protocol.Location)

Example 9 with DartComponent

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

the class DartServerGotoSuperHandler method invoke.

@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
    final PsiElement at = file.findElementAt(editor.getCaretModel().getOffset());
    final DartComponent inComponent = PsiTreeUtil.getParentOfType(at, DartComponent.class);
    final DartComponent inClass = PsiTreeUtil.getParentOfType(at, DartClass.class);
    if (inClass == null || inComponent == null || inComponent.getComponentName() == null) {
        return;
    }
    final boolean isInClass = inComponent instanceof DartClass;
    // ask for the super type hierarchy
    final VirtualFile virtualFile = file.getVirtualFile();
    final int offset = inComponent.getComponentName().getTextRange().getStartOffset();
    final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(project).search_getTypeHierarchy(virtualFile, offset, true);
    // build list of DartComponent(s)
    final List<DartComponent> supers = Lists.newArrayList();
    if (!items.isEmpty()) {
        TypeHierarchyItem seed = items.get(0);
        {
            final Integer superIndex = seed.getSuperclass();
            if (superIndex != null) {
                final TypeHierarchyItem superItem = items.get(superIndex);
                addSuperComponent(project, supers, isInClass, superItem);
            }
        }
        for (int superIndex : seed.getMixins()) {
            final TypeHierarchyItem superItem = items.get(superIndex);
            addSuperComponent(project, supers, isInClass, superItem);
        }
        for (int superIndex : seed.getInterfaces()) {
            final TypeHierarchyItem superItem = items.get(superIndex);
            addSuperComponent(project, supers, isInClass, superItem);
        }
    }
    // prepare the title
    final String title;
    if (isInClass) {
        title = DartBundle.message("goto.super.class.chooser.title");
    } else {
        title = CodeInsightBundle.message("goto.super.method.chooser.title");
    }
    // open DartComponent(s)
    final NavigatablePsiElement[] targets = DartResolveUtil.getComponentNameArray(supers);
    PsiElementListNavigator.openTargets(editor, targets, title, null, new DefaultPsiElementCellRenderer());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartClass(com.jetbrains.lang.dart.psi.DartClass) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) PsiElement(com.intellij.psi.PsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement)

Example 10 with DartComponent

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

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