package jetbrains.mps.ide.highlighters.structure;

/*Generated by MPS */

import jetbrains.mps.annotations.GeneratedClass;
import jetbrains.mps.nodeEditor.checking.BaseEventProcessingEditorChecker;
import jetbrains.mps.project.MPSProject;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.nodeEditor.checking.UpdateResult;
import jetbrains.mps.nodeEditor.EditorComponent;
import jetbrains.mps.util.Cancellable;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import java.util.List;
import jetbrains.mps.nodeEditor.EditorMessage;
import java.util.Collections;
import jetbrains.mps.ide.findusages.model.scopes.GlobalScope;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;

@GeneratedClass(node = "r:8da2312b-c61c-4a7c-bb90-3ea3623b8abe(jetbrains.mps.ide.highlighters.structure)/1401464578585832882", model = "r:8da2312b-c61c-4a7c-bb90-3ea3623b8abe(jetbrains.mps.ide.highlighters.structure)")
public final class OverrideConceptsChecker extends BaseEventProcessingEditorChecker {
  private static final int MAX_ITEMS_TO_SHOW = 5;

  private final MPSProject myProject;

  public OverrideConceptsChecker(@NotNull MPSProject project) {
    myProject = project;
  }

  @NotNull
  @Override
  public UpdateResult update(EditorComponent component, boolean incremental, boolean applyQuickFixes, Cancellable cancellable) {
    SNode rootNode = component.getEditedNode();
    if (!(SNodeOperations.isInstanceOf(rootNode, CONCEPTS.AbstractConceptDeclaration$KA))) {
      return new UpdateResult.Completed(false, emptyListEditorMessage());
    }

    List<EditorMessage> result = calculateEditorMessages(SNodeOperations.cast(rootNode, CONCEPTS.AbstractConceptDeclaration$KA), cancellable);
    if (cancellable.isCancelled()) {
      return new UpdateResult.Cancelled();
    }
    return new UpdateResult.Completed(true, result);
  }

  private static List<EditorMessage> emptyListEditorMessage() {
    return Collections.<EditorMessage>emptyList();
  }

  @NotNull
  private List<EditorMessage> calculateEditorMessages(SNode concept, Cancellable cancellable) {
    EditorMessage msg = new DescendantsLookup(cancellable, new GlobalScope(myProject), concept, this, MAX_ITEMS_TO_SHOW).calcMessage();
    return (msg == null ? Collections.<EditorMessage>emptyList() : Collections.singletonList(msg));
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept AbstractConceptDeclaration$KA = MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x1103553c5ffL, "jetbrains.mps.lang.structure.structure.AbstractConceptDeclaration");
  }
}
