com.intellij.lang.annotation.Annotation类的使用及代码示例

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

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

Annotation介绍

暂无

代码示例

代码示例来源:origin: ballerina-platform/ballerina-lang

private void annotateNumber(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    Annotation annotation = holder.createInfoAnnotation(element, null);
    annotation.setTextAttributes(BallerinaSyntaxHighlightingColors.NUMBER);
  }
}

代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin

private static void setHighlighting(@NotNull PsiElement element, @NotNull AnnotationHolder holder, @NotNull TextAttributesKey key) {
 holder.createInfoAnnotation(element, null).setEnforcedTextAttributes(TextAttributes.ERASE_MARKER);
 String description = ApplicationManager.getApplication().isUnitTestMode() ? key.getExternalName() : null;
 holder.createInfoAnnotation(element, description).setTextAttributes(key);
}

代码示例来源:origin: KronicDeth/intellij-elixir

/**
 * Highlights `textRange` with the given `textAttributesKey`.
 *
 * @param textRange         textRange in the document to highlight
 * @param annotationHolder  the container which receives annotations created by the plugin.
 * @param textAttributesKey text attributes to apply to the `node`.
 */
private void highlight(@NotNull final TextRange textRange, @NotNull AnnotationHolder annotationHolder, @NotNull final TextAttributesKey textAttributesKey) {
  annotationHolder.createInfoAnnotation(textRange, null).setEnforcedTextAttributes(TextAttributes.ERASE_MARKER);
  annotationHolder.createInfoAnnotation(textRange, null).setEnforcedTextAttributes(EditorColorsManager.getInstance().getGlobalScheme().getAttributes(textAttributesKey));
}

代码示例来源:origin: BashSupport/BashSupport

private void annotateBinaryData(BashBinaryDataElement element, AnnotationHolder annotationHolder) {
  Annotation annotation = annotationHolder.createInfoAnnotation(element, null);
  annotation.setEnforcedTextAttributes(TextAttributes.ERASE_MARKER);
  annotation = annotationHolder.createInfoAnnotation(element, null);
  annotation.setTextAttributes(BashSyntaxHighlighter.BINARY_DATA);
  annotation.setNeedsUpdateOnTyping(false);
}

代码示例来源: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()));
}

代码示例来源:origin: SeeSharpSoft/intellij-csv-validator

protected boolean handleSeparatorElement(@NotNull PsiElement element, @NotNull AnnotationHolder holder, IElementType elementType, CsvFile csvFile) {
  if (elementType == CsvTypes.COMMA) {
    TextAttributes textAttributes = holder.getCurrentAnnotationSession().getUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_KEY);
    if (!Boolean.TRUE.equals(holder.getCurrentAnnotationSession().getUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED_KEY))) {
      String separator = CsvCodeStyleSettings.getCurrentSeparator(csvFile.getProject(), csvFile.getLanguage());
      if (CsvEditorSettingsExternalizable.getInstance().isHighlightTabSeparator() && separator.equals(CsvCodeStyleSettings.TAB_SEPARATOR)) {
        textAttributes = new TextAttributes(null,
            CsvEditorSettingsExternalizable.getInstance().getTabHighlightColor(),
            null, null, 0);
        holder.getCurrentAnnotationSession().putUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_KEY, textAttributes);
        holder.getCurrentAnnotationSession().putUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED_KEY, Boolean.TRUE);
      }
    }
    if (textAttributes != null) {
      Annotation annotation = holder.createAnnotation(
          CSV_COLUMN_INFO_SEVERITY,
          element.getTextRange(),
          showInfoBalloon(holder.getCurrentAnnotationSession()) ? "↹" : null
      );
      annotation.setEnforcedTextAttributes(textAttributes);
      annotation.setNeedsUpdateOnTyping(false);
    }
    return true;
  }
  return false;
}

代码示例来源:origin: BashSupport/BashSupport

private void annotateHereDoc(BashHereDoc element, AnnotationHolder annotationHolder) {
  final Annotation annotation = annotationHolder.createInfoAnnotation(element, null);
  annotation.setTextAttributes(BashSyntaxHighlighter.HERE_DOC);
  annotation.setNeedsUpdateOnTyping(false);
  if (element.isEvaluatingVariables()) {
    highlightVariables(element, annotationHolder);
  }
}

代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin

if (!(PsiTreeUtil.getParentOfType(element, GoForStatement.class, GoFunctionLit.class) instanceof GoForStatement)) {
 Annotation annotation = holder.createErrorAnnotation(element, "Continue statement not inside a for loop");
 annotation.registerFix(new GoReplaceWithReturnStatementQuickFix(element));
if (GoPsiImplUtil.getBreakStatementOwner(element) == null) {
 Annotation annotation = holder.createErrorAnnotation(element, "Break statement not inside a for loop, select or switch");
 annotation.registerFix(new GoReplaceWithReturnStatementQuickFix(element));
     Annotation annotation = holder.createErrorAnnotation(result, declaration.getName() +
                                    " function must have no arguments and no return values");
     annotation.registerFix(new GoEmptySignatureQuickFix(declaration));
     Annotation annotation = holder.createErrorAnnotation(parameters, declaration.getName() +
                                      " function must have no arguments and no return values");
     annotation.registerFix(new GoEmptySignatureQuickFix(declaration));
  TextRange r = TextRange.create(secondColon.getTextRange().getStartOffset(), thirdIndex.getTextRange().getEndOffset());
  Annotation annotation = holder.createErrorAnnotation(r, "Invalid operation " + slice.getText() + " (3-index slice of string)");
  annotation.registerFix(new GoDeleteRangeQuickFix(secondColon, thirdIndex, "Delete third index"));

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

@Test
public void testRangeIssues() {
 createStoredIssues(5);
 annotator.apply(psiFile, ctx, holder);
 for (int i = 0; i < 5; i++) {
  assertThat(holder.get(i).getStartOffset()).isEqualTo(i);
  assertThat(holder.get(i).getEndOffset()).isEqualTo(i + 10);
  assertThat(holder.get(i).getMessage()).contains("issue " + i);
  assertThat(holder.get(i).getSeverity()).isEqualTo(HighlightSeverity.WARNING);
  assertThat(holder.get(i).isFileLevelAnnotation()).isFalse();
 }
}

代码示例来源:origin: zalando/intellij-swagger

private void warn(
   final PsiElement psiElement,
   final AnnotationHolder annotationHolder,
   final PsiElement searchableCurrentElement,
   final String warning) {
  final PsiReference first = ReferencesSearch.search(searchableCurrentElement).findFirst();

  if (first == null) {
   Annotation annotation = annotationHolder.createWeakWarningAnnotation(psiElement, warning);
   annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL);
  }
 }
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

public void assertAnnotationContains(String filename, String content, String contains) {
  List<String> matches = new ArrayList<String>();
  for (Annotation annotation : getAnnotationsAtCaret(filename, content)) {
    matches.add(annotation.toString());
    if(annotation.getMessage().contains(contains)) {
      return;
    }
  }
  fail(String.format("Fail matches '%s' with one of %s", contains, matches));
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

public void assertAnnotationNotContains(String filename, String content, String contains) {
  for (Annotation annotation : getAnnotationsAtCaret(filename, content)) {
    if(annotation.getMessage().contains(contains)) {
      fail(String.format("Fail not matching '%s' with '%s'", contains, annotation));
    }
  }
}

代码示例来源: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: KronicDeth/intellij-elixir

/**
   * Highlights `textRange` with the given `textAttributesKey`.
   *
   * @param textRange         textRange in the document to highlight
   * @param annotationHolder  the container which receives annotations created by the plugin.
   * @param textAttributesKey text attributes to apply to the `node`.
   */
  private void highlight(@NotNull final TextRange textRange,
              @NotNull AnnotationHolder annotationHolder,
              @NotNull final TextAttributesKey textAttributesKey) {
    annotationHolder.createInfoAnnotation(textRange, null)
        .setEnforcedTextAttributes(TextAttributes.ERASE_MARKER);
    annotationHolder.createInfoAnnotation(textRange, null)
        .setEnforcedTextAttributes(
            EditorColorsManager.getInstance().getGlobalScheme().getAttributes(textAttributesKey)
        );
  }
}

代码示例来源:origin: SeeSharpSoft/intellij-csv-validator

annotation.setEnforcedTextAttributes(
    CsvEditorSettingsExternalizable.getInstance().isColumnHighlightingEnabled() ?
        CsvColorSettings.getTextAttributesOfColumn(columnInfo.getColumnIndex(), holder.getCurrentAnnotationSession()) :
        null
);
annotation.setNeedsUpdateOnTyping(false);

代码示例来源:origin: zalando/intellij-swagger

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

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

@Test
public void testFileLevelIssues() {
 createFileIssues(5);
 annotator.apply(psiFile, ctx, holder);
 assertThat(holder).hasSize(5);
 for (int i = 0; i < 5; i++) {
  assertThat(holder.get(i).getStartOffset()).isEqualTo(psiFileRange.getStartOffset());
  assertThat(holder.get(i).getEndOffset()).isEqualTo(psiFileRange.getEndOffset());
  assertThat(holder.get(i).isFileLevelAnnotation()).isTrue();
  assertThat(holder.get(i).getMessage()).contains("issue " + i);
  assertThat(holder.get(i).getSeverity()).isEqualTo(HighlightSeverity.WARNING);
 }
}

代码示例来源:origin: zalando/intellij-swagger

private void warn(
   final PsiElement psiElement,
   final AnnotationHolder annotationHolder,
   final PsiElement searchableCurrentElement,
   final String warning) {
  final PsiReference first = ReferencesSearch.search(searchableCurrentElement).findFirst();

  if (first == null) {
   Annotation annotation = annotationHolder.createWeakWarningAnnotation(psiElement, warning);
   annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL);
  }
 }
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

/**
 * @see TemplateAnnotationAnnotator#annotate
 */
public void testThatTemplateCreationAnnotationProvidesQuickfix() {
  PsiFile psiFile = myFixture.configureByText("foobar.php", "<?php\n" +
    "use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template;\n" +
    "\n" +
    "class Foobar\n" +
    "{\n" +
    "   /**\n" +
    "   * @Temp<caret>late(\"foobar.html.twig\")\n" +
    "   */\n" +
    "   public function fooAction()\n" +
    "   {\n" +
    "   }\n" +
    "}\n" +
    ""
  );
  PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
  PsiElement phpDocTag = psiElement.getParent();
  AnnotationHolderImpl annotations = new AnnotationHolderImpl(new AnnotationSession(psiFile));
  new TemplateAnnotationAnnotator().annotate(new PhpAnnotationDocTagAnnotatorParameter(
    PhpIndex.getInstance(getProject()).getAnyByFQN(TwigUtil.TEMPLATE_ANNOTATION_CLASS).iterator().next(),
    (PhpDocTag) phpDocTag,
    annotations
  ));
  assertNotNull(
    annotations.stream().findFirst().filter(annotation -> annotation.getMessage().contains("Create Template"))
  );
}

代码示例来源:origin: ballerina-platform/ballerina-lang

private void annotateText(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
  Annotation annotation = holder.createInfoAnnotation(element, null);
  annotation.setTextAttributes(BallerinaSyntaxHighlightingColors.STRING);
}

相关文章