com.intellij.lang.annotation.Annotation.setFileLevelAnnotation()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(2.7k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中com.intellij.lang.annotation.Annotation.setFileLevelAnnotation()方法的一些代码示例,展示了Annotation.setFileLevelAnnotation()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Annotation.setFileLevelAnnotation()方法的具体详情如下:
包路径:com.intellij.lang.annotation.Annotation
类名称:Annotation
方法名:setFileLevelAnnotation

Annotation.setFileLevelAnnotation介绍

暂无

代码示例

代码示例来源:origin: sonar-intellij-plugin/sonar-intellij-plugin

private static Optional<Annotation> createAnnotation(AnnotationHolder holder, PsiFile psiFile, SonarIssue issue) {
 HighlightSeverity severity = SonarToIjSeverityMapping.toHighlightSeverity(issue.getSeverity());
 Annotation annotation;
 if (issue.getLine() == null) {
  annotation = createAnnotation(holder,issue.formattedMessage(),psiFile,severity);
  annotation.setFileLevelAnnotation(true);
 } else {
  Optional<PsiElement> startElement = Finders.findFirstElementAtLine(psiFile,issue.getLine());
  if (!startElement.isPresent()) {
   // There is no AST element on this line. Maybe a tabulation issue on a blank line?
   annotation = createAnnotation(
    holder,
    issue.formattedMessage(),
    Finders.getLineRange(psiFile,issue.getLine()),
    severity
   );
  } else
   if (startElement.get().isValid()) {
    TextRange lineRange = Finders.getLineRange(startElement.get());
    annotation = createAnnotation(holder,issue.formattedMessage(),lineRange,severity);
   } else {
    annotation = null;
   }
 }
 return Optional.ofNullable(annotation);
}

代码示例来源:origin: SonarSource/sonarlint-intellij

private void addAnnotation(LiveIssue issue, AnnotationHolder annotationHolder) {
 TextRange textRange;
 if (issue.getRange() != null) {
  textRange = createTextRange(issue.getRange());
 } else {
  textRange = issue.psiFile().getTextRange();
 }
 String htmlMsg = getHtmlMessage(issue);
 Annotation annotation = annotationHolder
  .createAnnotation(getSeverity(issue.getSeverity()), textRange, issue.getMessage(), htmlMsg);
 annotation.registerFix(new DisableRuleQuickFix(issue.getRuleKey()));
 if (!issue.flows().isEmpty()) {
  annotation.registerFix(new ShowLocationsIntention(issue.getRange(), issue.getMessage(), issue.flows()));
 }
 if (issue.getRange() == null) {
  annotation.setFileLevelAnnotation(true);
 } else {
  annotation.setTextAttributes(getTextAttrsKey(issue.getSeverity()));
 }
 /*
  * 3 possible ways to set text attributes and error stripe color:
  * - enforce text attributes ({@link Annotation#setEnforcedTextAttributes}) and we need to set everything
  * manually (including error stripe color). This won't be configurable in a standard way and won't change based on used color scheme
  * - rely on one of the default attributes by giving a key {@link com.intellij.openapi.editor.colors.CodeInsightColors} or your own
  * key (SonarLintTextAttributes) to Annotation#setTextAttributes
  * - let Annotation#getTextAttributes decide it based on highlight type and severity.
  */
 annotation.setHighlightType(getType(issue.getSeverity()));
}

相关文章