Java Code Examples for com.intellij.lang.annotation.HighlightSeverity#INFORMATION

The following examples show how to use com.intellij.lang.annotation.HighlightSeverity#INFORMATION . 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: ProblemDescriptorUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static HighlightInfoType highlightTypeFromDescriptor(@Nonnull ProblemDescriptor problemDescriptor,
                                                            @Nonnull HighlightSeverity severity,
                                                            @Nonnull SeverityRegistrar severityRegistrar) {
  final ProblemHighlightType highlightType = problemDescriptor.getHighlightType();
  switch (highlightType) {
    case GENERIC_ERROR_OR_WARNING:
      return severityRegistrar.getHighlightInfoTypeBySeverity(severity);
    case LIKE_DEPRECATED:
      return new HighlightInfoType.HighlightInfoTypeImpl(severity, HighlightInfoType.DEPRECATED.getAttributesKey());
    case LIKE_UNKNOWN_SYMBOL:
      if (severity == HighlightSeverity.ERROR) {
        return new HighlightInfoType.HighlightInfoTypeImpl(severity, HighlightInfoType.WRONG_REF.getAttributesKey());
      }
      if (severity == HighlightSeverity.WARNING) {
        return new HighlightInfoType.HighlightInfoTypeImpl(severity, CodeInsightColors.WEAK_WARNING_ATTRIBUTES);
      }
      return severityRegistrar.getHighlightInfoTypeBySeverity(severity);
    case LIKE_UNUSED_SYMBOL:
      return new HighlightInfoType.HighlightInfoTypeImpl(severity, HighlightInfoType.UNUSED_SYMBOL.getAttributesKey());
    case INFO:
      return HighlightInfoType.INFO;
    case WEAK_WARNING:
      return HighlightInfoType.WEAK_WARNING;
    case ERROR:
      return HighlightInfoType.WRONG_REF;
    case GENERIC_ERROR:
      return HighlightInfoType.ERROR;
    case INFORMATION:
      final TextAttributesKey attributes = ((ProblemDescriptorBase)problemDescriptor).getEnforcedTextAttributes();
      if (attributes != null) {
        return new HighlightInfoType.HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, attributes);
      }
      return HighlightInfoType.INFORMATION;
  }
  throw new RuntimeException("Cannot map " + highlightType);
}
 
Example 2
Source File: SeverityRegistrar.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public HighlightInfoType.HighlightInfoTypeImpl getHighlightInfoTypeBySeverity(@Nonnull HighlightSeverity severity) {
  HighlightInfoType infoType = STANDARD_SEVERITIES.get(severity.getName());
  if (infoType != null) {
    return (HighlightInfoType.HighlightInfoTypeImpl)infoType;
  }

  if (severity == HighlightSeverity.INFORMATION){
    return (HighlightInfoType.HighlightInfoTypeImpl)HighlightInfoType.INFORMATION;
  }

  final SeverityBasedTextAttributes type = getAttributesBySeverity(severity);
  return (HighlightInfoType.HighlightInfoTypeImpl)(type == null ? HighlightInfoType.WARNING : type.getType());
}
 
Example 3
Source File: HighlightInfoFilterImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean accept(@Nonnull HighlightInfo info, PsiFile file) {
  if (ourTestMode) return true; // Tests need to verify highlighting is applied no matter what attributes are defined for this kind of highlighting

  TextAttributes attributes = info.getTextAttributes(file, null);
  // optimization
   return attributes == TextAttributes.ERASE_MARKER || attributes != null &&
         !(attributes.isEmpty() && info.getSeverity() == HighlightSeverity.INFORMATION && info.getGutterIconRenderer() == null);
}
 
Example 4
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 5
Source File: SeveritiesProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean isGotoBySeverityEnabled(HighlightSeverity minSeverity) {
  return minSeverity != HighlightSeverity.INFORMATION;
}
 
Example 6
Source File: SeverityRegistrar.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isGotoBySeverityEnabled(@Nonnull HighlightSeverity minSeverity) {
  for (SeveritiesProvider provider : SeveritiesProvider.EP_NAME.getExtensionList()) {
    if (provider.isGotoBySeverityEnabled(minSeverity)) return true;
  }
  return minSeverity != HighlightSeverity.INFORMATION;
}