package jetbrains.mps.kotlin.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.kotlin.api.declaration.ParameterDeclaration;
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 jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import java.util.Collections;
import jetbrains.mps.internal.collections.runtime.NotNullWhereFilter;
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.SInterfaceConcept;
import org.jetbrains.mps.openapi.language.SReferenceLink;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import org.jetbrains.mps.openapi.language.SProperty;

public final class ValueArgument__BehaviorDescriptor extends BaseBHDescriptor {
  private static final SAbstractConcept CONCEPT = MetaAdapterFactory.getConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x28bef6d7551af579L, "jetbrains.mps.kotlin.structure.ValueArgument");

  public static final SMethod<ParameterDeclaration> getNamedTarget_id2PMtXoK3vgE = new SMethodBuilder<ParameterDeclaration>(new SJavaCompoundTypeImpl(ParameterDeclaration.class)).name("getNamedTarget").modifiers(8, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(3274811640864699434L).languageId(0x8baff8e6c33ed689L, 0x6b3888c1980244d8L).build2();
  public static final SMethod<SNode> getArgExpression_id26mUjU3EUyw = new SMethodBuilder<SNode>(new SJavaCompoundTypeImpl((Class<SNode>) ((Class) Object.class))).name("getArgExpression").modifiers(8, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(2420378304464529568L).languageId(0x8baff8e6c33ed689L, 0x6b3888c1980244d8L).build2();
  public static final SMethod<Boolean> isVarArg_idbbFPPtRGEL = new SMethodBuilder<Boolean>(new SJavaCompoundTypeImpl(Boolean.TYPE)).name("isVarArg").modifiers(8, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(201447423889820337L).languageId(0x8baff8e6c33ed689L, 0x6b3888c1980244d8L).build2();
  public static final SMethod<Iterable<SNode>> getAvailableParameters_id7bIC29gIZM1 = new SMethodBuilder<Iterable<SNode>>(new SJavaCompoundTypeImpl((Class<Iterable<SNode>>) ((Class) Object.class))).name("getAvailableParameters").modifiers(1, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(8281732834024750209L).languageId(0x8baff8e6c33ed689L, 0x6b3888c1980244d8L).build2(SMethodBuilder.createJavaParameter((Class<SNode>) ((Class) Object.class), ""));

  private static final List<SMethod<?>> BH_METHODS = Arrays.<SMethod<?>>asList(getNamedTarget_id2PMtXoK3vgE, getArgExpression_id26mUjU3EUyw, isVarArg_idbbFPPtRGEL, getAvailableParameters_id7bIC29gIZM1);

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

  /*package*/ static ParameterDeclaration getNamedTarget_id2PMtXoK3vgE(@NotNull final SNode __thisNode__) {
    // Get the parameter back from function definition (because parameter may not be a kotlin parameter)
    return Sequence.fromIterable(IArguments__BehaviorDescriptor.getAvailableParameters_id1$jFvlD0xqw.invoke(SNodeOperations.as(SNodeOperations.getParent(__thisNode__), CONCEPTS.IArguments$xj))).findFirst((it) -> it != null && it.getNode() == SLinkOperations.getTarget(__thisNode__, LINKS.parameter$8rO1));
  }
  /*package*/ static SNode getArgExpression_id26mUjU3EUyw(@NotNull SNode __thisNode__) {
    return SLinkOperations.getTarget(__thisNode__, LINKS.expression$RzsN);
  }
  /*package*/ static boolean isVarArg_idbbFPPtRGEL(@NotNull SNode __thisNode__) {
    return SPropertyOperations.getBoolean(__thisNode__, PROPS.isVararg$zs5Z);
  }
  /*package*/ static Iterable<SNode> getAvailableParameters_id7bIC29gIZM1(@NotNull SAbstractConcept __thisConcept__, SNode thisOrContextNode) {
    SNode provider = (SNodeOperations.isInstanceOf(thisOrContextNode, CONCEPTS.IArguments$xj) ? SNodeOperations.cast(thisOrContextNode, CONCEPTS.IArguments$xj) : SNodeOperations.as(SNodeOperations.getParent(thisOrContextNode), CONCEPTS.IArguments$xj));
    if ((provider == null)) {
      return Sequence.fromIterable(Collections.<SNode>emptyList());
    }
    return Sequence.fromIterable(IArguments__BehaviorDescriptor.getAvailableParameters_id1$jFvlD0xqw.invoke(provider)).select((this0) -> this0.getNode()).where(new NotNullWhereFilter());
  }

  /*package*/ ValueArgument__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) ((ParameterDeclaration) getNamedTarget_id2PMtXoK3vgE(node));
      case 1:
        return (T) ((SNode) getArgExpression_id26mUjU3EUyw(node));
      case 2:
        return (T) ((Boolean) isVarArg_idbbFPPtRGEL(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) {
      case 3:
        return (T) ((Iterable<SNode>) getAvailableParameters_id7bIC29gIZM1(concept, (SNode) parameters[0]));
      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 SInterfaceConcept IArguments$xj = MetaAdapterFactory.getInterfaceConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x5b1dd60162ecf00bL, "jetbrains.mps.kotlin.structure.IArguments");
  }

  private static final class LINKS {
    /*package*/ static final SReferenceLink parameter$8rO1 = MetaAdapterFactory.getReferenceLink(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x28bef6d7551af579L, 0x11400bb790b4f87bL, "parameter");
    /*package*/ static final SContainmentLink expression$RzsN = MetaAdapterFactory.getContainmentLink(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x28bef6d7551af579L, 0x28bef6d7551af924L, "expression");
  }

  private static final class PROPS {
    /*package*/ static final SProperty isVararg$zs5Z = MetaAdapterFactory.getProperty(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x28bef6d7551af579L, 0x11400bb790b4ef7eL, "isVararg");
  }
}
