Java 类com.intellij.lang.annotation.Annotation 实例源码

项目:lua-for-idea    文件:LuaAnnotator.java   
@Override
public void visitDocTag(LuaDocTag e) {
    super.visitDocTag(e);

    LuaDocSyntaxHighlighter highlighter = new LuaDocSyntaxHighlighter();

    PsiElement element = e.getFirstChild();
    while (element != null) {
        if (element instanceof ASTNode) {
            ASTNode astNode = (ASTNode) element;
            TextAttributesKey[] keys = highlighter.getTokenHighlights(astNode.getElementType());
            for (TextAttributesKey key : keys) {
                final Annotation a = myHolder.createInfoAnnotation(element, null);
                a.setTextAttributes(key);
            }
        }
        element = element.getNextSibling();
    }
}
项目:lua-for-idea    文件:LuaAnnotator.java   
public void visitIdentifier(LuaIdentifier id) {
    if ((id != null) && id instanceof LuaGlobal) {
        addSemanticHighlight(id, LuaHighlightingData.GLOBAL_VAR);
        return;
    }
    if (id instanceof LuaFieldIdentifier) {
        addSemanticHighlight(id, LuaHighlightingData.FIELD);
        return;
    }
    if (id instanceof LuaUpvalueIdentifier) {
        addSemanticHighlight(id, LuaHighlightingData.UPVAL);
    } else if (id instanceof LuaLocalIdentifier) {
        PsiReference reference = id.getReference();
        if (reference != null) {
            PsiElement resolved = reference.resolve();
            if (resolved instanceof LuaParameter)
                return;
        }
        final Annotation annotation = myHolder.createInfoAnnotation(id, null);
        annotation.setTextAttributes(LuaHighlightingData.LOCAL_VAR);
    }

}
项目:smcplugin    文件:SmcActionAnnotator.java   
@Override
public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) {
    if (SmcTypes.ACTION_NAME.equals(element.getNode().getElementType())) {
        PsiElement parent = element.getParent();
        if (parent == null || !(parent instanceof SmcAction)) {
            return;
        }
        SmcAction action = (SmcAction) parent;
        SmcFile containingFile = (SmcFile)action.getContainingFile();
        String contextClassName = containingFile.getContextClassQName();
        if (!SmcPsiUtil.isMethodInClass(contextClassName, action.getName(), action.getArgumentCount(), element.getProject())) {
            Annotation errorAnnotation = holder.createErrorAnnotation(element, getNotResolvedMessage(action.getFullName(), contextClassName));
            errorAnnotation.setTextAttributes(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
            errorAnnotation.registerFix(new CreateMethodInContextClassFix(action.getName(), action.getArgumentCount()));
        } else if (SmcPsiUtil.isMethodInClassNotUnique(contextClassName, action.getName(), action.getArgumentCount(), element.getProject())) {
            holder.createWarningAnnotation(element, getAmbiguityMessage(action.getFullName(),contextClassName));
        }
    }
}
项目:intellij-ce-playground    文件:GroovyAnnotator.java   
private static void registerMakeAbstractMethodNotAbstractFix(Annotation annotation, GrMethod method, boolean makeClassAbstract) {
  if (method.getBlock() == null) {
    annotation.registerFix(QuickFixFactory.getInstance().createAddMethodBodyFix(method));
  }
  else {
    annotation.registerFix(QuickFixFactory.getInstance().createDeleteMethodBodyFix(method));
  }
  registerFix(annotation, new GrModifierFix(method, PsiModifier.ABSTRACT, false, false, GrModifierFix.MODIFIER_LIST_OWNER), method);
  if (makeClassAbstract) {
    final PsiClass containingClass = method.getContainingClass();
    if (containingClass != null) {
      final PsiModifierList list = containingClass.getModifierList();
      if (list != null && !list.hasModifierProperty(PsiModifier.ABSTRACT)) {
        registerFix(annotation, new GrModifierFix(containingClass, PsiModifier.ABSTRACT, false, true, GrModifierFix.MODIFIER_LIST_OWNER), containingClass);
      }
    }
  }
}
项目:intellij-ce-playground    文件:GroovyAnnotator.java   
private static void checkFieldModifiers(AnnotationHolder holder, GrVariableDeclaration fieldDeclaration) {
  final GrModifierList modifierList = fieldDeclaration.getModifierList();
  final GrField member = (GrField)fieldDeclaration.getVariables()[0];

  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);
  }

  checkModifierIsNotAllowed(modifierList, PsiModifier.NATIVE, GroovyBundle.message("variable.cannot.be.native"), holder);
  checkModifierIsNotAllowed(modifierList, PsiModifier.ABSTRACT, GroovyBundle.message("variable.cannot.be.abstract"), holder);

  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);
  }
}
项目:intellij-ce-playground    文件:GroovyAnnotator.java   
private static void registerImplementsMethodsFix(@NotNull GrTypeDefinition typeDefinition,
                                                 @NotNull PsiMethod abstractMethod,
                                                 @NotNull Annotation annotation) {
  if (!OverrideImplementExploreUtil.getMethodsToOverrideImplement(typeDefinition, true).isEmpty()) {
    annotation.registerFix(QuickFixFactory.getInstance().createImplementMethodsFix(typeDefinition));
  }

  if (!JavaPsiFacade.getInstance(typeDefinition.getProject()).getResolveHelper().isAccessible(abstractMethod, typeDefinition, null)) {
    registerFix(annotation, new GrModifierFix(abstractMethod, PsiModifier.PUBLIC, true, true, GrModifierFix.MODIFIER_LIST_OWNER), abstractMethod);
    registerFix(annotation, new GrModifierFix(abstractMethod, PsiModifier.PROTECTED, true, true, GrModifierFix.MODIFIER_LIST_OWNER), abstractMethod);
  }

  if (!(typeDefinition instanceof GrAnnotationTypeDefinition) && typeDefinition.getModifierList() != null) {
    registerFix(annotation, new GrModifierFix(typeDefinition, PsiModifier.ABSTRACT, false, true, GrModifierFix.MODIFIER_LIST_OWNER), typeDefinition);
  }
}
项目:intellij-ce-playground    文件:JavaFxAnnotator.java   
private static void attachColorIcon(final PsiElement element, AnnotationHolder holder, String attributeValueText) {
  try {
    Color color = null;
    if (attributeValueText.startsWith("#")) {
      color = ColorUtil.fromHex(attributeValueText.substring(1));
    } else {
      final String hexCode = ColorMap.getHexCodeForColorName(StringUtil.toLowerCase(attributeValueText));
      if (hexCode != null) {
        color = ColorUtil.fromHex(hexCode);
      }
    }
    if (color != null) {
      final ColorIcon icon = new ColorIcon(8, color);
      final Annotation annotation = holder.createInfoAnnotation(element, null);
      annotation.setGutterIconRenderer(new ColorIconRenderer(icon, element));
    }
  }
  catch (Exception ignored) {
  }
}
项目:intellij-ce-playground    文件:XPathAnnotator.java   
private static void checkPrefixReferences(AnnotationHolder holder, QNameElement element, ContextProvider myProvider) {
  final PsiReference[] references = element.getReferences();
  for (PsiReference reference : references) {
    if (reference instanceof PrefixReference) {
      final PrefixReference pr = ((PrefixReference)reference);
      if (!pr.isSoft() && pr.isUnresolved()) {
        final TextRange range = pr.getRangeInElement().shiftRight(pr.getElement().getTextRange().getStartOffset());
        final Annotation a = holder.createErrorAnnotation(range, "Unresolved namespace prefix '" + pr.getCanonicalText() + "'");
        a.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);

        final NamespaceContext namespaceContext = myProvider.getNamespaceContext();
        final PrefixedName qName = element.getQName();
        if (namespaceContext != null && qName != null) {
          final IntentionAction[] fixes = namespaceContext.getUnresolvedNamespaceFixes(reference, qName.getLocalName());
          for (IntentionAction fix : fixes) {
            a.registerFix(fix);
          }
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:GroovyAnnotator.java   
private static void checkImplementedMethodsOfClass(AnnotationHolder holder, GrTypeDefinition typeDefinition) {
  if (typeDefinition.hasModifierProperty(PsiModifier.ABSTRACT)) return;
  if (typeDefinition.isAnnotationType()) return;
  if (typeDefinition instanceof GrTypeParameter) return;


  PsiMethod abstractMethod = ClassUtil.getAnyAbstractMethod(typeDefinition);
  if (abstractMethod == null) return;

  String notImplementedMethodName = abstractMethod.getName();

  final TextRange range = GrHighlightUtil.getClassHeaderTextRange(typeDefinition);
  final Annotation annotation = holder.createErrorAnnotation(range,
                                                             GroovyBundle.message("method.is.not.implemented", notImplementedMethodName));
  registerImplementsMethodsFix(typeDefinition, abstractMethod, annotation);
}
项目:intellij-ce-playground    文件:PyBuiltinAnnotator.java   
@Override
public void visitPyReferenceExpression(PyReferenceExpression node) {
  final String name = node.getName();
  if (name == null) return;
  final boolean highlightedAsAttribute = highlightAsAttribute(node, name);
  if (!highlightedAsAttribute && PyBuiltinCache.isInBuiltins(node)) {
    final Annotation ann;
    final PsiElement parent = node.getParent();
    if (parent instanceof PyDecorator) {
      // don't mark the entire decorator, only mark the "@", else we'll conflict with deco annotator
      ann = getHolder().createInfoAnnotation(parent.getFirstChild(), null); // first child is there, or we'd not parse as deco
    }
    else {
      ann = getHolder().createInfoAnnotation(node, null);
    }
    ann.setTextAttributes(PyHighlighter.PY_BUILTIN_NAME);
  }
}
项目:intellij-ce-playground    文件:XPathAnnotator.java   
@Override
public void visitXPath2TypeElement(XPath2TypeElement o) {
  final ContextProvider contextProvider = o.getXPathContext();
  checkPrefixReferences(myHolder, o, contextProvider);

  if (o.getDeclaredType() == XPathType.UNKNOWN) {
    final PsiReference[] references = o.getReferences();
    for (PsiReference reference : references) {
      if (reference instanceof XsltReferenceContributor.SchemaTypeReference ) {
        if (!reference.isSoft() && reference.resolve() == null) {
          final String message = ((EmptyResolveMessageProvider)reference).getUnresolvedMessagePattern();
          final Annotation annotation =
            myHolder.createErrorAnnotation(reference.getRangeInElement().shiftRight(o.getTextOffset()), message);
          annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
        }
      }
    }
  }
  super.visitXPath2TypeElement(o);
}
项目:intellij-ce-playground    文件:DocStringAnnotator.java   
private void annotateDocStringStmt(final PyStringLiteralExpression stmt) {
  if (stmt != null) {
    final DocStringFormat format = DocStringUtil.getConfiguredDocStringFormat(stmt);
    final String[] tags;
    if (format == DocStringFormat.EPYTEXT) {
      tags = EpydocString.ALL_TAGS;
    }
    else if (format == DocStringFormat.REST) {
      tags = SphinxDocString.ALL_TAGS;
    }
    else {
      return;
    }
    int pos = 0;
    while (true) {
      TextRange textRange = DocStringReferenceProvider.findNextTag(stmt.getText(), pos, tags);
      if (textRange == null) break;
      Annotation annotation = getHolder().createInfoAnnotation(textRange.shiftRight(stmt.getTextRange().getStartOffset()), null);
      annotation.setTextAttributes(PyHighlighter.PY_DOC_COMMENT_TAG);
      pos = textRange.getEndOffset();
    }
  }
}
项目:intellij-ce-playground    文件:GroovyAnnotator.java   
private static void checkAccessModifiers(AnnotationHolder holder, @NotNull GrModifierList modifierList, PsiMember member) {
  boolean hasPrivate = modifierList.hasExplicitModifier(PsiModifier.PRIVATE);
  boolean hasPublic = modifierList.hasExplicitModifier(PsiModifier.PUBLIC);
  boolean hasProtected = modifierList.hasExplicitModifier(PsiModifier.PROTECTED);

  if (hasPrivate && hasPublic || hasPrivate && hasProtected || hasPublic && hasProtected) {
    final Annotation annotation = holder.createErrorAnnotation(modifierList, GroovyBundle.message("illegal.combination.of.modifiers"));
    if (hasPrivate) {
      registerFix(annotation, new GrModifierFix(member, PsiModifier.PRIVATE, false, false, GrModifierFix.MODIFIER_LIST), modifierList);
    }
    if (hasProtected) {
      registerFix(annotation, new GrModifierFix(member, PsiModifier.PROTECTED, false, false, GrModifierFix.MODIFIER_LIST), modifierList);
    }
    if (hasPublic) {
      registerFix(annotation, new GrModifierFix(member, PsiModifier.PUBLIC, false, false, GrModifierFix.MODIFIER_LIST), modifierList);
    }
  }
  else if (member instanceof PsiClass &&
           member.getContainingClass() == null &&
           GroovyConfigUtils.getInstance().isVersionAtLeast(member, GroovyConfigUtils.GROOVY2_0)) {
    checkModifierIsNotAllowed(modifierList, PsiModifier.PRIVATE, GroovyBundle.message("top.level.class.maynot.have.private.modifier"), holder);
    checkModifierIsNotAllowed(modifierList, PsiModifier.PROTECTED, GroovyBundle.message("top.level.class.maynot.have.protected.modifier"), holder);
  }
}
项目:intellij-ce-playground    文件:RegExpAnnotator.java   
@Override
public void visitRegExpNamedGroupRef(RegExpNamedGroupRef groupRef) {
  if (!myLanguageHosts.supportsNamedGroupRefSyntax(groupRef)) {
    myHolder.createErrorAnnotation(groupRef, "This named group reference syntax is not supported");
    return;
  }
  if (groupRef.getGroupName() == null) {
    return;
  }
  final RegExpGroup group = groupRef.resolve();
  if (group == null) {
    final Annotation a = myHolder.createErrorAnnotation(groupRef, "Unresolved named group reference");
    if (a != null) {
      // IDEA-9381
      a.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
    }
  }
  else if (PsiTreeUtil.isAncestor(group, groupRef, true)) {
    myHolder.createWarningAnnotation(groupRef, "Group reference is nested into the named group it refers to");
  }
}
项目:intellij-ce-playground    文件:DomElementsHighlightingUtil.java   
@Nullable
public static Annotation createAnnotation(final DomElementProblemDescriptor problemDescriptor) {

  return createProblemDescriptors(problemDescriptor, new Function<Pair<TextRange, PsiElement>, Annotation>() {
    @Override
    public Annotation fun(final Pair<TextRange, PsiElement> s) {
      String text = problemDescriptor.getDescriptionTemplate();
      if (StringUtil.isEmpty(text)) text = null;
      final HighlightSeverity severity = problemDescriptor.getHighlightSeverity();

      TextRange range = s.first;
      if (text == null) range = TextRange.from(range.getStartOffset(), 0);
      range = range.shiftRight(s.second.getTextRange().getStartOffset());
      final Annotation annotation = createAnnotation(severity, range, text);

      if (problemDescriptor instanceof DomElementResolveProblemDescriptor) {
        annotation.setTextAttributes(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
      }

      for(LocalQuickFix fix:problemDescriptor.getFixes()) {
        if (fix instanceof IntentionAction) annotation.registerFix((IntentionAction)fix);
      }
      return annotation;
    }
  });
}
项目:intellij-ce-playground    文件:XmlWrongClosingTagNameInspection.java   
private static void registerProblemStart(@NotNull final AnnotationHolder holder,
                                    @NotNull final XmlTag tag,
                                    @NotNull final XmlToken start,
                                    @NotNull final XmlToken end) {
  PsiElement context = tag.getContainingFile().getContext();
  if (context != null) {
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(context.getLanguage());
    if (parserDefinition != null) {
      ASTNode contextNode = context.getNode();
      if (contextNode != null && contextNode.getChildren(parserDefinition.getStringLiteralElements()) != null) {
        // TODO: we should check for concatenations here
        return;
      }
    }
  }
  final String tagName = tag.getName();
  final String endTokenText = end.getText();

  final RenameTagBeginOrEndIntentionAction renameEndAction = new RenameTagBeginOrEndIntentionAction(tagName, endTokenText, false);
  final RenameTagBeginOrEndIntentionAction renameStartAction = new RenameTagBeginOrEndIntentionAction(endTokenText, tagName, true);

  final Annotation annotation = holder.createErrorAnnotation(start, XmlErrorMessages.message("tag.has.wrong.closing.tag.name"));
  annotation.registerFix(renameEndAction);
  annotation.registerFix(renameStartAction);
}
项目:intellij-ce-playground    文件:XmlWrongClosingTagNameInspection.java   
private static void registerProblemEnd(@NotNull final AnnotationHolder holder,
                                       @NotNull final XmlTag tag,
                                       @NotNull final XmlToken end) {
  PsiElement context = tag.getContainingFile().getContext();
  if (context != null) {
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(context.getLanguage());
    if (parserDefinition != null) {
      ASTNode contextNode = context.getNode();
      if (contextNode != null && contextNode.getChildren(parserDefinition.getStringLiteralElements()) != null) {
        // TODO: we should check for concatenations here
        return;
      }
    }
  }
  final String tagName = tag.getName();
  final String endTokenText = end.getText();

  final RenameTagBeginOrEndIntentionAction renameEndAction = new RenameTagBeginOrEndIntentionAction(tagName, endTokenText, false);
  final RenameTagBeginOrEndIntentionAction renameStartAction = new RenameTagBeginOrEndIntentionAction(endTokenText, tagName, true);

  final Annotation annotation = holder.createErrorAnnotation(end, XmlErrorMessages.message("wrong.closing.tag.name"));
  annotation.registerFix(new RemoveExtraClosingTagIntentionAction());
  annotation.registerFix(renameEndAction);
  annotation.registerFix(renameStartAction);
}
项目:intellij-ce-playground    文件:XMLExternalAnnotator.java   
private static void addMessagesForTreeChild(final XmlToken childByRole,
                                            final Validator.ValidationHost.ErrorType type,
                                            final String message,
                                            AnnotationHolder myHolder, IntentionAction... actions) {
  if (childByRole != null) {
    Annotation annotation;
    if (type == Validator.ValidationHost.ErrorType.ERROR) {
      annotation = myHolder.createErrorAnnotation(childByRole, message);
    }
    else {
      annotation = myHolder.createWarningAnnotation(childByRole, message);
    }

    appendFixes(annotation, actions);
  }
}
项目:intellij-ce-playground    文件:XPathAnnotator.java   
private static void markUnresolvedVariable(XPathVariableReference reference, AnnotationHolder holder) {
  final String referencedName = reference.getReferencedName();
  // missing name is already flagged by parser
  if (referencedName.length() > 0) {
    final TextRange range = reference.getTextRange().shiftRight(1).grown(-1);
    final Annotation ann = holder.createErrorAnnotation(range, "Unresolved variable '" + referencedName + "'");
    ann.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
    final VariableContext variableContext = ContextProvider.getContextProvider(reference).getVariableContext();
    if (variableContext != null) {
      final IntentionAction[] fixes = variableContext.getUnresolvedVariableFixes(reference);
      for (IntentionAction fix : fixes) {
        ann.registerFix(fix);
      }
    }
  }
}
项目:intellij-ce-playground    文件:FormClassAnnotator.java   
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder holder) {
  if (psiElement instanceof PsiField) {
    PsiField field = (PsiField) psiElement;
    final PsiFile boundForm = FormReferenceProvider.getFormFile(field);
    if (boundForm != null) {
      annotateFormField(field, boundForm, holder);
    }
  }
  else if (psiElement instanceof PsiClass) {
    PsiClass aClass = (PsiClass) psiElement;
    final List<PsiFile> formsBoundToClass = FormClassIndex.findFormsBoundToClass(aClass.getProject(), aClass);
    if (formsBoundToClass.size() > 0) {
      Annotation boundClassAnnotation = holder.createInfoAnnotation(aClass.getNameIdentifier(), null);
      boundClassAnnotation.setGutterIconRenderer(new BoundIconRenderer(aClass));
    }
  }
}
项目:intellij-ce-playground    文件:PropertiesAnnotator.java   
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
  if (!(element instanceof IProperty)) return;
  final Property property = (Property)element;
  PropertiesFile propertiesFile = property.getPropertiesFile();
  Collection<IProperty> others = propertiesFile.findPropertiesByKey(property.getUnescapedKey());
  ASTNode keyNode = ((PropertyImpl)property).getKeyNode();
  if (others.size() != 1) {
    Annotation annotation = holder.createErrorAnnotation(keyNode, PropertiesBundle.message("duplicate.property.key.error.message"));
    annotation.registerFix(PropertiesQuickFixFactory.getInstance().createRemovePropertyFix(property));
  }

  highlightTokens(property, keyNode, holder, new PropertiesHighlighter());
  ASTNode valueNode = ((PropertyImpl)property).getValueNode();
  if (valueNode != null) {
    highlightTokens(property, valueNode, holder, new PropertiesValueHighlighter());
  }
}
项目:intellij-plugin    文件:CoffigYamlAnnotator.java   
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
    if (isConfigFile(psiElement) && psiElement instanceof YAMLKeyValue && isYamlLeaf(psiElement)) {
        if (hasNoConfigurationObject(psiElement) && hasNoExplicitReference(psiElement)) {
            TextRange range = new TextRange(psiElement.getTextRange().getStartOffset(), psiElement.getTextRange().getStartOffset() + ((YAMLKeyValue) psiElement).getKeyText().length());
            Annotation warningAnnotation = annotationHolder.createWarningAnnotation(range, "Unused configuration property");
            warningAnnotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL);
        }
    }
}
项目:lua-for-idea    文件:LuaAnnotator.java   
public void visitReturnStatement(LuaReturnStatement stat) {
    super.visitReturnStatement(stat);

    if (stat.isTailCall()) {
        final Annotation a = myHolder.createInfoAnnotation(stat, null);
        a.setTextAttributes(LuaHighlightingData.TAIL_CALL);
    }
}
项目:lua-for-idea    文件:LuaAnnotator.java   
private void highlightReference(PsiReference ref, PsiElement e) {
        if (e instanceof LuaParameter) {
            final Annotation a = myHolder.createInfoAnnotation((PsiElement)ref, null);
            a.setTextAttributes(LuaHighlightingData.PARAMETER);
        }
//        else if (e instanceof LuaIdentifier) {
//            LuaIdentifier id = (LuaIdentifier) e;
//            TextAttributesKey attributesKey = null;
//
//            if (id instanceof LuaGlobal) {
//                attributesKey = LuaHighlightingData.GLOBAL_VAR;
//            } else if (id instanceof LuaLocal && !id.getText().equals("...")) {
//                attributesKey = LuaHighlightingData.LOCAL_VAR;
//            } else if (id instanceof LuaFieldIdentifier) {
//                attributesKey = LuaHighlightingData.FIELD;
//            }
//
//            if (attributesKey != null) {
//                final Annotation annotation = myHolder.createInfoAnnotation(ref.getElement(), null);
//                annotation.setTextAttributes(attributesKey);
//            }
//            if (ref.getElement() instanceof LuaUpvalueIdentifier) {
//                final Annotation a = myHolder.createInfoAnnotation((PsiElement) ref, null);
//                a.setTextAttributes(LuaHighlightingData.UPVAL);
//            }
//        }
    }
项目:lua-for-idea    文件:LuaAnnotator.java   
public void visitDeclarationExpression(LuaDeclarationExpression dec) {
    if (!(dec.getContext() instanceof LuaParameter)) {
        final Annotation a = myHolder.createInfoAnnotation(dec, null);

        if (dec instanceof LuaLocalDeclarationImpl) a.setTextAttributes(LuaHighlightingData.LOCAL_VAR);
        else if (dec instanceof LuaGlobalDeclarationImpl) a.setTextAttributes(LuaHighlightingData.GLOBAL_VAR);
    }
}
项目:smcplugin    文件:SmcTypeIsAvailableAnnotator.java   
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    if (element instanceof SmcParameterType) {
        SmcParameterType type = (SmcParameterType) element;
        String name = type.getName();
        PsiElement nameIdentifier = type.getNameIdentifier();
        if (name == null || nameIdentifier == null) return;
        if (!SmcPsiUtil.isTypeAvailableFromSmc(type)) {
            Annotation errorAnnotation = holder.createErrorAnnotation(nameIdentifier, getMessage(name));
            errorAnnotation.setTextAttributes(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
        }
    }
}
项目:intellij-swagger    文件:ReferenceValidator.java   
void validateDefinitionReference(final PsiElement psiElement,
                                 final AnnotationHolder annotationHolder) {
    if (isLocalReference(psiElement)) {
        final boolean definitionFound =
                getAvailableDefinitions(psiElement)
                        .contains(ReferenceValueExtractor.extractValue(psiElement.getText()));

        if (!definitionFound) {
            final Annotation errorAnnotation =
                    annotationHolder.createErrorAnnotation(psiElement, "Definition not found");
            errorAnnotation.registerFix(intentionAction);
        }
    }
}
项目:intellij-swagger    文件:ReferenceValidator.java   
void validateParameterReference(final PsiElement psiElement,
                                final AnnotationHolder annotationHolder) {
    if (isLocalReference(psiElement)) {
        final boolean parameterFound =
                getAvailableParameters(psiElement)
                        .contains(ReferenceValueExtractor.extractValue(psiElement.getText()));

        if (!parameterFound) {
            final Annotation errorAnnotation =
                    annotationHolder.createErrorAnnotation(psiElement, "Parameter not found");
            errorAnnotation.registerFix(intentionAction);
        }
    }
}
项目:intellij-swagger    文件:ReferenceValidator.java   
void validateResponseReference(final PsiElement psiElement,
                               final AnnotationHolder annotationHolder) {
    if (isLocalReference(psiElement)) {
        final boolean responseFound =
                getAvailableResponses(psiElement)
                        .contains(ReferenceValueExtractor.extractValue(psiElement.getText()));

        if (!responseFound) {
            final Annotation errorAnnotation = annotationHolder.createErrorAnnotation(psiElement, "Response not found");
            errorAnnotation.registerFix(intentionAction);
        }
    }
}
项目:intellij-swagger    文件:UnknownKeyValidator.java   
void validate(final String key,
              final List<Field> availableKeys,
              final PsiElement psiElement,
              final AnnotationHolder annotationHolder) {
    if (shouldIgnore(key, psiElement)) {
        return;
    }

    if (isInvalid(key, availableKeys)) {
        final Annotation errorAnnotation = annotationHolder.createErrorAnnotation(psiElement, "Invalid key");
        errorAnnotation.registerFix(intentionAction);
    }
}
项目:arma-intellij-plugin    文件:SQFMagicVarColorizerAnnotator.java   
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    if (element instanceof SQFVariable) {
        SQFVariable var = (SQFVariable) element;
        if (var.isMagicVar()) {
            Annotation a = holder.createInfoAnnotation(TextRange.from(element.getTextOffset(), var.getTextLength()), null);
            a.setTextAttributes(SQFSyntaxHighlighter.MAGIC_VAR);
        }
    }
}
项目:arma-intellij-plugin    文件:PreprocessorColorizerAnnotator.java   
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    String elementText = element.getText();
    if (elementText.length() >= 1 && elementText.charAt(0) == '#') {
        int macroNameEnd = elementText.indexOf(' ');
        Annotation a = holder.createInfoAnnotation(TextRange.from(element.getTextOffset(), macroNameEnd < 0 ? elementText.length() : macroNameEnd), null);
        a.setTextAttributes(HeaderSyntaxHighlighter.PREPROCESSOR);
    }
}
项目:protobuf-jetbrains-plugin    文件:ProtoErrorsAnnotator.java   
private void markError(ASTNode parent, @Nullable ASTNode node, String message) {
    Annotation annotation;
    if (node == null) {
        annotation = holder.createErrorAnnotation(parent, message);
    } else {
        annotation = holder.createErrorAnnotation(node, message);
    }
    annotation.setHighlightType(ProblemHighlightType.GENERIC_ERROR);
}
项目:stylint-plugin    文件:StylintExternalAnnotator.java   
@Override
public void apply(@NotNull PsiFile file, StylintAnnotationResult annotationResult, @NotNull AnnotationHolder holder) {
    if (annotationResult == null) {
        return;
    }
    InspectionProjectProfileManager inspectionProjectProfileManager = InspectionProjectProfileManager.getInstance(file.getProject());
    SeverityRegistrar severityRegistrar = inspectionProjectProfileManager.getSeverityRegistrar();
    HighlightDisplayKey inspectionKey = getHighlightDisplayKeyByClass();
    EditorColorsScheme colorsScheme = annotationResult.input.colorsScheme;

    Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
    if (document == null) {
        return;
    }

    if (annotationResult.fileLevel != null) {
        Annotation annotation = holder.createWarningAnnotation(file, annotationResult.fileLevel);
        annotation.registerFix(new EditSettingsAction(new StylintSettingsPage(file.getProject())));
        annotation.setFileLevelAnnotation(true);
        return;
    }

    // TODO consider adding a fix to edit configuration file
    if (annotationResult.result == null || annotationResult.result.lint == null || annotationResult.result.lint.isEmpty()) {
        return;
    }
    List<Lint.Issue> issues = annotationResult.result.lint;
    if (issues == null) {
        return;
    }
    StylintProjectComponent component = annotationResult.input.project.getComponent(StylintProjectComponent.class);
    int tabSize = 4;
    for (Lint.Issue issue : issues) {
        HighlightSeverity severity = getHighlightSeverity(issue, component.treatAsWarnings);
        TextAttributes forcedTextAttributes = AnnotatorUtils.getTextAttributes(colorsScheme, severityRegistrar, severity);
        createAnnotation(holder, file, document, issue, "Stylint: ", tabSize, severity, forcedTextAttributes, inspectionKey, component);
    }
}
项目:stylint-plugin    文件:StylintExternalAnnotator.java   
@Nullable
private static Annotation createAnnotation(@NotNull AnnotationHolder holder, @NotNull HighlightSeverity severity, @Nullable TextAttributes forcedTextAttributes, @NotNull TextRange range, @NotNull String message) {
    if (forcedTextAttributes != null) {
        Annotation annotation = createAnnotation(holder, severity, range, message);
        annotation.setEnforcedTextAttributes(forcedTextAttributes);
        return annotation;
    }
    return createAnnotation(holder, severity, range, message);
}
项目:sass-lint-plugin    文件:SassLintExternalAnnotator.java   
@Override
    public void apply(@NotNull PsiFile file, ExternalLintAnnotationResult<LintResult> annotationResult, @NotNull AnnotationHolder holder) {
        if (annotationResult == null) {
            return;
        }
        InspectionProjectProfileManager inspectionProjectProfileManager = InspectionProjectProfileManager.getInstance(file.getProject());
        SeverityRegistrar severityRegistrar = inspectionProjectProfileManager.getSeverityRegistrar();
//        HighlightDisplayKey inspectionKey = getHighlightDisplayKeyByClass();
//        HighlightSeverity severity = InspectionUtil.getSeverity(inspectionProjectProfileManager, inspectionKey, file);
        EditorColorsScheme colorsScheme = annotationResult.input.colorsScheme;

        Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
        if (document == null) {
            return;
        }
        SassLintProjectComponent component = annotationResult.input.project.getComponent(SassLintProjectComponent.class);
        for (SassLint.Issue warn : annotationResult.result.sassLint.file.errors) {
            HighlightSeverity severity = getHighlightSeverity(warn, component.treatAsWarnings);
            TextAttributes forcedTextAttributes = InspectionUtil.getTextAttributes(colorsScheme, severityRegistrar, severity);
            Annotation annotation = createAnnotation(holder, file, document, warn, severity, forcedTextAttributes, false);
//            if (annotation != null) {
//                int offset = StringUtil.lineColToOffset(document.getText(), warn.line - 1, warn.column);
//                PsiElement lit = PsiUtil.getElementAtOffset(file, offset);
//                BaseActionFix actionFix = Fixes.getFixForRule(warn.rule, lit);
//                if (actionFix != null) {
//                    annotation.registerFix(actionFix, null, inspectionKey);
//                }
//                annotation.registerFix(new SuppressActionFix(warn.rule, lit), null, inspectionKey);
//            }
        }
    }
项目:sass-lint-plugin    文件:SassLintExternalAnnotator.java   
@Nullable
    private static Annotation createAnnotation(@NotNull AnnotationHolder holder, @NotNull PsiFile file, @NotNull Document document, @NotNull SassLint.Issue warn,
                                               @NotNull HighlightSeverity severity, @Nullable TextAttributes forcedTextAttributes,
                                               boolean showErrorOnWholeLine) {
        int line = warn.line - 1;
//        int column = warn.column /*- 1*/;

        if (line < 0 || line >= document.getLineCount()) {
            return null;
        }
        int lineEndOffset = document.getLineEndOffset(line);
        int lineStartOffset = document.getLineStartOffset(line);

//        int errorLineStartOffset = StringUtil.lineColToOffset(document.getCharsSequence(),  line, column);
//        int errorLineStartOffset = PsiUtil.calcErrorStartOffsetInDocument(document, lineStartOffset, lineEndOffset, column, tab);

//        if (errorLineStartOffset == -1) {
//            return null;
//        }
//        PsiElement element = file.findElementAt(errorLineStartOffset);
        TextRange range;
//        if (showErrorOnWholeLine) {
            range = new TextRange(lineStartOffset, lineEndOffset);
//        } else {
////            int offset = StringUtil.lineColToOffset(document.getText(), warn.line - 1, warn.column);
//            PsiElement lit = PsiUtil.getElementAtOffset(file, errorLineStartOffset);
//            range = lit.getTextRange();
//            range = new TextRange(errorLineStartOffset, errorLineStartOffset + 1);
//        }

        Annotation annotation = InspectionUtil.createAnnotation(holder, severity, forcedTextAttributes, range, MESSAGE_PREFIX + warn.message.trim() + " (" + warn.source + ')');
//        if (annotation != null) {
//            annotation.setAfterEndOfLine(errorLineStartOffset == lineEndOffset);
//        }
        return annotation;
    }
项目:intellij-ce-playground    文件:JavaDocAnnotator.java   
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
  if (element instanceof PsiDocTag) {
    String name = ((PsiDocTag)element).getName();
    if ("param".equals(name)) {
      PsiDocTagValue tagValue = ((PsiDocTag)element).getValueElement();
      if (tagValue != null) {
        Annotation annotation = holder.createInfoAnnotation(tagValue, null);
        annotation.setTextAttributes(JavaHighlightingColors.DOC_COMMENT_TAG_VALUE);
      }
    }
  }
}
项目:intellij-ce-playground    文件:GroovyAnnotator.java   
private static void checkReferenceList(@NotNull AnnotationHolder holder,
                                       @NotNull GrReferenceList list,
                                       @NotNull Condition<PsiClass> applicabilityCondition,
                                       @NotNull String message,
                                       @Nullable IntentionAction fix) {
  for (GrCodeReferenceElement refElement : list.getReferenceElementsGroovy()) {
    final PsiElement psiClass = refElement.resolve();
    if (psiClass instanceof PsiClass && !applicabilityCondition.value((PsiClass)psiClass)) {
      Annotation annotation = holder.createErrorAnnotation(refElement, message);
      if (fix != null) {
        annotation.registerFix(fix);
      }
    }
  }
}
项目:intellij-ce-playground    文件:InspectionValidatorWrapper.java   
private Map<ProblemDescriptor, HighlightDisplayLevel> runXmlFileSchemaValidation(@NotNull XmlFile xmlFile) {
  final AnnotationHolderImpl holder = new AnnotationHolderImpl(new AnnotationSession(xmlFile));

  final List<ExternalAnnotator> annotators = ExternalLanguageAnnotators.allForFile(StdLanguages.XML, xmlFile);
  for (ExternalAnnotator<?, ?> annotator : annotators) {
    processAnnotator(xmlFile, holder, annotator);
  }

  if (!holder.hasAnnotations()) return Collections.emptyMap();

  Map<ProblemDescriptor, HighlightDisplayLevel> problemsMap = new LinkedHashMap<ProblemDescriptor, HighlightDisplayLevel>();
  for (final Annotation annotation : holder) {
    final HighlightInfo info = HighlightInfo.fromAnnotation(annotation);
    if (info.getSeverity() == HighlightSeverity.INFORMATION) continue;

    final PsiElement startElement = xmlFile.findElementAt(info.startOffset);
    final PsiElement endElement = info.startOffset == info.endOffset ? startElement : xmlFile.findElementAt(info.endOffset - 1);
    if (startElement == null || endElement == null) continue;

    final ProblemDescriptor descriptor =
      myInspectionManager.createProblemDescriptor(startElement, endElement, info.getDescription(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
                                                  false);
    final HighlightDisplayLevel level = info.getSeverity() == HighlightSeverity.ERROR? HighlightDisplayLevel.ERROR: HighlightDisplayLevel.WARNING;
    problemsMap.put(descriptor, level);
  }
  return problemsMap;
}