protected void collectMessagesForNodesWithErrors(
     TypeCheckingContext context,
     final EditorContext editorContext,
     Set<EditorMessage> messages,
     boolean typesystemErrors) {
   for (Pair<SNode, List<IErrorReporter>> errorNode :
       context.getNodesWithErrors(typesystemErrors)) {
     List<IErrorReporter> errors = new ArrayList<IErrorReporter>(errorNode.o2);
     Collections.sort(
         errors,
         new Comparator<IErrorReporter>() {
           @Override
           public int compare(IErrorReporter o1, IErrorReporter o2) {
             return o2.getMessageStatus().compareTo(o1.getMessageStatus());
           }
         });
     boolean instantIntentionApplied = false;
     for (IErrorReporter errorReporter : errors) {
       MessageStatus status = errorReporter.getMessageStatus();
       String errorString = errorReporter.reportError();
       HighlighterMessage message =
           HighlightUtil.createHighlighterMessage(
               errorNode.o1,
               NameUtil.capitalize(status.getPresentation()) + ": " + errorString,
               errorReporter,
               AbstractTypesystemEditorChecker.this,
               editorContext);
       List<QuickFixProvider> intentionProviders = message.getIntentionProviders();
       final SNode quickFixNode = errorNode.o1;
       if (intentionProviders.size() == 1
           && intentionProviders.get(0) != null
           && intentionProviders.get(0).isExecutedImmediately()
           && !AbstractTypesystemEditorChecker.IMMEDIATE_QFIX_DISABLED) {
         QuickFixProvider intentionProvider = intentionProviders.get(0);
         if (!instantIntentionApplied) {
           instantIntentionApplied =
               applyInstantIntention(editorContext, quickFixNode, intentionProvider);
         }
       } else {
         messages.add(message);
       }
     }
   }
 }
Example #2
0
  public static void checkNodeHasMessageWithStatus(SNode operation, MessageStatus messageStatus) {
    final SNode nodeToCheck =
        INodesTestMethod__BehaviorDescriptor.getAnnotatedNode_id38gbJV0XvZR.invoke(operation);
    TestsErrorsChecker checker =
        new TestsErrorsChecker(SNodeOperations.getContainingRoot(nodeToCheck));
    final Iterable<IErrorReporter> errorReporters =
        checker.getErrorsSpecificType(nodeToCheck, messageStatus);

    final String errorString =
        "node <"
            + NodeCheckerUtil.nodeWithIdToString(nodeToCheck)
            + "> does not have expected "
            + messageStatus.getPresentation()
            + " message";

    Assert.assertTrue(
        errorString,
        (boolean)
            IChecksRules__BehaviorDescriptor.hasExpectedRuleMessage_id4CT6QR8SJl8.invoke(
                operation, errorReporters, SNodeOperations.getModel(nodeToCheck).getRepository()));
  }
Example #3
0
  public Set<EditorMessage> doCreateMessages(
      SNode node, List<SModelEvent> list, boolean wasCheckedOnce, EditorContext editorContext) {
    myMessagesChanged = false;
    EditorComponent editorComponent = (EditorComponent) editorContext.getEditorComponent();
    SNode sNode = editorComponent.getEditedNode();
    SNodeReference sNodePointer = editorComponent.getEditedNodePointer();

    Set<EditorMessage> result = SetSequence.fromSet(new HashSet<EditorMessage>());
    if (sNode == null) {
      if (LOG.isEnabledFor(Priority.ERROR)) {
        LOG.error("edited node is null");
      }
      return result;
    }
    if (sNodePointer == null) {
      if (LOG.isEnabledFor(Priority.ERROR)) {
        LOG.error("edited NodePointer is null");
      }
      return result;
    }

    SModel descriptor = SNodeOperations.getModel(sNode);
    if (descriptor == null) {
      // descriptor is null for a replaced model
      // after model is replaced but before it is disposed (this can happen asyncronously)
      return result;
    }
    LanguageErrorsComponent errorsComponent =
        MapSequence.fromMap(myNodePointersToComponents)
            .get(new SNodePointer(SNodeOperations.getContainingRoot(sNode)));
    if (errorsComponent == null) {
      errorsComponent = new LanguageErrorsComponent(sNode);
      MapSequence.fromMap(myNodePointersToComponents).put(sNodePointer, errorsComponent);
    }
    if (!(editorComponent instanceof InspectorEditorComponent)
        && !(SetSequence.fromSet(myEditorComponents).contains(editorComponent))) {
      SetSequence.fromSet(myEditorComponents).addElement(editorComponent);
      editorComponent.addDisposeListener(myDisposeListener);
    }
    addModelListener(descriptor);

    if (!(wasCheckedOnce)) {
      errorsComponent.clear();
    }
    boolean changed = false;
    TypeCheckingContext typecheckingContext = editorComponent.getTypeCheckingContext();
    try {
      if (typecheckingContext != null) {
        typecheckingContext.setIsNonTypesystemComputation();
      }
      changed = errorsComponent.check(node, myRules, editorContext.getOperationContext());
    } finally {
      if (typecheckingContext != null) {
        typecheckingContext.resetIsNonTypesystemComputation();
      }
    }
    myMessagesChanged = changed;
    for (IErrorReporter errorReporter : errorsComponent.getErrors()) {
      MessageStatus status = errorReporter.getMessageStatus();
      String errorString = errorReporter.reportError();
      HighlighterMessage message =
          HighlightUtil.createHighlighterMessage(
              errorReporter.getSNode(),
              NameUtil.capitalize(status.getPresentation()) + ": " + errorString,
              errorReporter,
              LanguageEditorChecker.this,
              editorContext);
      SetSequence.fromSet(result).addElement(message);
    }
    return result;
  }