Search in sources :

Example 1 with GrVariableDeclarationImpl

use of org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrVariableDeclarationImpl 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 2 with GrVariableDeclarationImpl

use of org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrVariableDeclarationImpl in project intellij-community by JetBrains.

the class GroovyLineMarkerProvider method getGroovyCategory.

private static int getGroovyCategory(@NotNull PsiElement element, @NotNull CharSequence documentChars) {
    if (element instanceof GrVariableDeclarationImpl) {
        GrVariable[] variables = ((GrVariableDeclarationImpl) element).getVariables();
        if (variables.length == 1 && variables[0] instanceof GrField && variables[0].getInitializerGroovy() instanceof GrClosableBlock) {
            return 2;
        }
    }
    if (element instanceof GrField || element instanceof GrTypeParameter)
        return 1;
    if (element instanceof GrTypeDefinition || element instanceof GrClassInitializer)
        return 2;
    if (element instanceof GrMethod) {
        if (((GrMethod) element).hasModifierProperty(PsiModifier.ABSTRACT) && !(((GrMethod) element).getBlock() != null && GrTraitUtil.isTrait(((GrMethod) element).getContainingClass()))) {
            return 1;
        }
        TextRange textRange = element.getTextRange();
        int start = textRange.getStartOffset();
        int end = Math.min(documentChars.length(), textRange.getEndOffset());
        int crlf = StringUtil.getLineBreakCount(documentChars.subSequence(start, end));
        return crlf == 0 ? 1 : 2;
    }
    return 0;
}
Also used : GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GrClassInitializer(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrClassInitializer) GrTypeParameter(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameter) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrVariableDeclarationImpl(org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrVariableDeclarationImpl) TextRange(com.intellij.openapi.util.TextRange)

Aggregations

GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)2 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)2 GrVariableDeclarationImpl (org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrVariableDeclarationImpl)2 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)1 MarkerType (com.intellij.codeInsight.daemon.impl.MarkerType)1 Document (com.intellij.openapi.editor.Document)1 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)1 TextRange (com.intellij.openapi.util.TextRange)1 MethodSignatureBackedByPsiMethod (com.intellij.psi.util.MethodSignatureBackedByPsiMethod)1 GrDocComment (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment)1 GrDocCommentOwner (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner)1 GrClassInitializer (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrClassInitializer)1 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)1 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)1 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)1 GrAccessorMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod)1 GrTypeParameter (org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameter)1