Java Code Examples for com.intellij.codeInsight.daemon.impl.HighlightInfo

The following examples show how to use com.intellij.codeInsight.daemon.impl.HighlightInfo. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: litho   Source File: ResolveRedSymbolsAction.java    License: Apache License 2.0 6 votes vote down vote up
private static Map<String, List<PsiElement>> collectRedSymbols(
    PsiFile psiFile, Document document, Project project, ProgressIndicator daemonIndicator) {
  Map<String, List<PsiElement>> redSymbolToElements = new HashMap<>();
  List<HighlightInfo> infos =
      ((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(project))
          .runMainPasses(psiFile, document, daemonIndicator);
  for (HighlightInfo info : infos) {
    if (!info.getSeverity().equals(HighlightSeverity.ERROR)) continue;

    final String redSymbol = document.getText(new TextRange(info.startOffset, info.endOffset));
    if (!StringUtil.isJavaIdentifier(redSymbol) || !StringUtil.isCapitalized(redSymbol)) continue;

    final PsiJavaCodeReferenceElement ref =
        PsiTreeUtil.findElementOfClassAtOffset(
            psiFile, info.startOffset, PsiJavaCodeReferenceElement.class, false);
    if (ref == null) continue;

    redSymbolToElements.putIfAbsent(redSymbol, new ArrayList<>());
    redSymbolToElements.get(redSymbol).add(ref);
  }
  return redSymbolToElements;
}
 
Example 2
Source Project: consulo   Source File: TooltipActionProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
static TooltipAction calcTooltipAction(@Nonnull final HighlightInfo info, @Nonnull Editor editor) {
  if (!Registry.is("ide.tooltip.show.with.actions")) return null;

  Project project = editor.getProject();
  if (project == null) return null;

  PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  if (file == null) return null;

  for (TooltipActionProvider extension : EXTENSION_POINT_NAME.getExtensionList()) {
    TooltipAction action = extension.getTooltipAction(info, editor, file);
    if (action != null) return action;
  }

  return null;
}
 
Example 3
Source Project: neovim-intellij-complete   Source File: Inspect.java    License: MIT License 6 votes vote down vote up
/**
 * Runs code analyzis and returns all problems found under cursor (row and col).
 *
 * @param path
 * @param fileContent
 * @param row
 * @param col
 * @return
 */
public static List<HighlightInfo.IntentionActionDescriptor> getFixes(
        final String path, @Nullable final String fileContent, final int row, final int col) {
    List<HighlightInfo.IntentionActionDescriptor> fixes = new ArrayList<>();
    Pair<Document, List<HighlightInfo>> problems = getProblems(path, fileContent);
    Document doc = problems.getFirst();
    for (HighlightInfo h : problems.getSecond()) {
        if (h.quickFixActionRanges == null) continue;
        for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> p : h.quickFixActionRanges) {
            int offset = EmbeditorUtil.lineAndColumnToOffset(doc, row, col);
            if (p.getSecond().contains(offset)) {
                fixes.add(p.getFirst());
            }
        }
    }
    return fixes;
}
 
Example 4
@Override
  public boolean accept(@NotNull HighlightInfo highlightInfo, @Nullable PsiFile file) {
//        if (null != file && HighlightSeverity.ERROR.equals(highlightInfo.getSeverity())) {
//
//            String description = StringUtil.notNullize(highlightInfo.getDescription());
//
//            // Handling LazyGetter
//            if (uninitializedField(description) && LazyGetterHandler.isLazyGetterHandled(highlightInfo, file)) {
//                return false;
//            }
//
//            //Handling onX parameters
//            if (OnXAnnotationHandler.isOnXParameterAnnotation(highlightInfo, file)
//                    || OnXAnnotationHandler.isOnXParameterValue(highlightInfo, file)
//                    || LOMBOK_ANYANNOTATIONREQUIRED.matcher(description).matches()) {
//                return false;
//            }
//        }
    return true;
  }
 
Example 5
Source Project: consulo   Source File: GlobalInspectionUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void createProblem(@Nonnull PsiElement elt,
                                 @Nonnull HighlightInfo info,
                                 TextRange range,
                                 @javax.annotation.Nullable ProblemGroup problemGroup,
                                 @Nonnull InspectionManager manager,
                                 @Nonnull ProblemDescriptionsProcessor problemDescriptionsProcessor,
                                 @Nonnull GlobalInspectionContext globalContext) {
  List<LocalQuickFix> fixes = new ArrayList<LocalQuickFix>();
  if (info.quickFixActionRanges != null) {
    for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> actionRange : info.quickFixActionRanges) {
      final IntentionAction action = actionRange.getFirst().getAction();
      if (action instanceof LocalQuickFix) {
        fixes.add((LocalQuickFix)action);
      }
    }
  }
  ProblemDescriptor descriptor = manager.createProblemDescriptor(elt, range, createInspectionMessage(StringUtil.notNullize(info.getDescription())),
                                                                 HighlightInfo.convertType(info.type), false,
                                                                 fixes.isEmpty() ? null : fixes.toArray(new LocalQuickFix[fixes.size()]));
  descriptor.setProblemGroup(problemGroup);
  problemDescriptionsProcessor.addProblemElement(
          GlobalInspectionContextUtil.retrieveRefElement(elt, globalContext),
          descriptor
  );
}
 
Example 6
@Override
public void visit(@NotNull PsiElement element) {
  // FIXME: Re-enable quick fix for missing dependencies once it is functional again.
  // https://github.com/pantsbuild/intellij-pants-plugin/issues/280
  if (!ApplicationManager.getApplication().isUnitTestMode()) {
    return;
  }
  final PsiFile containingFile = element.getContainingFile();
  if (containingFile == null || DumbService.getInstance(myHolder.getProject()).isDumb()) {
    return;
  }
  int infoSize = myHolder.size();
  for (int i = 0; i < infoSize; i++) {
    final HighlightInfo info = myHolder.get(i);
    tryToExtendInfo(info, containingFile);
  }
}
 
Example 7
Source Project: consulo-unity3d   Source File: SharpLabHighlightVisitor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void visitElement(PsiElement element)
{
	super.visitElement(element);

	ASTNode node = element.getNode();

	if(node != null)
	{
		if(node.getElementType() == ShaderLabKeyTokens.VALUE_KEYWORD)
		{
			myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(node).textAttributes(DefaultLanguageHighlighterColors.MACRO_KEYWORD).create());
		}
		else if(node.getElementType() == ShaderLabKeyTokens.START_KEYWORD)
		{
			myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(node).textAttributes(DefaultLanguageHighlighterColors.KEYWORD).create());
		}
	}
}
 
Example 8
private static void registerInOutProblem(DotNetGenericParameter parameter,
		HighlightInfoHolder highlightInfoHolder,
		PsiElement modifierElement,
		CSharpModifier modifier)
{
	CSharpModifier revertModifier = modifier == CSharpModifier.IN ? CSharpModifier.OUT : CSharpModifier.IN;
	HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR);
	builder.descriptionAndTooltip(CSharpErrorBundle.message("conflicting.0.modifier.with.1.modifier", modifier.getPresentableText(),
			revertModifier.getPresentableText()));
	builder.range(modifierElement);

	HighlightInfo info = builder.create();
	if(info != null)
	{
		QuickFixAction.registerQuickFixAction(info, modifierElement.getTextRange(), new RemoveModifierFix(modifier, parameter));
		highlightInfoHolder.add(info);
	}
}
 
Example 9
Source Project: consulo   Source File: EditorMouseHoverPopupManager.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
private VisualPosition getPopupPosition(Editor editor) {
  HighlightInfo highlightInfo = getHighlightInfo();
  if (highlightInfo == null) {
    int offset = targetOffset;
    PsiElement elementForQuickDoc = getElementForQuickDoc();
    if (elementForQuickDoc != null) {
      offset = elementForQuickDoc.getTextRange().getStartOffset();
    }
    return editor.offsetToVisualPosition(offset);
  }
  else {
    VisualPosition targetPosition = editor.offsetToVisualPosition(targetOffset);
    VisualPosition endPosition = editor.offsetToVisualPosition(highlightInfo.getEndOffset());
    if (endPosition.line <= targetPosition.line) return targetPosition;
    Point targetPoint = editor.visualPositionToXY(targetPosition);
    Point endPoint = editor.visualPositionToXY(endPosition);
    Point resultPoint = new Point(targetPoint.x, endPoint.x > targetPoint.x ? endPoint.y : editor.visualLineToY(endPosition.line - 1));
    return editor.xyToVisualPosition(resultPoint);
  }
}
 
Example 10
Source Project: consulo-csharp   Source File: CSharpHighlightVisitor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void visitElement(PsiElement element)
{
	ProgressIndicatorProvider.checkCanceled();

	IElementType elementType = PsiUtilCore.getElementType(element);
	if(CSharpSoftTokens.ALL.contains(elementType))
	{
		myHighlightInfoHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(element).textAttributes(CSharpHighlightKey.SOFT_KEYWORD).create());
	}
	else if(elementType == CSharpTokens.NON_ACTIVE_SYMBOL || elementType == CSharpPreprocessorElements.DISABLED_PREPROCESSOR_DIRECTIVE)
	{
		if(myDocument == null)
		{
			return;
		}
		int lineNumber = myDocument.getLineNumber(element.getTextOffset());
		if(!myProcessedLines.contains(lineNumber))
		{
			myProcessedLines.add(lineNumber);

			TextRange textRange = new TextRange(myDocument.getLineStartOffset(lineNumber), myDocument.getLineEndOffset(lineNumber));
			myHighlightInfoHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(textRange).textAttributes(CSharpHighlightKey.DISABLED_BLOCK).create());
		}
	}
}
 
Example 11
public static boolean isOnXParameterAnnotation(HighlightInfo highlightInfo, PsiFile file) {
  final String description = StringUtil.notNullize(highlightInfo.getDescription());
  if (!(ANNOTATION_TYPE_EXPECTED.equals(description)
    || CANNOT_RESOLVE_SYMBOL_UNDERSCORES_MESSAGE.matcher(description).matches()
    || CANNOT_RESOLVE_METHOD_UNDERSCORES_MESSAGE.matcher(description).matches())) {
    return false;
  }

  PsiElement highlightedElement = file.findElementAt(highlightInfo.getStartOffset());

  PsiNameValuePair nameValuePair = findContainingNameValuePair(highlightedElement);
  if (nameValuePair == null || !(nameValuePair.getContext() instanceof PsiAnnotationParameterList)) {
    return false;
  }

  String parameterName = nameValuePair.getName();
  if (null != parameterName && parameterName.contains("_")) {
    parameterName = parameterName.substring(0, parameterName.indexOf('_'));
  }
  if (!ONX_PARAMETERS.contains(parameterName)) {
    return false;
  }

  PsiElement containingAnnotation = nameValuePair.getContext().getContext();
  return containingAnnotation instanceof PsiAnnotation && ONXABLE_ANNOTATIONS.contains(((PsiAnnotation) containingAnnotation).getQualifiedName());
}
 
Example 12
Source Project: consulo   Source File: ChangeSignaturePassFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void doApplyInformationToEditor() {
  HighlightInfo info = null;
  final InplaceChangeSignature currentRefactoring = InplaceChangeSignature.getCurrentRefactoring(myEditor);
  if (currentRefactoring != null) {
    final ChangeInfo changeInfo = currentRefactoring.getStableChange();
    final PsiElement element = changeInfo.getMethod();
    int offset = myEditor.getCaretModel().getOffset();
    if (element == null || !element.isValid()) return;
    final TextRange elementTextRange = element.getTextRange();
    if (elementTextRange == null || !elementTextRange.contains(offset)) return;
    final LanguageChangeSignatureDetector<ChangeInfo> detector = LanguageChangeSignatureDetectors.INSTANCE.forLanguage(changeInfo.getLanguage());
    TextRange range = detector.getHighlightingRange(changeInfo);
    TextAttributes attributes = new TextAttributes(null, null,
                                                   myEditor.getColorsScheme().getAttributes(CodeInsightColors.WEAK_WARNING_ATTRIBUTES)
                                                           .getEffectColor(),
                                                   null, Font.PLAIN);
    HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(range);
    builder.textAttributes(attributes);
    builder.descriptionAndTooltip(SIGNATURE_SHOULD_BE_POSSIBLY_CHANGED);
    info = builder.createUnconditionally();
    QuickFixAction.registerQuickFixAction(info, new ApplyChangeSignatureAction(currentRefactoring.getInitialName()));
  }
  Collection<HighlightInfo> infos = info != null ? Collections.singletonList(info) : Collections.emptyList();
  UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), infos, getColorsScheme(), getId());
}
 
Example 13
Source Project: intellij-csv-validator   Source File: CsvAnnotatorTest.java    License: Apache License 2.0 5 votes vote down vote up
private long collectAndCheckHighlighting(@NotNull ExpectedHighlightingDataWrapper data) {
    Project project = myFixture.getProject();
    EdtTestUtil.runInEdtAndWait(() -> {
        PsiDocumentManager.getInstance(project).commitAllDocuments();
    });
    PsiFileImpl file = (PsiFileImpl)this.getHostFile();
    FileElement hardRefToFileElement = file.calcTreeElement();
    if (!DumbService.isDumb(project)) {
        ServiceManager.getService(project, CacheManager.class).getFilesWithWord("XXX", (short)2, GlobalSearchScope.allScope(project), true);
    }

    long start = System.currentTimeMillis();
    Disposable disposable = Disposer.newDisposable();

    List<HighlightInfo> infos;
    try {
        infos = myFixture.doHighlighting();
        this.removeDuplicatedRangesForInjected(infos);
    } finally {
        Disposer.dispose(disposable);
    }

    long elapsed = System.currentTimeMillis() - start;
    data.checkResultWrapper(file, infos, file.getText());
    hardRefToFileElement.hashCode();
    return elapsed;
}
 
Example 14
public void testAnnotatorStringFormatValid() {
    myFixture.configureByText("AnnotatorTestData.java", getStringFormatValidEndpoint());
    myFixture.checkHighlighting(false, false, true, true);

    List<HighlightInfo> list = myFixture.doHighlighting();

    // there should not be any invalid boolean warnings as String.format should work
    boolean found = list.stream().anyMatch(i -> i.getDescription() != null && i.getDescription().startsWith("Invalid boolean value"));
    assertFalse("Should not find any warning", found);
}
 
Example 15
Source Project: consulo   Source File: RainbowVisitor.java    License: Apache License 2.0 5 votes vote down vote up
protected HighlightInfo getInfo(@Nonnull final PsiElement context,
                                @Nonnull final PsiElement rainbowElement,
                                @Nonnull final String name,
                                @javax.annotation.Nullable final TextAttributesKey colorKey) {
  int colorIndex = UsedColors.getOrAddColorIndex((UserDataHolderEx)context, name, getHighlighter().getColorsCount());
  return getHighlighter().getInfo(colorIndex, rainbowElement, colorKey);
}
 
Example 16
public void testIncorrectXmlBeanReference() {
    List<HighlightInfo> highlights = getHighlights("incorrect-reference.xml", "TestClass1.java", "TestClass2.java");
    assertEquals(1, highlights.size());
    HighlightInfo highlight = highlights.get(0);
    assertEquals(HighlightSeverity.ERROR, highlight.getSeverity());
    assertEquals("testBean", highlight.getText());
    assertEquals("Bean must be of 'TestClass2' type", highlight.getDescription());
}
 
Example 17
Source Project: consulo   Source File: HighlightInfoHolder.java    License: Apache License 2.0 5 votes vote down vote up
public boolean add(@Nullable HighlightInfo info) {
  if (info == null || !accepted(info)) return false;

  HighlightSeverity severity = info.getSeverity();
  if (severity == HighlightSeverity.ERROR) {
    myErrorCount++;
  }

  return myInfos.add(info);
}
 
Example 18
@NotNull
private List<HighlightInfo> getHighlights(String ... filePaths) {
    myFixture.configureByFiles(filePaths);
    myFixture.checkHighlighting(false, false, true, true);

    return myFixture.doHighlighting().stream()
            .filter(info -> !info.getText().equals("http://www.osgi.org/xmlns/blueprint/v1.0.0"))
            .collect(Collectors.toList());
}
 
Example 19
/**
 * Test if the annotator mark the bean call "thisIsVeryPrivate","methodDoesNotExist" as errors
 */
public void testAnnotatorJavaBeanWithPrivateAndNoneExistingMethod() {
    myFixture.configureByFiles("AnnotatorJavaBeanRoute1TestData.java", "AnnotatorJavaBeanTestData.java", "AnnotatorJavaBeanSuperClassTestData.java");
    myFixture.checkHighlighting(false, false, false, true);

    List<HighlightInfo> list = myFixture.doHighlighting();
    verifyHighlight(list, "\"thisIsVeryPrivate\"", "'thisIsVeryPrivate' has private access in bean 'testData.annotator.method.AnnotatorJavaBeanTestData'", HighlightSeverity.ERROR);
    verifyHighlight(list, "\"methodDoesNotExist\"", "Can not resolve method 'methodDoesNotExist' in bean 'testData.annotator.method.AnnotatorJavaBeanTestData'", HighlightSeverity.ERROR);
    verifyHighlight(list, "(AnnotatorJavaBeanTestData.class, \"letsDoThis\")", "Cannot resolve method 'bean(java.lang.Class, java.lang.String)'", HighlightSeverity.ERROR);
}
 
Example 20
/**
 * Test if the annotator mark the bean call "thisIsVeryPrivate","methodDoesNotExist" as errors
 */
public void testAnnotatorJavaBeanWithAbstractMethod() {
    myFixture.configureByFiles("AnnotatorJavaBeanRoute2TestData.java", "AnnotatorJavaBeanTestData.java", "AnnotatorJavaBeanSuperClassTestData.java");
    myFixture.checkHighlighting(false, false, false, true);

    List<HighlightInfo> list = myFixture.doHighlighting();

    verifyHighlight(list, "\"letsDoThis\"", "Can not resolve method 'letsDoThis' in bean 'testData.annotator.method.AnnotatorJavaBeanSuperClassTestData'", HighlightSeverity.ERROR);
    verifyHighlight(list, "(beanTestData, \"mySuperAbstractMethod\")", "Cannot resolve method 'bean(testData.annotator.method.AnnotatorJavaBeanSuperClassTestData, java.lang.String)'", HighlightSeverity.ERROR);
    verifyHighlight(list, "\"thisIsVeryPrivate\"", "Can not resolve method 'thisIsVeryPrivate' in bean 'testData.annotator.method.AnnotatorJavaBeanSuperClassTestData'", HighlightSeverity.ERROR);
}
 
Example 21
/**
 * Test if the annotator mark the bean call "myOverLoadedBean" as errors because it's Ambiguous. This test also test if the scenario where one of the
 * overloaded methods is private and the other is public
 */
public void testAnnotatorJavaBeanAmbiguousMatch() {
    myFixture.configureByFiles("AnnotatorJavaBeanRoute3TestData.java", "AnnotatorJavaBeanTestData.java", "AnnotatorJavaBeanSuperClassTestData.java");
    myFixture.checkHighlighting(false, false, false, true);

    List<HighlightInfo> list = myFixture.doHighlighting();
    verifyHighlight(list, "(beanTestData, \"myOverLoadedBean2\")", "Cannot resolve method 'bean(testData.annotator.method.AnnotatorJavaBeanTestData, java.lang.String)'", HighlightSeverity.ERROR);
    verifyHighlight(list, "(beanTestData, \"myOverLoadedBean(${body})\")", "Cannot resolve method 'bean(testData.annotator.method.AnnotatorJavaBeanTestData, java.lang.String)'", HighlightSeverity.ERROR);
    verifyHighlight(list, "\"myOverLoadedBean\"", "Ambiguous matches 'myOverLoadedBean' in bean 'testData.annotator.method.AnnotatorJavaBeanTestData'", HighlightSeverity.ERROR);
}
 
Example 22
/**
 * Test if the annotator is false and don't mark any methods even it's ambiguous, but one of the methods are marked as @Handle
 */
public void testAnnotatorJavaBeanWithHandlerAnnotation() {
    myFixture.configureByFiles("AnnotatorJavaBeanRoute4TestData.java", "AnnotatorJavaBeanTestData.java", "AnnotatorJavaBeanSuperClassTestData.java");
    myFixture.checkHighlighting(false, false, false, true);

    List<HighlightInfo> list = myFixture.doHighlighting();
    verifyHighlight(list, "(beanTestData, \"myOverLoadedBean3\")", "Cannot resolve method 'bean(testData.annotator.method.AnnotatorJavaBeanTestData, java.lang.String)'", HighlightSeverity.ERROR);
}
 
Example 23
Source Project: consulo   Source File: ApplyIntentionAction.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public static ApplyIntentionAction[] getAvailableIntentions(final Editor editor, final PsiFile file) {
  final ShowIntentionsPass.IntentionsInfo info = new ShowIntentionsPass.IntentionsInfo();
  ApplicationManager.getApplication().runReadAction(new Runnable() {
    @Override
    public void run() {
      ShowIntentionsPass.getActionsToShow(editor, file, info, -1);
    }
  });
  if (info.isEmpty()) return null;

  final List<HighlightInfo.IntentionActionDescriptor> actions = new ArrayList<HighlightInfo.IntentionActionDescriptor>();
  actions.addAll(info.errorFixesToShow);
  actions.addAll(info.inspectionFixesToShow);
  actions.addAll(info.intentionsToShow);

  final ApplyIntentionAction[] result = new ApplyIntentionAction[actions.size()];
  for (int i = 0; i < result.length; i++) {
    final HighlightInfo.IntentionActionDescriptor descriptor = actions.get(i);
    final String actionText = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
      @Override
      public String compute() {
        return descriptor.getAction().getText();
      }
    });
    result[i] = new ApplyIntentionAction(descriptor, actionText, editor, file);
  }
  return result;
}
 
Example 24
Source Project: neovim-intellij-complete   Source File: NeovimIntellijComplete.java    License: MIT License 5 votes vote down vote up
@NeovimHandler("IntellijProblems")
public Fix[] intellijProblems(String path, List<String> lines, final int row, final int col) {
    final String fileContent = String.join("\n", lines) ;
    List<HighlightInfo.IntentionActionDescriptor> allFixes = Inspect.getFixes(path, fileContent, row, col);
    List<Fix> fixes = new ArrayList<>();
    for (int i = 0; i < allFixes.size(); i++) {
        HighlightInfo.IntentionActionDescriptor d = allFixes.get(i);
        if (d.getAction().getText().length() == 0) continue;
        fixes.add(new Fix(d.getAction().getText(), i, d));
    }
    mCachedFixes = fixes.toArray(new Fix[fixes.size()]);
    return mCachedFixes;
}
 
Example 25
Source Project: consulo   Source File: QuickFixAction.java    License: Apache License 2.0 5 votes vote down vote up
/** This is used by TeamCity plugin */
@Deprecated
public static void registerQuickFixAction(@Nullable HighlightInfo info,
                                          @Nullable IntentionAction action,
                                          @Nullable List<IntentionAction> options,
                                          @Nullable String displayName) {
  if (info == null) return;
  info.registerFix(action, options, displayName, null, null);
}
 
Example 26
Source Project: intellij   Source File: HighlightingStatsCollector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void visit(PsiElement psiElement) {
  if (highlightInfoHolder == null) {
    return;
  }

  // Compute the collectors pertaining to each HighlightInfoType
  // `visit` is called for every Highlight in the file, which include keyword highlighting and
  // such.
  // Number of calls to `visit` can quickly blow up for a large file, so we want to avoid any
  // repeated computations
  if (infoTypesToCollectors == null) {
    PsiFile psiFile = psiElement.getContainingFile();
    if (psiFile == null) {
      return;
    }
    Set<BlazeHighlightStatsCollector> collectors =
        BlazeHighlightStatsCollector.getCollectorsSupportingFile(psiFile);
    infoTypesToCollectors =
        BlazeHighlightStatsCollector.getCollectorsByHighlightInfoTypes(collectors);
  }

  for (int i = 0; i < highlightInfoHolder.size(); i++) {
    HighlightInfo highlightInfo = highlightInfoHolder.get(i);
    infoTypesToCollectors
        .get(highlightInfo.type)
        .forEach(c -> c.processHighlight(psiElement, highlightInfo));
  }
}
 
Example 27
Source Project: consulo   Source File: CachedIntentions.java    License: Apache License 2.0 5 votes vote down vote up
private boolean addActionsTo(@Nonnull List<? extends HighlightInfo.IntentionActionDescriptor> newDescriptors, @Nonnull Set<? super IntentionActionWithTextCaching> cachedActions) {
  boolean changed = false;
  for (HighlightInfo.IntentionActionDescriptor descriptor : newDescriptors) {
    changed |= cachedActions.add(wrapAction(descriptor, myFile, myFile, myEditor));
  }
  return changed;
}
 
Example 28
Source Project: react-templates-plugin   Source File: RTInfoFilter.java    License: MIT License 5 votes vote down vote up
@Override
    public boolean accept(@NotNull HighlightInfo highlightInfo, PsiFile psiFile) {
        if (psiFile != null && psiFile.getName() != null && psiFile.getName().endsWith(".rt") && MSG_EMPTY_TAG.equals(highlightInfo.getDescription())) {
            return false;
        }
//        System.out.println(highlightInfo.getSeverity() + " " + highlightInfo.getDescription());
        return true;
    }
 
Example 29
@Test
public void testErrorAnnotatorOnFragments() {
    myFixture.configureByFiles("injection-comment.js");
    final List<HighlightInfo> highlighting = myFixture.doHighlighting(HighlightSeverity.ERROR);
    assertEquals("Expected just one error", 1, highlighting.size());
    assertEquals("Unknown fragment name should be the error", "OnlyTheUnknownFragmentShouldBeHighlightedAsError", highlighting.get(0).getText());
}
 
Example 30
@Test
public void testErrorAnnotatorSourceLines1() {
    myFixture.configureByFiles("lines-1/injection-source-lines-1.js");
    final List<HighlightInfo> highlighting = myFixture.doHighlighting(HighlightSeverity.ERROR);
    assertEquals("Expected just one error", 1, highlighting.size());
    assertEquals("Should mark ServerType with an error", "ServerType", highlighting.get(0).getText());
    assertEquals("Should mark ServerType in the right injected position", 201, highlighting.get(0).getStartOffset());
}