package jetbrains.mps.lang.text.behavior;

/*Generated by MPS */

import jetbrains.mps.core.aspects.behaviour.BaseBHDescriptor;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.core.aspects.behaviour.api.SMethod;
import jetbrains.mps.core.aspects.behaviour.SMethodBuilder;
import jetbrains.mps.core.aspects.behaviour.SJavaCompoundTypeImpl;
import jetbrains.mps.core.aspects.behaviour.AccessPrivileges;
import org.jetbrains.mps.openapi.model.SNode;
import java.util.List;
import java.util.Arrays;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.internal.collections.runtime.Sequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import java.util.Objects;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import jetbrains.mps.core.aspects.behaviour.api.SConstructor;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.core.aspects.behaviour.api.BHMethodNotFoundException;
import org.jetbrains.mps.openapi.language.SConcept;
import org.jetbrains.mps.openapi.language.SProperty;

public final class TextualElement__BehaviorDescriptor extends BaseBHDescriptor {
  private static final SAbstractConcept CONCEPT = MetaAdapterFactory.getConcept(0xc7fb639fbe784307L, 0x89b0b5959c3fa8c8L, 0x2c99af34e20d9cfbL, "jetbrains.mps.lang.text.structure.TextualElement");

  public static final SMethod<String> getTextualRepresentation_id69wk_bF5sg9 = new SMethodBuilder<String>(new SJavaCompoundTypeImpl(String.class)).name("getTextualRepresentation").modifiers(12, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(7088756329566028809L).languageId(0x89b0b5959c3fa8c8L, 0xc7fb639fbe784307L).build2();
  public static final SMethod<SNode> findPreviousWordStart_id3VJiP1sDlYQ = new SMethodBuilder<SNode>(new SJavaCompoundTypeImpl((Class<SNode>) ((Class) Object.class))).name("findPreviousWordStart").modifiers(0, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(4534926158309187510L).languageId(0x89b0b5959c3fa8c8L, 0xc7fb639fbe784307L).build2();
  public static final SMethod<SNode> findNextWordEnd_id3VJiP1sDz5g = new SMethodBuilder<SNode>(new SJavaCompoundTypeImpl((Class<SNode>) ((Class) Object.class))).name("findNextWordEnd").modifiers(0, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(4534926158309241168L).languageId(0x89b0b5959c3fa8c8L, 0xc7fb639fbe784307L).build2();

  private static final List<SMethod<?>> BH_METHODS = Arrays.<SMethod<?>>asList(getTextualRepresentation_id69wk_bF5sg9, findPreviousWordStart_id3VJiP1sDlYQ, findNextWordEnd_id3VJiP1sDz5g);

  private static void ___init___(@NotNull SNode __thisNode__) {
  }

  /*package*/ static SNode findPreviousWordStart_id3VJiP1sDlYQ(@NotNull SNode __thisNode__) {
    SNode closest = Sequence.fromIterable(SNodeOperations.ofConcept(SNodeOperations.getPrevSiblings(__thisNode__, false), CONCEPTS.TextualElement$9C)).where((it) -> !(SNodeOperations.isInstanceOf(it, CONCEPTS.Letter$kd)) || Objects.equals(SPropertyOperations.getString(SNodeOperations.as(it, CONCEPTS.Letter$kd), PROPS.value$X7Tp), " ")).last();
    if ((closest == null)) {
      return SNodeOperations.as(ListSequence.fromList(SNodeOperations.getPrevSiblings(__thisNode__, true)).first(), CONCEPTS.TextualElement$9C);
    } else {
      return SNodeOperations.as(SNodeOperations.getNextSibling(closest), CONCEPTS.TextualElement$9C);
    }
  }
  /*package*/ static SNode findNextWordEnd_id3VJiP1sDz5g(@NotNull SNode __thisNode__) {
    if ((SNodeOperations.getNextSibling(__thisNode__) == null)) {
      return __thisNode__;
    }
    SNode closest = Sequence.fromIterable(SNodeOperations.ofConcept(SNodeOperations.getNextSiblings(__thisNode__, false), CONCEPTS.TextualElement$9C)).where((it) -> !(SNodeOperations.isInstanceOf(it, CONCEPTS.Letter$kd)) || Objects.equals(SPropertyOperations.getString(SNodeOperations.as(it, CONCEPTS.Letter$kd), PROPS.value$X7Tp), " ")).first();
    if ((closest == null)) {
      return SNodeOperations.as(ListSequence.fromList(SNodeOperations.getNextSiblings(__thisNode__, false)).last(), CONCEPTS.TextualElement$9C);
    } else {
      return SNodeOperations.as(SNodeOperations.getPrevSibling(closest), CONCEPTS.TextualElement$9C);
    }
  }

  /*package*/ TextualElement__BehaviorDescriptor() {
  }

  @Override
  protected void initNode(@NotNull SNode node, @NotNull SConstructor constructor, @Nullable Object[] parameters) {
    ___init___(node);
  }

  @Override
  protected <T> T invokeSpecial0(@NotNull SNode node, @NotNull SMethod<T> method, @Nullable Object[] parameters) {
    int methodIndex = BH_METHODS.indexOf(method);
    if (methodIndex < 0) {
      throw new BHMethodNotFoundException(this, method);
    }
    switch (methodIndex) {
      case 1:
        return (T) ((SNode) findPreviousWordStart_id3VJiP1sDlYQ(node));
      case 2:
        return (T) ((SNode) findNextWordEnd_id3VJiP1sDz5g(node));
      default:
        throw new BHMethodNotFoundException(this, method);
    }
  }

  @Override
  protected <T> T invokeSpecial0(@NotNull SAbstractConcept concept, @NotNull SMethod<T> method, @Nullable Object[] parameters) {
    int methodIndex = BH_METHODS.indexOf(method);
    if (methodIndex < 0) {
      throw new BHMethodNotFoundException(this, method);
    }
    switch (methodIndex) {
      default:
        throw new BHMethodNotFoundException(this, method);
    }
  }

  @NotNull
  @Override
  public List<SMethod<?>> getDeclaredMethods() {
    return BH_METHODS;
  }

  @NotNull
  @Override
  public SAbstractConcept getConcept() {
    return CONCEPT;
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept TextualElement$9C = MetaAdapterFactory.getConcept(0xc7fb639fbe784307L, 0x89b0b5959c3fa8c8L, 0x2c99af34e20d9cfbL, "jetbrains.mps.lang.text.structure.TextualElement");
    /*package*/ static final SConcept Letter$kd = MetaAdapterFactory.getConcept(0xc7fb639fbe784307L, 0x89b0b5959c3fa8c8L, 0x7ee31bf598f4ac1dL, "jetbrains.mps.lang.text.structure.Letter");
  }

  private static final class PROPS {
    /*package*/ static final SProperty value$X7Tp = MetaAdapterFactory.getProperty(0xc7fb639fbe784307L, 0x89b0b5959c3fa8c8L, 0x7ee31bf598f4ac1dL, 0x7ee31bf598f4ad9eL, "value");
  }
}
