Search in sources :

Example 36 with Annotation

use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.

the class GroovyAnnotator method visitVariable.

@Override
public void visitVariable(@NotNull GrVariable variable) {
    checkName(variable);
    PsiElement parent = variable.getParent();
    if (parent instanceof GrForInClause) {
        PsiElement delimiter = ((GrForInClause) parent).getDelimiter();
        if (delimiter.getNode().getElementType() == GroovyTokenTypes.mCOLON) {
            GrTypeElement typeElement = variable.getTypeElementGroovy();
            GrModifierList modifierList = variable.getModifierList();
            if (typeElement == null && StringUtil.isEmptyOrSpaces(modifierList.getText())) {
                Annotation annotation = myHolder.createErrorAnnotation(variable.getNameIdentifierGroovy(), GroovyBundle.message("java.style.for.each.statement.requires.a.type.declaration"));
                annotation.registerFix(new ReplaceDelimiterFix());
            }
        }
    }
    PsiNamedElement duplicate = ResolveUtil.findDuplicate(variable);
    if (duplicate instanceof GrVariable && (variable instanceof GrField || ResolveUtil.isScriptField(variable) || !(duplicate instanceof GrField))) {
        final String key = duplicate instanceof GrField ? "field.already.defined" : "variable.already.defined";
        myHolder.createErrorAnnotation(variable.getNameIdentifierGroovy(), GroovyBundle.message(key, variable.getName()));
    }
    PsiType type = variable.getDeclaredType();
    if (type instanceof PsiEllipsisType && !isLastParameter(variable)) {
        TextRange range = getEllipsisRange(variable);
        if (range == null) {
            range = getTypeRange(variable);
        }
        if (range != null) {
            myHolder.createErrorAnnotation(range, GroovyBundle.message("ellipsis.type.is.not.allowed.here"));
        }
    }
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) TextRange(com.intellij.openapi.util.TextRange) Annotation(com.intellij.lang.annotation.Annotation) GrForInClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClause)

Example 37 with Annotation

use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.

the class GroovyAnnotator method checkFieldModifiers.

private static void checkFieldModifiers(AnnotationHolder holder, GrVariableDeclaration fieldDeclaration) {
    GrVariable[] variables = fieldDeclaration.getVariables();
    if (variables.length == 0)
        return;
    GrVariable variable = variables[0];
    if (!(variable instanceof GrField))
        return;
    final GrField member = (GrField) variable;
    final GrModifierList modifierList = fieldDeclaration.getModifierList();
    checkAccessModifiers(holder, modifierList, member);
    checkDuplicateModifiers(holder, modifierList, member);
    if (modifierList.hasExplicitModifier(PsiModifier.VOLATILE) && modifierList.hasExplicitModifier(PsiModifier.FINAL)) {
        final Annotation annotation = holder.createErrorAnnotation(modifierList, GroovyBundle.message("illegal.combination.of.modifiers.volatile.and.final"));
        registerFix(annotation, new GrModifierFix(member, PsiModifier.VOLATILE, true, false, GrModifierFix.MODIFIER_LIST), modifierList);
        registerFix(annotation, new GrModifierFix(member, PsiModifier.FINAL, true, false, GrModifierFix.MODIFIER_LIST), modifierList);
    }
    if (member.getContainingClass() instanceof GrInterfaceDefinition) {
        checkModifierIsNotAllowed(modifierList, PsiModifier.PRIVATE, GroovyBundle.message("interface.members.are.not.allowed.to.be", PsiModifier.PRIVATE), holder);
        checkModifierIsNotAllowed(modifierList, PsiModifier.PROTECTED, GroovyBundle.message("interface.members.are.not.allowed.to.be", PsiModifier.PROTECTED), holder);
    }
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrModifierFix(org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix) Annotation(com.intellij.lang.annotation.Annotation)

Example 38 with Annotation

use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.

the class WebReferencesAnnotatorBase method apply.

@Override
public void apply(@NotNull PsiFile file, MyInfo[] infos, @NotNull AnnotationHolder holder) {
    if (infos == null || infos.length == 0) {
        return;
    }
    final HighlightDisplayLevel displayLevel = getHighlightDisplayLevel(file);
    for (MyInfo info : infos) {
        if (!info.myResult) {
            final PsiElement element = info.myAnchor.retrieve();
            if (element != null) {
                final int start = element.getTextRange().getStartOffset();
                final TextRange range = new TextRange(start + info.myRangeInElement.getStartOffset(), start + info.myRangeInElement.getEndOffset());
                final String message = getErrorMessage(info.myUrl);
                final Annotation annotation;
                if (displayLevel == HighlightDisplayLevel.ERROR) {
                    annotation = holder.createErrorAnnotation(range, message);
                } else if (displayLevel == HighlightDisplayLevel.WARNING) {
                    annotation = holder.createWarningAnnotation(range, message);
                } else if (displayLevel == HighlightDisplayLevel.WEAK_WARNING) {
                    annotation = holder.createInfoAnnotation(range, message);
                } else {
                    annotation = holder.createWarningAnnotation(range, message);
                }
                for (IntentionAction action : getQuickFixes()) {
                    annotation.registerFix(action);
                }
            }
        }
    }
}
Also used : HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) Annotation(com.intellij.lang.annotation.Annotation)

Example 39 with Annotation

use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.

the class ClassReferenceParser method annotate.

@Override
public boolean annotate(@NotNull Header header, @NotNull AnnotationHolder holder) {
    HeaderValue value = header.getHeaderValue();
    if (!(value instanceof HeaderValuePart))
        return false;
    HeaderValuePart valuePart = (HeaderValuePart) value;
    String className = valuePart.getUnwrappedText();
    if (StringUtil.isEmptyOrSpaces(className)) {
        holder.createErrorAnnotation(valuePart.getHighlightingRange(), ManifestBundle.message("header.reference.invalid"));
        return true;
    }
    Project project = header.getProject();
    Module module = ModuleUtilCore.findModuleForPsiElement(header);
    GlobalSearchScope scope = module != null ? module.getModuleWithDependenciesAndLibrariesScope(false) : ProjectScope.getAllScope(project);
    PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(className, scope);
    if (aClass == null) {
        String message = JavaErrorMessages.message("error.cannot.resolve.class", className);
        Annotation anno = holder.createErrorAnnotation(valuePart.getHighlightingRange(), message);
        anno.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
        return true;
    }
    return checkClass(valuePart, aClass, holder);
}
Also used : Project(com.intellij.openapi.project.Project) HeaderValue(org.jetbrains.lang.manifest.psi.HeaderValue) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) HeaderValuePart(org.jetbrains.lang.manifest.psi.HeaderValuePart) Module(com.intellij.openapi.module.Module) Annotation(com.intellij.lang.annotation.Annotation)

Example 40 with Annotation

use of com.intellij.lang.annotation.Annotation in project intellij-plugins by JetBrains.

the class MarkdownHighlightingAnnotator method annotate.

@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    final IElementType type = element.getNode().getElementType();
    if (type == MarkdownTokenTypes.EMPH) {
        final PsiElement parent = element.getParent();
        if (parent == null) {
            return;
        }
        final IElementType parentType = parent.getNode().getElementType();
        if (parentType == MarkdownElementTypes.EMPH || parentType == MarkdownElementTypes.STRONG) {
            final Annotation annotation = holder.createInfoAnnotation(element, null);
            annotation.setTextAttributes(parentType == MarkdownElementTypes.EMPH ? MarkdownHighlighterColors.ITALIC_MARKER_ATTR_KEY : MarkdownHighlighterColors.BOLD_MARKER_ATTR_KEY);
        }
        return;
    }
    if (element instanceof LeafPsiElement) {
        return;
    }
    final TextAttributesKey[] tokenHighlights = SYNTAX_HIGHLIGHTER.getTokenHighlights(type);
    if (tokenHighlights.length > 0 && !MarkdownHighlighterColors.TEXT_ATTR_KEY.equals(tokenHighlights[0])) {
        final Annotation annotation = holder.createInfoAnnotation(element, null);
        annotation.setTextAttributes(tokenHighlights[0]);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) PsiElement(com.intellij.psi.PsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Annotation(com.intellij.lang.annotation.Annotation)

Aggregations

Annotation (com.intellij.lang.annotation.Annotation)98 PsiElement (com.intellij.psi.PsiElement)24 ASTNode (com.intellij.lang.ASTNode)22 TextRange (com.intellij.openapi.util.TextRange)19 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)15 Project (com.intellij.openapi.project.Project)11 NotNull (org.jetbrains.annotations.NotNull)10 PsiFile (com.intellij.psi.PsiFile)8 GrModifierFix (org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix)6 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)4 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)4 Editor (com.intellij.openapi.editor.Editor)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 GrModifierList (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList)4 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)3 Module (com.intellij.openapi.module.Module)3 PsiReference (com.intellij.psi.PsiReference)3 IElementType (com.intellij.psi.tree.IElementType)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 Nullable (org.jetbrains.annotations.Nullable)3