Search in sources :

Example 1 with LineMarkerInfo

use of com.intellij.codeInsight.daemon.LineMarkerInfo in project intellij-community by JetBrains.

the class PyExecuteFileLineMarkerProvider method collectSlowLineMarkers.

@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
    if (elements.isEmpty()) {
        return;
    }
    Optional<PsiElement> psiElement = elements.stream().filter((element) -> element instanceof PsiFile).findFirst();
    if (!psiElement.isPresent())
        return;
    final PsiElement file = psiElement.get();
    final RunContextAction runAction = new PyStudyRunContextAction(DefaultRunExecutor.getRunExecutorInstance());
    final PyExecuteFileExtensionPoint[] extensions = ApplicationManager.getApplication().getExtensions(PyExecuteFileExtensionPoint.EP_NAME);
    final List<AnAction> actions = new ArrayList<>();
    final DefaultActionGroup group = new DefaultActionGroup();
    if (PlatformUtils.isPyCharmEducational()) {
        group.add(runAction);
    }
    for (PyExecuteFileExtensionPoint extension : extensions) {
        AnAction action = extension.getRunAction();
        if (action != null && extension.accept(file.getProject())) {
            actions.add(action);
            group.add(action);
        }
    }
    if (actions.isEmpty() && !PlatformUtils.isPyCharmEducational()) {
        return;
    }
    Icon icon = PlatformUtils.isPyCharmEducational() ? AllIcons.Actions.Execute : actions.get(0).getTemplatePresentation().getIcon();
    final LineMarkerInfo<PsiElement> markerInfo = new LineMarkerInfo<PsiElement>(file, file.getTextRange(), icon, Pass.LINE_MARKERS, e -> {
        String text = "Execute '" + e.getContainingFile().getName() + "'";
        return PlatformUtils.isPyCharmEducational() ? text : actions.get(0).getTemplatePresentation().getText();
    }, null, GutterIconRenderer.Alignment.RIGHT) {

        @Nullable
        @Override
        public GutterIconRenderer createGutterRenderer() {
            return new LineMarkerGutterIconRenderer<PsiElement>(this) {

                @Override
                public AnAction getClickAction() {
                    return PlatformUtils.isPyCharmEducational() ? runAction : actions.get(0);
                }

                @Nullable
                @Override
                public ActionGroup getPopupMenuActions() {
                    if (!PlatformUtils.isPyCharmEducational() && actions.isEmpty()) {
                        return null;
                    }
                    if (actions.size() == 1) {
                        return null;
                    }
                    return group;
                }
            };
        }
    };
    result.add(markerInfo);
}
Also used : AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) Collection(java.util.Collection) PlatformUtils(com.intellij.util.PlatformUtils) AnAction(com.intellij.openapi.actionSystem.AnAction) RunContextAction(com.intellij.execution.actions.RunContextAction) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Pass(com.intellij.codeHighlighting.Pass) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) ApplicationManager(com.intellij.openapi.application.ApplicationManager) PsiFile(com.intellij.psi.PsiFile) Optional(java.util.Optional) LineMarkerProvider(com.intellij.codeInsight.daemon.LineMarkerProvider) NotNull(org.jetbrains.annotations.NotNull) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) javax.swing(javax.swing) RunContextAction(com.intellij.execution.actions.RunContextAction) ArrayList(java.util.ArrayList) AnAction(com.intellij.openapi.actionSystem.AnAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 2 with LineMarkerInfo

use of com.intellij.codeInsight.daemon.LineMarkerInfo in project intellij-community by JetBrains.

the class PyLineMarkerProvider method getMethodMarker.

@Nullable
private static LineMarkerInfo<PsiElement> getMethodMarker(final PsiElement element, final PyFunction function) {
    if (PyNames.INIT.equals(function.getName())) {
        return null;
    }
    final TypeEvalContext context = TypeEvalContext.codeAnalysis(element.getProject(), (function != null ? function.getContainingFile() : null));
    final PsiElement superMethod = PySuperMethodsSearch.search(function, context).findFirst();
    if (superMethod != null) {
        PyClass superClass = null;
        if (superMethod instanceof PyFunction) {
            superClass = ((PyFunction) superMethod).getContainingClass();
        }
        // TODO: show "implementing" instead of "overriding" icon for Python implementations of Java interface methods
        return new LineMarkerInfo<PsiElement>(element, element.getTextRange().getStartOffset(), AllIcons.Gutter.OverridingMethod, Pass.LINE_MARKERS, superClass == null ? null : new TooltipProvider("Overrides method in " + superClass.getName()), ourSuperMethodNavigator);
    }
    return null;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) PyFunction(com.jetbrains.python.psi.PyFunction) TypeEvalContext(com.jetbrains.python.psi.types.TypeEvalContext) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with LineMarkerInfo

use of com.intellij.codeInsight.daemon.LineMarkerInfo in project intellij-community by JetBrains.

the class PyLineMarkerProvider method getAttributeMarker.

@Nullable
private static LineMarkerInfo<PsiElement> getAttributeMarker(PyTargetExpression element) {
    final String name = element.getReferencedName();
    if (name == null) {
        return null;
    }
    PyClass containingClass = PsiTreeUtil.getParentOfType(element, PyClass.class);
    if (containingClass == null)
        return null;
    for (PyClass ancestor : containingClass.getAncestorClasses(TypeEvalContext.codeAnalysis(element.getProject(), element.getContainingFile()))) {
        final PyTargetExpression ancestorAttr = ancestor.findClassAttribute(name, false, null);
        if (ancestorAttr != null) {
            return new LineMarkerInfo<PsiElement>(element, element.getTextRange().getStartOffset(), AllIcons.Gutter.OverridingMethod, Pass.LINE_MARKERS, new TooltipProvider("Overrides attribute in " + ancestor.getName()), ourSuperAttributeNavigator);
        }
    }
    return null;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) PyTargetExpression(com.jetbrains.python.psi.PyTargetExpression) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with LineMarkerInfo

use of com.intellij.codeInsight.daemon.LineMarkerInfo in project intellij-community by JetBrains.

the class GroovyLineMarkerProvider method getLineMarkerInfo.

@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
    final PsiElement parent = element.getParent();
    if (parent instanceof PsiNameIdentifierOwner) {
        if (parent instanceof GrField && element == ((GrField) parent).getNameIdentifierGroovy()) {
            for (GrAccessorMethod method : GroovyPropertyUtils.getFieldAccessors((GrField) parent)) {
                MethodSignatureBackedByPsiMethod superSignature = SuperMethodsSearch.search(method, null, true, false).findFirst();
                if (superSignature != null) {
                    PsiMethod superMethod = superSignature.getMethod();
                    boolean overrides = method.hasModifierProperty(PsiModifier.ABSTRACT) == superMethod.hasModifierProperty(PsiModifier.ABSTRACT) || superMethod.getBody() != null && GrTraitUtil.isTrait(superMethod.getContainingClass());
                    final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
                    final MarkerType type = GroovyMarkerTypes.OVERRIDING_PROPERTY_TYPE;
                    return new LineMarkerInfo<>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, type.getTooltip(), type.getNavigationHandler(), GutterIconRenderer.Alignment.LEFT);
                }
            }
        } else if (parent instanceof GrMethod && element == ((GrMethod) parent).getNameIdentifierGroovy() && hasSuperMethods((GrMethod) element.getParent())) {
            final Icon icon = AllIcons.Gutter.OverridingMethod;
            final MarkerType type = GroovyMarkerTypes.GR_OVERRIDING_METHOD;
            return new LineMarkerInfo<>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, type.getTooltip(), type.getNavigationHandler(), GutterIconRenderer.Alignment.LEFT);
        }
    }
    //need to draw method separator above docComment
    if (myDaemonSettings.SHOW_METHOD_SEPARATORS && element.getFirstChild() == null) {
        PsiElement element1 = element;
        boolean isMember = false;
        while (element1 != null && !(element1 instanceof PsiFile) && element1.getPrevSibling() == null) {
            element1 = element1.getParent();
            if (element1 instanceof PsiMember || element1 instanceof GrVariableDeclarationImpl) {
                isMember = true;
                break;
            }
        }
        if (isMember && !(element1 instanceof PsiAnonymousClass || element1.getParent() instanceof PsiAnonymousClass)) {
            PsiFile file = element1.getContainingFile();
            Document document = file == null ? null : PsiDocumentManager.getInstance(file.getProject()).getLastCommittedDocument(file);
            boolean drawSeparator = false;
            if (document != null) {
                CharSequence documentChars = document.getCharsSequence();
                int category = getGroovyCategory(element1, documentChars);
                for (PsiElement child = element1.getPrevSibling(); child != null; child = child.getPrevSibling()) {
                    int category1 = getGroovyCategory(child, documentChars);
                    if (category1 == 0)
                        continue;
                    drawSeparator = category != 1 || category1 != 1;
                    break;
                }
            }
            if (drawSeparator) {
                GrDocComment comment = null;
                if (element1 instanceof GrDocCommentOwner) {
                    comment = ((GrDocCommentOwner) element1).getDocComment();
                }
                LineMarkerInfo info = new LineMarkerInfo<>(element, comment != null ? comment.getTextRange() : element.getTextRange(), null, Pass.LINE_MARKERS, FunctionUtil.<Object, String>nullConstant(), null, GutterIconRenderer.Alignment.RIGHT);
                EditorColorsScheme scheme = myColorsManager.getGlobalScheme();
                info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
                info.separatorPlacement = SeparatorPlacement.TOP;
                return info;
            }
        }
    }
    return null;
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) MethodSignatureBackedByPsiMethod(com.intellij.psi.util.MethodSignatureBackedByPsiMethod) MethodSignatureBackedByPsiMethod(com.intellij.psi.util.MethodSignatureBackedByPsiMethod) GrDocCommentOwner(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) Document(com.intellij.openapi.editor.Document) GrDocComment(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment) GrAccessorMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) MarkerType(com.intellij.codeInsight.daemon.impl.MarkerType) GrVariableDeclarationImpl(org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrVariableDeclarationImpl) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 5 with LineMarkerInfo

use of com.intellij.codeInsight.daemon.LineMarkerInfo in project intellij-elixir by KronicDeth.

the class CallDefinition method getLineMarkerInfo.

@Nullable
private LineMarkerInfo getLineMarkerInfo(@NotNull Call call) {
    LineMarkerInfo lineMarkerInfo = null;
    if (daemonCodeAnalyzerSettings.SHOW_METHOD_SEPARATORS && CallDefinitionClause.is(call)) {
        Call previousCallDefinitionClause = siblingCallDefinitionClause(call, PREVIOUS_SIBLING);
        boolean firstClause;
        if (previousCallDefinitionClause == null) {
            firstClause = true;
        } else {
            Pair<String, IntRange> callNameArityRange = nameArityRange(call);
            if (callNameArityRange != null) {
                Pair<String, IntRange> previousNameArityRange = nameArityRange(previousCallDefinitionClause);
                firstClause = previousNameArityRange == null || !previousNameArityRange.equals(callNameArityRange);
            } else {
                firstClause = true;
            }
        }
        if (firstClause) {
            PsiElement previousExpression = previousSiblingExpression(call);
            if (previousExpression instanceof AtUnqualifiedNoParenthesesCall) {
                AtUnqualifiedNoParenthesesCall previousModuleAttributeDefinition = (AtUnqualifiedNoParenthesesCall) previousExpression;
                String moduleAttributeName = moduleAttributeName(previousModuleAttributeDefinition);
                if (moduleAttributeName.equals("@doc")) {
                    firstClause = false;
                } else if (moduleAttributeName.equals("@spec")) {
                    Pair<String, IntRange> callNameArityRange = nameArityRange(call);
                    if (callNameArityRange != null) {
                        Pair<String, Integer> specNameArity = moduleAttributeNameArity(previousModuleAttributeDefinition);
                        if (specNameArity != null) {
                            Integer specArity = specNameArity.second;
                            IntRange callArityRange = callNameArityRange.second;
                            if (callArityRange.containsInteger(specArity)) {
                                firstClause = false;
                            }
                        }
                    }
                }
            }
        }
        if (firstClause) {
            lineMarkerInfo = callDefinitionSeparator(call);
        }
    }
    return lineMarkerInfo;
}
Also used : LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) Call(org.elixir_lang.psi.call.Call) AtUnqualifiedNoParenthesesCall(org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall) AtUnqualifiedNoParenthesesCall(org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall) IntRange(org.apache.commons.lang.math.IntRange) Pair(com.intellij.openapi.util.Pair) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)44 PsiElement (com.intellij.psi.PsiElement)17 Nullable (org.jetbrains.annotations.Nullable)12 NotNull (org.jetbrains.annotations.NotNull)7 Pass (com.intellij.codeHighlighting.Pass)5 GutterIconNavigationHandler (com.intellij.codeInsight.daemon.GutterIconNavigationHandler)5 AllIcons (com.intellij.icons.AllIcons)5 Document (com.intellij.openapi.editor.Document)5 GutterIconRenderer (com.intellij.openapi.editor.markup.GutterIconRenderer)5 Collection (java.util.Collection)5 LineMarkerProvider (com.intellij.codeInsight.daemon.LineMarkerProvider)4 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)4 Project (com.intellij.openapi.project.Project)4 List (java.util.List)4 javax.swing (javax.swing)4 DaemonBundle (com.intellij.codeInsight.daemon.DaemonBundle)3 PsiElementListNavigator (com.intellij.codeInsight.daemon.impl.PsiElementListNavigator)3 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 GutterMark (com.intellij.codeInsight.daemon.GutterMark)2