@Override
 public void visitReferenceExpression(@NotNull JetReferenceExpression expression) {
   super.visitReferenceExpression(expression);
   ResolvedCall resolvedCall = CallUtilPackage.getResolvedCall(expression, bindingContext);
   if (resolvedCall != null && resolvedCall instanceof VariableAsFunctionResolvedCall) {
     // Deprecated for invoke()
     JetCallExpression parent = PsiTreeUtil.getParentOfType(expression, JetCallExpression.class);
     if (parent != null) {
       reportAnnotationIfNeeded(parent, resolvedCall.getResultingDescriptor(), true);
     }
   }
   if (expression.getNode().getElementType() == JetNodeTypes.OPERATION_REFERENCE) {
     // Deprecated for operations (mark as warning)
     checkDeprecatedForOperations(expression);
   } else {
     checkDeprecatedForReferenceExpression(expression);
   }
 }
 public DiagnosticWithParameters1<JetReferenceExpression, String> on(
     @NotNull JetReferenceExpression reference) {
   return new DiagnosticWithParameters1<JetReferenceExpression, String>(
       reference, reference.getText(), this, severity);
 }
Example #3
0
  private static void registerDiagnosticAnnotations(
      @NotNull Diagnostic diagnostic,
      @NotNull Set<PsiElement> redeclarations,
      @NotNull final AnnotationHolder holder) {
    List<TextRange> textRanges = diagnostic.getTextRanges();
    if (diagnostic.getSeverity() == Severity.ERROR) {
      if (diagnostic.getFactory() == Errors.UNRESOLVED_IDE_TEMPLATE) {
        return;
      }
      if (diagnostic instanceof UnresolvedReferenceDiagnostic) {
        UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic =
            (UnresolvedReferenceDiagnostic) diagnostic;
        JetReferenceExpression referenceExpression = unresolvedReferenceDiagnostic.getPsiElement();
        PsiReference reference = referenceExpression.getReference();
        if (reference instanceof MultiRangeReference) {
          MultiRangeReference mrr = (MultiRangeReference) reference;
          for (TextRange range : mrr.getRanges()) {
            Annotation annotation =
                holder.createErrorAnnotation(
                    range.shiftRight(referenceExpression.getTextOffset()), diagnostic.getMessage());

            registerQuickFix(annotation, diagnostic);

            annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
          }
        } else {
          for (TextRange textRange : textRanges) {
            Annotation annotation =
                holder.createErrorAnnotation(textRange, diagnostic.getMessage());
            registerQuickFix(annotation, diagnostic);
            annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
          }
        }

        return;
      }

      if (diagnostic.getFactory() == Errors.ILLEGAL_ESCAPE_SEQUENCE) {
        for (TextRange textRange : diagnostic.getTextRanges()) {
          Annotation annotation = holder.createErrorAnnotation(textRange, diagnostic.getMessage());
          annotation.setTextAttributes(JetHighlightingColors.INVALID_STRING_ESCAPE);
        }
      }

      if (diagnostic instanceof RedeclarationDiagnostic) {
        RedeclarationDiagnostic redeclarationDiagnostic = (RedeclarationDiagnostic) diagnostic;
        registerQuickFix(
            markRedeclaration(redeclarations, redeclarationDiagnostic, holder), diagnostic);
        return;
      }

      // Generic annotation
      for (TextRange textRange : textRanges) {
        Annotation errorAnnotation =
            holder.createErrorAnnotation(textRange, getMessage(diagnostic));
        registerQuickFix(errorAnnotation, diagnostic);

        if (diagnostic.getFactory() == Errors.INVISIBLE_REFERENCE) {
          errorAnnotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
        }
      }
    } else if (diagnostic.getSeverity() == Severity.WARNING) {
      for (TextRange textRange : textRanges) {
        Annotation annotation = holder.createWarningAnnotation(textRange, getMessage(diagnostic));
        registerQuickFix(annotation, diagnostic);

        if (diagnostic.getFactory() instanceof UnusedElementDiagnosticFactory) {
          annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL);
        }
      }
    }
  }