com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder Java Examples

The following examples show how to use com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder. 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 File: PantsScalaHighlightVisitor.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean analyze(
  @NotNull PsiFile file,
  boolean updateWholeFile,
  @NotNull HighlightInfoHolder holder,
  @NotNull Runnable action
) {
  myHolder = holder;
  try {
    action.run();
  }
  finally {
    myHolder = null;
  }
  return true;
}
 
Example #2
Source File: InjectedGeneralHighlightingPass.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void runHighlightVisitorsForInjected(@Nonnull PsiFile injectedPsi, @Nonnull HighlightInfoHolder holder) {
  HighlightVisitor[] filtered = getHighlightVisitors(injectedPsi);
  try {
    final List<PsiElement> elements = CollectHighlightsUtil.getElementsInRange(injectedPsi, 0, injectedPsi.getTextLength());
    for (final HighlightVisitor visitor : filtered) {
      visitor.analyze(injectedPsi, true, holder, () -> {
        for (PsiElement element : elements) {
          ProgressManager.checkCanceled();
          visitor.visit(element);
        }
      });
    }
  }
  finally {
    incVisitorUsageCount(-1);
  }
}
 
Example #3
Source File: RainbowVisitor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public final boolean analyze(@Nonnull PsiFile file,
                             boolean updateWholeFile,
                             @Nonnull HighlightInfoHolder holder,
                             @Nonnull Runnable action) {
  myHolder = holder;
  myRainbowHighlighter = new RainbowHighlighter(myHolder.getColorsScheme());
  try {
    action.run();
  }
  finally {
    myHolder = null;
    myRainbowHighlighter = null;
  }
  return true;
}
 
Example #4
Source File: DefaultHighlightVisitor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean analyze(@Nonnull final PsiFile file,
                       final boolean updateWholeFile,
                       @Nonnull final HighlightInfoHolder holder,
                       @Nonnull final Runnable action) {
  myHolder = holder;
  myAnnotationHolder = new AnnotationHolderImpl(holder.getAnnotationSession(), myBatchMode);
  try {
    action.run();
  }
  finally {
    myAnnotationHolder.clear();
    myAnnotationHolder = null;
    myHolder = null;
  }
  return true;
}
 
Example #5
Source File: GenericParameterHighlightUtil.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
public static void checkInAndOutModifiers(DotNetGenericParameter parameter, HighlightInfoHolder highlightInfoHolder)
{
	DotNetModifierList modifierList = parameter.getModifierList();
	if(modifierList == null)
	{
		return;
	}

	PsiElement outModifierElement = modifierList.getModifierElement(CSharpModifier.OUT);
	PsiElement inModifierElement = modifierList.getModifierElement(CSharpModifier.IN);
	if(outModifierElement != null && inModifierElement != null)
	{
		registerInOutProblem(parameter, highlightInfoHolder, outModifierElement, CSharpModifier.OUT);
		registerInOutProblem(parameter, highlightInfoHolder, inModifierElement, CSharpModifier.IN);
	}
}
 
Example #6
Source File: GenericParameterHighlightUtil.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: HighlightingStatsCollector.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public boolean analyze(
    PsiFile psiFile,
    boolean updateWholeFile,
    HighlightInfoHolder highlightInfoHolder,
    Runnable runnable) {
  if (!enabled.getValue()) {
    runnable.run();
    return true;
  }

  // Only analyze if the whole file is being highlighted.
  // We avoid analyzing partial highlights because they typically happen when the user is editing
  // a file. This creates noise as IntelliJ tries to keep highlights up to date with each
  // user keystroke.
  if (updateWholeFile) {
    this.highlightInfoHolder = highlightInfoHolder;
  }

  try {
    runnable.run();
  } finally {
    this.highlightInfoHolder = null;
  }
  return true;
}
 
Example #8
Source File: CSharpHighlightVisitor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public boolean analyze(@Nonnull PsiFile psiFile, boolean b, @Nonnull HighlightInfoHolder highlightInfoHolder, @Nonnull Runnable runnable)
{
	myHighlightInfoHolder = highlightInfoHolder;
	myProcessedLines.clear();
	myDocument = PsiDocumentManager.getInstance(psiFile.getProject()).getCachedDocument(psiFile);
	runnable.run();
	myDocument = null;
	return true;
}
 
Example #9
Source File: CppErrorHighlightingHandler.java    From CppTools with Apache License 2.0 5 votes vote down vote up
public boolean analyze(@NotNull PsiFile psiFile, boolean wholeFile, HighlightInfoHolder highlightInfoHolder, @NotNull Runnable runnable) {
  if (!wholeFile) {
    runnable.run();
    return true;
  }
  myReadyToHighlight = true;
  myHighlightInfoHolder = highlightInfoHolder;
  runnable.run();
  return true;
}
 
Example #10
Source File: GeneralHighlightingPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean analyzeByVisitors(@Nonnull final HighlightVisitor[] visitors, @Nonnull final HighlightInfoHolder holder, final int i, @Nonnull final Runnable action) {
  final boolean[] success = {true};
  if (i == visitors.length) {
    action.run();
  }
  else {
    if (!visitors[i].analyze(getFile(), myUpdateAll, holder, () -> success[0] = analyzeByVisitors(visitors, holder, i + 1, action))) {
      success[0] = false;
    }
  }
  return success[0];
}
 
Example #11
Source File: CSharpHighlightUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@RequiredReadAction
public static HighlightInfo highlightNamed(@Nonnull HighlightInfoHolder holder, @Nullable PsiElement element, @Nullable PsiElement target, @Nullable PsiElement owner)
{
	if(target == null || element == null)
	{
		return null;
	}

	IElementType elementType = target.getNode().getElementType();
	if(CSharpTokenSets.KEYWORDS.contains(elementType))  // don't highlight keywords
	{
		return null;
	}

	if(isMethodRef(owner, element))
	{
		HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(target).textAttributes(CSharpHighlightKey.METHOD_REF).create();
		holder.add(highlightInfo);
	}

	TextAttributesKey defaultTextAttributeKey = getDefaultTextAttributeKey(element, target);
	if(defaultTextAttributeKey == null)
	{
		return null;
	}

	HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(target).textAttributes(defaultTextAttributeKey).create();
	holder.add(info);
	if(!(target instanceof CSharpIdentifier) && DotNetAttributeUtil.hasAttribute(element, DotNetTypes.System.ObsoleteAttribute))
	{
		holder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(target).textAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES).create());
	}

	return info;
}
 
Example #12
Source File: CSharpCompilerCheckVisitor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public boolean analyze(@Nonnull PsiFile psiFile, boolean b, @Nonnull HighlightInfoHolder highlightInfoHolder, @Nonnull Runnable runnable)
{
	myPragmaContext = CSharpPragmaContext.get(psiFile);
	myHighlightContext = new CSharpHighlightContext(psiFile);
	myHighlightInfoHolder = highlightInfoHolder;
	runnable.run();
	myHighlightContext = null;

	return true;
}
 
Example #13
Source File: SharpLabHighlightVisitor.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Override
public boolean analyze(@Nonnull PsiFile file, boolean updateWholeFile, @Nonnull HighlightInfoHolder holder, @Nonnull Runnable action)
{
	myHolder = holder;
	action.run();
	return true;
}
 
Example #14
Source File: GeneralHighlightingPass.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected HighlightInfoHolder createInfoHolder(@Nonnull PsiFile file) {
  final HighlightInfoFilter[] filters = HighlightInfoFilter.EXTENSION_POINT_NAME.getExtensions();
  return new CustomHighlightInfoHolder(file, getColorsScheme(), filters);
}
 
Example #15
Source File: CheckLevelHighlightInfoHolder.java    From consulo with Apache License 2.0 4 votes vote down vote up
public CheckLevelHighlightInfoHolder(@Nonnull PsiFile file, @Nonnull HighlightInfoHolder holder) {
  super(file);
  myHolder = holder;
}
 
Example #16
Source File: JSGraphQLQueryContextHighlightVisitor.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
/**
 * Highlights the operation, if any, that wraps the current caret position.
 * Fragments used from the operation are highlighted recursively.
 */
@Override
public boolean analyze(final @NotNull PsiFile file, boolean updateWholeFile, @NotNull HighlightInfoHolder holder, @NotNull Runnable action) {

    // run the default pass first (DefaultHighlightVisitor) which calls annotators etc.
    action.run();

    final PsiElement operationAtCursor = getOperationAtCursor(file);
    if (operationAtCursor != null && hasMultipleVisibleTopLevelElement(file)) {

        // store the range of the current operation for use in the caret listener
        file.putUserData(QUERY_OPERATION_TEXT_RANGE, operationAtCursor.getTextRange());

        final Color borderColor = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.TEARLINE_COLOR);
        final TextAttributes textAttributes = new TextAttributes(null, null, borderColor, EffectType.ROUNDED_BOX, Font.PLAIN);
        final Map<String, GraphQLFragmentDefinition> foundFragments = Maps.newHashMap();
        findFragmentsInsideOperation(operationAtCursor, foundFragments, null);
        for (PsiElement psiElement : file.getChildren()) {
            boolean showAsUsed = false;
            if (psiElement instanceof GraphQLFragmentDefinition) {
                GraphQLFragmentDefinition definition = (GraphQLFragmentDefinition) psiElement;
                if (definition.getOriginalElement() instanceof GraphQLFragmentDefinition) {
                    // use the original PSI to compare since a separate editor tab has its own version of the PSI
                    definition = (GraphQLFragmentDefinition) definition.getOriginalElement();
                }
                showAsUsed = foundFragments.containsKey(getFragmentKey(definition));
            } else if (psiElement == operationAtCursor) {
                showAsUsed = true;
            }
            if (showAsUsed) {
                final TextRange range = psiElement.getTextRange();
                final Annotation annotation = new Annotation(range.getStartOffset(), range.getEndOffset(), HighlightSeverity.INFORMATION, ELEMENT_INCLUDED_MESSAGE, null);
                annotation.setEnforcedTextAttributes(textAttributes);
                holder.add(HighlightInfo.fromAnnotation(annotation));
            }
        }

    } else {
        file.putUserData(QUERY_OPERATION_TEXT_RANGE, null);
    }


    // find the editor that was highlighted and listen for caret changes to update the active operation
    UIUtil.invokeLaterIfNeeded(() -> {
        final FileEditor fileEditor = FileEditorManager.getInstance(file.getProject()).getSelectedEditor(file.getVirtualFile());
        if (fileEditor instanceof TextEditor) {
            final Editor editor = ((TextEditor) fileEditor).getEditor();
            if (!Boolean.TRUE.equals(editor.getUserData(QUERY_HIGHLIGHT_LISTENER_ADDED))) {
                editor.getCaretModel().addCaretListener(new CaretListener() {
                    @Override
                    public void caretPositionChanged(CaretEvent e) {
                        // re-highlight when the operation changes

                        final Editor currentEditor = e.getEditor();
                        final Project project = currentEditor.getProject();
                        if (project != null) {

                            final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(currentEditor.getDocument());
                            if (psiFile != null) {

                                final TextRange previousOperationRange = psiFile.getUserData(QUERY_OPERATION_TEXT_RANGE);
                                psiFile.putUserData(QUERY_FROM_SELECTION, currentEditor.getSelectionModel().hasSelection());

                                boolean sameOperation = false;
                                boolean hadOperation = (previousOperationRange != null);
                                if (hadOperation) {
                                    // check if we're still inside the range of the previously highlighted op
                                    final int newOffset = currentEditor.logicalPositionToOffset(e.getNewPosition());
                                    sameOperation = previousOperationRange.contains(newOffset);
                                    if (sameOperation && !Boolean.TRUE.equals(psiFile.getUserData(QUERY_FROM_SELECTION))) {
                                        // still the same op, and we didn't select text before, so no need to proceed
                                        return;
                                    }
                                }

                                // remove existing unused query text range highlights
                                removeHighlights(currentEditor, project);

                                if (!sameOperation) {
                                    // moved to somewhere outside the previous operation
                                    if (hadOperation || getOperationAtCursor(psiFile) != null) {
                                        // perform a new highlighting pass
                                        DaemonCodeAnalyzer.getInstance(project).restart(psiFile);
                                    }
                                }
                            }
                        }
                    }
                });
                // finally indicate we've added the listener
                editor.putUserData(QUERY_HIGHLIGHT_LISTENER_ADDED, true);
            }
        }
    });

    return true;
}
 
Example #17
Source File: HighlightVisitor.java    From consulo with Apache License 2.0 votes vote down vote up
boolean analyze(@Nonnull PsiFile file, final boolean updateWholeFile, @Nonnull HighlightInfoHolder holder, @Nonnull Runnable action);