package jetbrains.mps.baseLanguage.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 java.util.List;
import java.util.Arrays;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import java.util.Iterator;
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.SInterfaceConcept;

public final class ILocalDeclaration__BehaviorDescriptor extends BaseBHDescriptor {
  private static final SAbstractConcept CONCEPT = MetaAdapterFactory.getInterfaceConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x2d45f01afccba89cL, "jetbrains.mps.baseLanguage.structure.ILocalDeclaration");

  public static final SMethod<Boolean> isReferencedInClosure_id2P5W1FWMWTY = new SMethodBuilder<Boolean>(new SJavaCompoundTypeImpl(Boolean.TYPE)).name("isReferencedInClosure").modifiers(8, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(3262277503800823422L).languageId(0xa443f952ceaf5816L, 0xf3061a5392264cc5L).build2();
  public static final SMethod<Boolean> isReferencedInControlFlowInterrupter_id1rgSh_h_K4n = new SMethodBuilder<Boolean>(new SJavaCompoundTypeImpl(Boolean.TYPE)).name("isReferencedInControlFlowInterrupter").modifiers(8, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(1644061362849513751L).languageId(0xa443f952ceaf5816L, 0xf3061a5392264cc5L).build2();

  private static final List<SMethod<?>> BH_METHODS = Arrays.<SMethod<?>>asList(isReferencedInClosure_id2P5W1FWMWTY, isReferencedInControlFlowInterrupter_id1rgSh_h_K4n);

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

  /*package*/ static boolean isReferencedInClosure_id2P5W1FWMWTY(@NotNull SNode __thisNode__) {
    SNode container = SNodeOperations.getNodeAncestor(__thisNode__, CONCEPTS.StatementList$m_, false, false);
    {
      Iterator<SNode> ref_it = ListSequence.fromList(SNodeOperations.getNodeDescendants(container, CONCEPTS.ILocalReference$Us, false, new SAbstractConcept[]{})).iterator();
      SNode ref_var;
      while (ref_it.hasNext()) {
        ref_var = ref_it.next();
        if (ILocalReference__BehaviorDescriptor.getDeclaration_id2P5W1FWMYZ5.invoke(ref_var) == __thisNode__) {
          SNode referenceContainer = SNodeOperations.getNodeAncestor(ref_var, CONCEPTS.StatementList$m_, false, false);
          while (referenceContainer != null) {
            if (referenceContainer == container) {
              return false;
            }
            if ((boolean) IStatementListContainer__BehaviorDescriptor.isClosure_id2P5W1FWMZPJ.invoke(SNodeOperations.getNodeAncestor(referenceContainer, CONCEPTS.IStatementListContainer$xz, false, false))) {
              return true;
            }
            referenceContainer = SNodeOperations.getNodeAncestor(referenceContainer, CONCEPTS.StatementList$m_, false, false);
          }
        }
      }
    }
    return false;
  }
  /*package*/ static boolean isReferencedInControlFlowInterrupter_id1rgSh_h_K4n(@NotNull SNode __thisNode__) {
    SNode container = SNodeOperations.getNodeAncestor(__thisNode__, CONCEPTS.StatementList$m_, false, false);
    {
      Iterator<SNode> ref_it = ListSequence.fromList(SNodeOperations.getNodeDescendants(container, CONCEPTS.ILocalReference$Us, false, new SAbstractConcept[]{})).iterator();
      SNode ref_var;
      while (ref_it.hasNext()) {
        ref_var = ref_it.next();
        if (ILocalReference__BehaviorDescriptor.getDeclaration_id2P5W1FWMYZ5.invoke(ref_var) == __thisNode__) {
          SNode interrupter = SNodeOperations.getNodeAncestor(ref_var, CONCEPTS.IControlFlowInterrupter$Ra, false, false);
          if (interrupter == container || ListSequence.fromList(SNodeOperations.getNodeAncestors(interrupter, null, false)).contains(container)) {
            return true;
          }
        }
      }
    }
    return false;
  }

  /*package*/ ILocalDeclaration__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 0:
        return (T) ((Boolean) isReferencedInClosure_id2P5W1FWMWTY(node));
      case 1:
        return (T) ((Boolean) isReferencedInControlFlowInterrupter_id1rgSh_h_K4n(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 StatementList$m_ = MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b200L, "jetbrains.mps.baseLanguage.structure.StatementList");
    /*package*/ static final SInterfaceConcept ILocalReference$Us = MetaAdapterFactory.getInterfaceConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x2d45f01afccba89dL, "jetbrains.mps.baseLanguage.structure.ILocalReference");
    /*package*/ static final SInterfaceConcept IStatementListContainer$xz = MetaAdapterFactory.getInterfaceConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x11750ef8265L, "jetbrains.mps.baseLanguage.structure.IStatementListContainer");
    /*package*/ static final SInterfaceConcept IControlFlowInterrupter$Ra = MetaAdapterFactory.getInterfaceConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x7c8556154508e980L, "jetbrains.mps.baseLanguage.structure.IControlFlowInterrupter");
  }
}
