Java Code Examples for com.intellij.lang.annotation.AnnotationHolder#createWarningAnnotation()

The following examples show how to use com.intellij.lang.annotation.AnnotationHolder#createWarningAnnotation() . 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: LSPAnnotator.java    From lsp4intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
protected Annotation createAnnotation(Editor editor, AnnotationHolder holder, Diagnostic diagnostic) {
    final int start = DocumentUtils.LSPPosToOffset(editor, diagnostic.getRange().getStart());
    final int end = DocumentUtils.LSPPosToOffset(editor, diagnostic.getRange().getEnd());
    if (start >= end) {
        return null;
    }
    final TextRange textRange = new TextRange(start, end);
    switch (diagnostic.getSeverity()) {
        // TODO: Use 'newAnnotation'; 'create*Annotation' methods are deprecated.
        case Error:
            return holder.createErrorAnnotation(textRange, diagnostic.getMessage());
        case Warning:
            return holder.createWarningAnnotation(textRange, diagnostic.getMessage());
        case Information:
            return holder.createInfoAnnotation(textRange, diagnostic.getMessage());
        default:
            return holder.createWeakWarningAnnotation(textRange, diagnostic.getMessage());
    }
}
 
Example 2
Source File: ErrorAnnotator.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@Override
public void apply(@NotNull PsiFile file, @NotNull Collection<BsbErrorAnnotation> annotationResult, @NotNull AnnotationHolder holder) {
    WolfTheProblemSolver problemSolver = WolfTheProblemSolver.getInstance(file.getProject());
    Collection<Problem> problems = new ArrayList<>();

    for (BsbErrorAnnotation annotation : annotationResult) {
        if (annotation.isError) {
            holder.createErrorAnnotation(annotation.range, annotation.message);
            problems.add(problemSolver.convertToProblem(file.getVirtualFile(), annotation.startPos.line, annotation.startPos.column,
                                                        new String[]{annotation.message}));
        } else {
            holder.createWarningAnnotation(annotation.range, annotation.message);
        }
    }

    problemSolver.reportProblems(file.getVirtualFile(), problems);
}
 
Example 3
Source File: IconAnnotator.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
private void annotateIconUsage(PsiElement psiElement, AnnotationHolder annotationHolder, String value) {
    if (IconIndex.getAllAvailableIcons(psiElement.getProject()).contains(value)) {
        return;
    }

    annotationHolder.createWarningAnnotation(new TextRange(psiElement.getTextRange().getStartOffset() + 1, psiElement.getTextRange().getEndOffset() - 1), "Unresolved icon - this may also occur if the icon is defined in your extension, but not in the global icon registry.");
}
 
Example 4
Source File: CamelEndpointAnnotator.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
private void extractSetValue(EndpointValidationResult result, Set<String> validationSet, String fromElement, PsiElement element,
                             AnnotationHolder holder, CamelAnnotatorEndpointMessage msg, boolean lenient) {
    if (validationSet != null && (lenient || !result.isSuccess())) {

        for (String entry : validationSet) {
            String propertyValue = entry;

            int startIdxQueryParameters = fromElement.indexOf("?" + propertyValue);
            startIdxQueryParameters = (startIdxQueryParameters == -1) ? fromElement.indexOf("&" + propertyValue) : fromElement.indexOf("?");

            int propertyIdx = fromElement.indexOf(propertyValue, startIdxQueryParameters);
            int propertyLength = propertyValue.length();

            propertyIdx = getIdeaUtils().isJavaLanguage(element) || getIdeaUtils().isXmlLanguage(element)  ? propertyIdx + 1  : propertyIdx;

            TextRange range = new TextRange(element.getTextRange().getStartOffset() + propertyIdx,
                element.getTextRange().getStartOffset() + propertyIdx + propertyLength);

            if (msg.isInfoLevel()) {
                holder.createInfoAnnotation(range, summaryMessage(result, propertyValue, msg));
            } else if (msg.isWarnLevel()) {
                holder.createWarningAnnotation(range, summaryMessage(result, propertyValue, msg));
            } else {
                holder.createErrorAnnotation(range, summaryMessage(result, propertyValue, msg));
            }
        }
    }
}
 
Example 5
Source File: StructureMemberQualifierAnnotation.java    From glsl4idea with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void annotate(GLSLStructMemberDeclaration expr, AnnotationHolder holder) {
    for (GLSLQualifier qualifier : expr.getQualifiers()) {
        final GLSLTypeQualifier type = qualifier.getQualifierType();
        if (type == null) continue;
        if (type != GLSLTypeQualifier.PRECISION_QUALIFIER) {
            holder.createWarningAnnotation(qualifier,
                    "GLSL 4.50: Member declarators may contain precision qualifiers, " +
                            "but use of any other qualifier results in a compile-time error." +
                            " (You may put the qualifier on the whole struct.)");
        }
    }
}
 
Example 6
Source File: ReservedIdentifierAnnotation.java    From glsl4idea with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void annotate(GLSLIdentifier identifier, AnnotationHolder holder) {
    String name = identifier.getName();
    if (name.startsWith("__")) {
        holder.createWarningAnnotation(identifier, "This identifier is reserved for use by underlying software layers and may result in undefined behavior.");
    }
}
 
Example 7
Source File: WebReferencesAnnotatorBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(@Nonnull PsiFile file, MyInfo[] infos, @Nonnull AnnotationHolder holder) {
  if (infos.length == 0) {
    return;
  }

  final HighlightDisplayLevel displayLevel = getHighlightDisplayLevel(file);

  for (MyInfo info : infos) {
    if (!info.myResult) {
      final PsiElement element = info.myAnchor.retrieve();
      if (element != null) {
        final int start = element.getTextRange().getStartOffset();
        final TextRange range = new TextRange(start + info.myRangeInElement.getStartOffset(), start + info.myRangeInElement.getEndOffset());
        final String message = getErrorMessage(info.myUrl);

        final Annotation annotation;

        if (displayLevel == HighlightDisplayLevel.ERROR) {
          annotation = holder.createErrorAnnotation(range, message);
        }
        else if (displayLevel == HighlightDisplayLevel.WARNING) {
          annotation = holder.createWarningAnnotation(range, message);
        }
        else if (displayLevel == HighlightDisplayLevel.WEAK_WARNING) {
          annotation = holder.createInfoAnnotation(range, message);
        }
        else {
          annotation = holder.createWarningAnnotation(range, message);
        }

        for (IntentionAction action : getQuickFixes()) {
          annotation.registerFix(action);
        }
      }
    }
  }
}
 
Example 8
Source File: PathResourceAnnotator.java    From idea-php-typo3-plugin with MIT License 4 votes vote down vote up
private void createErrorMessage(@NotNull PsiElement element, @NotNull AnnotationHolder holder, String resourceName) {
    String message = "Resource \"%s\" could not be found in your current project.".replace("%s", resourceName);

    holder.createWarningAnnotation(element, message);
}
 
Example 9
Source File: SwitchAnnotation.java    From glsl4idea with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void annotate(GLSLSwitchStatement expr, AnnotationHolder holder) {
    final GLSLExpression switchCondition = expr.getSwitchCondition();
    if (switchCondition == null) return;

    final GLSLType switchConditionType = switchCondition.getType();
    if (!switchConditionType.isValidType()) return;

    if (!GLSLScalarType.isIntegerScalar(switchConditionType)) {
        holder.createErrorAnnotation(switchCondition, "Expression must be of integer scalar type");
    } else if (switchCondition.isConstantValue()) {
        holder.createWeakWarningAnnotation(switchCondition, "Expression is constant");
    }

    final List<GLSLLabelStatement> labelStatements = expr.getLabelStatements();


    Set<Object> encounteredCases = new HashSet<>();
    boolean defaultFound = false;

    for (GLSLLabelStatement label : labelStatements) {
        if (label instanceof GLSLDefaultStatement) {
            if (defaultFound) {
                holder.createErrorAnnotation(label, "Multiple default labels are not allowed");
            }
            defaultFound = true;
        } else if (label instanceof GLSLCaseStatement) {//This _should_ be the only possible way
            final GLSLCaseStatement caseLabel = (GLSLCaseStatement) label;
            final GLSLExpression caseExpression = caseLabel.getCaseExpression();
            if (caseExpression != null) {
                final GLSLType caseExpressionType = caseExpression.getType();
                if (caseExpressionType.isValidType()) {
                    if (!GLSLScalarType.isIntegerScalar(caseExpressionType)) {
                        holder.createErrorAnnotation(caseExpression, "Case expression must be of integer scalar type");
                    } else {
                        //It is a valid type, do dupe check
                        if (caseExpression.isConstantValue()) {
                            Object constantValue = caseExpression.getConstantValue();
                            //constantValue should be Long, but don't dwell on that
                            if (encounteredCases.contains(constantValue)) {
                                holder.createWarningAnnotation(caseExpression, "Duplicate case label (" + constantValue + ")");
                            }
                            encounteredCases.add(constantValue);
                        }
                    }
                }
            }
        }
    }
}
 
Example 10
Source File: ANTLRv4ExternalAnnotator.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void annotateFileIssue(@NotNull PsiFile file, @NotNull AnnotationHolder holder, GrammarIssue issue) {
	Annotation annotation = holder.createWarningAnnotation(file, issue.getAnnotation());
	annotation.setFileLevelAnnotation(true);
}