Search in sources :

Example 26 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 27 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 28 with Annotation

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

the class AnnotationHolderImpl method createAnnotation.

@Override
public Annotation createAnnotation(@NotNull HighlightSeverity severity, @NotNull TextRange range, @Nullable String message, @Nullable String tooltip) {
    Annotation annotation = new Annotation(range.getStartOffset(), range.getEndOffset(), severity, message, tooltip);
    add(annotation);
    return annotation;
}
Also used : Annotation(com.intellij.lang.annotation.Annotation)

Example 29 with Annotation

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

the class GroovyAnnotator method checkGrDocReferenceElement.

private static void checkGrDocReferenceElement(AnnotationHolder holder, PsiElement element) {
    ASTNode node = element.getNode();
    if (node != null && TokenSets.BUILT_IN_TYPES.contains(node.getElementType())) {
        Annotation annotation = holder.createInfoAnnotation(element, null);
        annotation.setTextAttributes(GroovySyntaxHighlighter.KEYWORD);
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) Annotation(com.intellij.lang.annotation.Annotation)

Example 30 with Annotation

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

the class GroovyAnnotator method checkForAbstractAndFinalCombination.

private static void checkForAbstractAndFinalCombination(AnnotationHolder holder, GrMember member, GrModifierList modifiersList) {
    if (member.hasModifierProperty(PsiModifier.FINAL) && member.hasModifierProperty(PsiModifier.ABSTRACT)) {
        final Annotation annotation = holder.createErrorAnnotation(modifiersList, GroovyBundle.message("illegal.combination.of.modifiers.abstract.and.final"));
        registerFix(annotation, new GrModifierFix(member, PsiModifier.FINAL, false, false, GrModifierFix.MODIFIER_LIST), modifiersList);
        registerFix(annotation, new GrModifierFix(member, PsiModifier.ABSTRACT, false, false, GrModifierFix.MODIFIER_LIST), modifiersList);
    }
}
Also used : GrModifierFix(org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix) Annotation(com.intellij.lang.annotation.Annotation)

Aggregations

Annotation (com.intellij.lang.annotation.Annotation)97 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 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 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)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 HbCloseBlockMustache (com.dmarcotte.handlebars.psi.HbCloseBlockMustache)2