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.core.aspects.behaviour.SMethodBuilder;
import jetbrains.mps.core.aspects.behaviour.SJavaCompoundTypeImpl;
import jetbrains.mps.core.aspects.behaviour.AccessPrivileges;
import jetbrains.mps.kotlin.api.members.SignatureCollector;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.kotlin.api.declaration.TypeParameterDeclaration;
import jetbrains.mps.kotlin.scopes.signed.SignatureScope;
import jetbrains.mps.kotlin.scopes.SignatureFilter;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.kotlin.scopes.signed.ScopeCollector;
import java.util.List;
import java.util.Arrays;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.internal.collections.runtime.Sequence;
import java.util.Collections;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.kotlin.signatures.FunctionSignature;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.kotlin.scopes.signed.TopLevelVisibility;
import jetbrains.mps.kotlin.api.members.SignatureBuilder;
import jetbrains.mps.kotlin.api.members.TypeExpander;
import jetbrains.mps.kotlin.api.members.SignatureAttributeKey;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.baseLanguage.closures.runtime.YieldingIterator;
import jetbrains.mps.core.aspects.behaviour.api.SConstructor;
import jetbrains.mps.core.aspects.behaviour.api.BHMethodNotFoundException;
import jetbrains.mps.smodel.builder.SNodeBuilder;
import org.jetbrains.mps.openapi.language.SInterfaceConcept;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import org.jetbrains.mps.openapi.language.SReferenceLink;

public final class IClassLike__BehaviorDescriptor extends BaseBHDescriptor {
  private static final SAbstractConcept CONCEPT = MetaAdapterFactory.getInterfaceConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x298a6a355c110274L, "jetbrains.mps.kotlin.structure.IClassLike");

  public static final SMethod<Void> populateNonMemberSignatures_id1pD7IS2T3rZ = new SMethodBuilder<Void>(new SJavaCompoundTypeImpl(Void.class)).name("populateNonMemberSignatures").modifiers(8, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(1614855948988593919L).languageId(0x8baff8e6c33ed689L, 0x6b3888c1980244d8L).build2(SMethodBuilder.createJavaParameter(SignatureCollector.class, ""));
  public static final SMethod<SNode> getThisType_id46gC9M6gB68 = new SMethodBuilder<SNode>(new SJavaCompoundTypeImpl((Class<SNode>) ((Class) Object.class))).name("getThisType").modifiers(8, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(4724452603239494024L).languageId(0x8baff8e6c33ed689L, 0x6b3888c1980244d8L).build2();
  public static final SMethod<Iterable<TypeParameterDeclaration>> getTypeParameters_idTmm2uCbI_X = new SMethodBuilder<Iterable<TypeParameterDeclaration>>(new SJavaCompoundTypeImpl((Class<Iterable<TypeParameterDeclaration>>) ((Class) Object.class))).name("getTypeParameters").modifiers(8, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(1033110091876723069L).languageId(0x8baff8e6c33ed689L, 0x6b3888c1980244d8L).build2();
  public static final SMethod<SignatureScope> getStaticScope_id3HHsmlLCHdO = new SMethodBuilder<SignatureScope>(new SJavaCompoundTypeImpl(SignatureScope.class)).name("getStaticScope").modifiers(8, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(4282203501211341684L).languageId(0x8baff8e6c33ed689L, 0x6b3888c1980244d8L).build2(SMethodBuilder.createJavaParameter(SignatureFilter.class, ""), SMethodBuilder.createJavaParameter((Class<SNode>) ((Class) Object.class), ""));
  public static final SMethod<SConcept> getConstructorDefaultVisibility_idu1nygduECM = new SMethodBuilder<SConcept>(new SJavaCompoundTypeImpl((Class<SConcept>) ((Class) Object.class))).name("getConstructorDefaultVisibility").modifiers(8, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(540816939199146546L).languageId(0x8baff8e6c33ed689L, 0x6b3888c1980244d8L).build2();
  public static final SMethod<SNode> getCompanion_id1dpU28wP77w = new SMethodBuilder<SNode>(new SJavaCompoundTypeImpl((Class<SNode>) ((Class) Object.class))).name("getCompanion").modifiers(8, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(1394400792925204960L).languageId(0x8baff8e6c33ed689L, 0x6b3888c1980244d8L).build2();
  public static final SMethod<Boolean> hasModifier_id2NtWm0y2Y2A = new SMethodBuilder<Boolean>(new SJavaCompoundTypeImpl(Boolean.TYPE)).name("hasModifier").modifiers(8, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(3233005502712242342L).languageId(0x8baff8e6c33ed689L, 0x6b3888c1980244d8L).build2(SMethodBuilder.createJavaParameter((Class<SAbstractConcept>) ((Class) Object.class), ""));
  public static final SMethod<Iterable<TypeReference>> getThisTypeReferences_idxpyqH1FuA0 = new SMethodBuilder<Iterable<TypeReference>>(new SJavaCompoundTypeImpl((Class<Iterable<TypeReference>>) ((Class) Object.class))).name("getThisTypeReferences").modifiers(8, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(601663393865001344L).languageId(0x8baff8e6c33ed689L, 0x6b3888c1980244d8L).build2();
  public static final SMethod<Boolean> collectScope_id7DyvjiA20yV = new SMethodBuilder<Boolean>(new SJavaCompoundTypeImpl(Boolean.TYPE)).name("collectScope").modifiers(8, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(8818748685422168251L).languageId(0x8baff8e6c33ed689L, 0x6b3888c1980244d8L).build2(SMethodBuilder.createJavaParameter(ScopeCollector.class, ""), SMethodBuilder.createJavaParameter((Class<SNode>) ((Class) Object.class), ""));
  public static final SMethod<Iterable<SNode>> getConstructors_id2NtWm0y9fFa = new SMethodBuilder<Iterable<SNode>>(new SJavaCompoundTypeImpl((Class<Iterable<SNode>>) ((Class) Object.class))).name("getConstructors").modifiers(8, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(3233005502713887434L).languageId(0x8baff8e6c33ed689L, 0x6b3888c1980244d8L).build2();
  public static final SMethod<Boolean> isAbstractClass_id$q1KckYQOy = new SMethodBuilder<Boolean>(new SJavaCompoundTypeImpl(Boolean.TYPE)).name("isAbstractClass").modifiers(12, AccessPrivileges.PUBLIC).concept(CONCEPT).baseMethodId(655844405554146594L).languageId(0x8baff8e6c33ed689L, 0x6b3888c1980244d8L).build2();

  private static final List<SMethod<?>> BH_METHODS = Arrays.<SMethod<?>>asList(populateNonMemberSignatures_id1pD7IS2T3rZ, getThisType_id46gC9M6gB68, getTypeParameters_idTmm2uCbI_X, getStaticScope_id3HHsmlLCHdO, getConstructorDefaultVisibility_idu1nygduECM, getCompanion_id1dpU28wP77w, hasModifier_id2NtWm0y2Y2A, getThisTypeReferences_idxpyqH1FuA0, collectScope_id7DyvjiA20yV, getConstructors_id2NtWm0y9fFa, isAbstractClass_id$q1KckYQOy);

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

  /*package*/ static void populateNonMemberSignatures_id1pD7IS2T3rZ(@NotNull SNode __thisNode__, SignatureCollector visitor) {
    // default: no-op
  }
  /*package*/ static SNode getThisType_id46gC9M6gB68(@NotNull SNode __thisNode__) {
    return createClassType_do2jmd_a0a1(__thisNode__);
  }
  /*package*/ static Iterable<TypeParameterDeclaration> getTypeParameters_idTmm2uCbI_X(@NotNull SNode __thisNode__) {
    return Sequence.fromIterable(Collections.<TypeParameterDeclaration>emptyList());
  }
  @Nullable
  /*package*/ static SignatureScope getStaticScope_id3HHsmlLCHdO(@NotNull SNode __thisNode__, SignatureFilter filter, final SNode contextNode) {
    if (filter.acceptKind(FunctionSignature.class)) {
      // Only non-inner classes (otherwise, belongs to instance functions)
      Iterable<SNode> constructors = Sequence.fromIterable(SNodeOperations.ofConcept(IDeclarationHolder__BehaviorDescriptor.getMembers_id213J8chg2xy.invoke(__thisNode__), CONCEPTS.IClassLike$go)).where((klass) -> !((boolean) IClassLike__BehaviorDescriptor.hasModifier_id2NtWm0y2Y2A.invoke(klass, CONCEPTS.InnerClassModifier$wL))).translate((klass) -> (Iterable<SNode>) IClassLike__BehaviorDescriptor.getConstructors_id2NtWm0y9fFa.invoke(klass)).where((cons) -> TopLevelVisibility.visibleTo(cons, contextNode));

      return SignatureBuilder.create(constructors, FunctionSignature.class).withSignature((SNode it) -> new FunctionSignature(KotlinFunctionDeclaration.of(it), (TypeExpander) null)).withAttribute(SignatureAttributeKey.VISIBILITY, (FunctionSignature _sig, SNode node) -> {
        // Class as constructors may have special visibility handling
        SConcept overrideVisibility = IClassLike__BehaviorDescriptor.getConstructorDefaultVisibility_idu1nygduECM.invoke(SNodeOperations.as(node, CONCEPTS.IClassLike$go));
        if (overrideVisibility != null) {
          return overrideVisibility;
        }

        // This will handle visibility of the class if needed
        return (SConcept) IVisible__BehaviorDescriptor.getVisibility_id2WVyZr44ojH.invoke(node);
      }).toScope(filter);
    }

    return null;
  }
  /*package*/ static SConcept getConstructorDefaultVisibility_idu1nygduECM(@NotNull SNode __thisNode__) {
    return null;
  }
  /*package*/ static SNode getCompanion_id1dpU28wP77w(@NotNull SNode __thisNode__) {
    return Sequence.fromIterable(SNodeOperations.ofConcept(SLinkOperations.getChildren(__thisNode__, LINKS.members$gqdV), CONCEPTS.CompanionObject$TE)).first();
  }
  /*package*/ static boolean hasModifier_id2NtWm0y2Y2A(@NotNull SNode __thisNode__, SAbstractConcept modifier) {
    return modifier == null;
  }
  /*package*/ static Iterable<TypeReference> getThisTypeReferences_idxpyqH1FuA0(@NotNull final SNode __thisNode__) {
    return Sequence.fromClosure(() -> {
      return (Iterable<TypeReference>) () -> {
        return new YieldingIterator<TypeReference>() {
          private int __CP__ = 0;
          protected boolean moveToNext() {
__loop__:
            do {
__switch__:
              switch (this.__CP__) {
                case -1:
                  assert false : "Internal error";
                  return false;
                case 5:
                  if ((_4_companion != null)) {
                    this.__CP__ = 6;
                    break;
                  }
                  this.__CP__ = 1;
                  break;
                case 2:
                  this.__CP__ = 3;
                  this.yield((TypeReference) new ThisTypeReference(__thisNode__));
                  return true;
                case 7:
                  this.__CP__ = 1;
                  this.yield(new ThisTypeReference(_4_companion));
                  return true;
                case 0:
                  this.__CP__ = 2;
                  break;
                case 3:

                  this._4_companion = IClassLike__BehaviorDescriptor.getCompanion_id1dpU28wP77w.invoke(__thisNode__);
                  this.__CP__ = 5;
                  break;
                case 6:
                  this.__CP__ = 7;
                  break;
                default:
                  break __loop__;
              }
            } while (true);
            return false;
          }
          private SNode _4_companion;
        };
      };
    });
  }
  /*package*/ static boolean collectScope_id7DyvjiA20yV(@NotNull SNode __thisNode__, ScopeCollector collector, SNode childNode) {
    // Not available for non inner class (see https://kotlinlang.org/docs/nested-classes.html#inner-classes)
    if (!(SNodeOperations.isInstanceOf(childNode, CONCEPTS.IClassLike$go)) || (boolean) IClassLike__BehaviorDescriptor.hasModifier_id2NtWm0y2Y2A.invoke(SNodeOperations.cast(childNode, CONCEPTS.IClassLike$go), CONCEPTS.InnerClassModifier$wL)) {
      // Need to call both branches
      ISignatureScopeProvider__BehaviorDescriptor.collectScope_id7DyvjiA20yV.invoke0(__thisNode__, CONCEPTS.IWithClassBody$QD, collector, childNode);
      ISignatureScopeProvider__BehaviorDescriptor.collectScope_id7DyvjiA20yV.invoke0(__thisNode__, CONCEPTS.IThisReceiverProvider$mP, collector, childNode);
    }
    return true;
  }
  /*package*/ static Iterable<SNode> getConstructors_id2NtWm0y9fFa(@NotNull SNode __thisNode__) {
    return Sequence.fromIterable(Collections.<SNode>emptyList());
  }

  /*package*/ IClassLike__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:
        populateNonMemberSignatures_id1pD7IS2T3rZ(node, (SignatureCollector) parameters[0]);
        return null;
      case 1:
        return (T) ((SNode) getThisType_id46gC9M6gB68(node));
      case 2:
        return (T) ((Iterable<TypeParameterDeclaration>) getTypeParameters_idTmm2uCbI_X(node));
      case 3:
        return (T) ((SignatureScope) getStaticScope_id3HHsmlLCHdO(node, (SignatureFilter) parameters[0], (SNode) parameters[1]));
      case 4:
        return (T) ((SConcept) getConstructorDefaultVisibility_idu1nygduECM(node));
      case 5:
        return (T) ((SNode) getCompanion_id1dpU28wP77w(node));
      case 6:
        return (T) ((Boolean) hasModifier_id2NtWm0y2Y2A(node, (SAbstractConcept) parameters[0]));
      case 7:
        return (T) ((Iterable<TypeReference>) getThisTypeReferences_idxpyqH1FuA0(node));
      case 8:
        return (T) ((Boolean) collectScope_id7DyvjiA20yV(node, (ScopeCollector) parameters[0], (SNode) parameters[1]));
      case 9:
        return (T) ((Iterable<SNode>) getConstructors_id2NtWm0y9fFa(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 SNode createClassType_do2jmd_a0a1(SNode p0) {
    SNodeBuilder n0 = new SNodeBuilder().init(CONCEPTS.ClassType$jI);
    n0.setReferenceTarget(LINKS.class$ExdX, p0);
    return n0.getResult();
  }

  private static final class CONCEPTS {
    /*package*/ static final SInterfaceConcept IClassLike$go = MetaAdapterFactory.getInterfaceConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x298a6a355c110274L, "jetbrains.mps.kotlin.structure.IClassLike");
    /*package*/ static final SConcept InnerClassModifier$wL = MetaAdapterFactory.getConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x28bef6d7551af40bL, "jetbrains.mps.kotlin.structure.InnerClassModifier");
    /*package*/ static final SConcept CompanionObject$TE = MetaAdapterFactory.getConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x28bef6d7551af57dL, "jetbrains.mps.kotlin.structure.CompanionObject");
    /*package*/ static final SInterfaceConcept IWithClassBody$QD = MetaAdapterFactory.getInterfaceConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x2043bc8310a1ff68L, "jetbrains.mps.kotlin.structure.IWithClassBody");
    /*package*/ static final SInterfaceConcept IThisReceiverProvider$mP = MetaAdapterFactory.getInterfaceConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x85989ab41addf50L, "jetbrains.mps.kotlin.structure.IThisReceiverProvider");
    /*package*/ static final SConcept ClassType$jI = MetaAdapterFactory.getConcept(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x28bef6d7551af4dfL, "jetbrains.mps.kotlin.structure.ClassType");
  }

  private static final class LINKS {
    /*package*/ static final SContainmentLink members$gqdV = MetaAdapterFactory.getContainmentLink(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x2043bc8310a1ff68L, 0x2043bc8310a1ff69L, "members");
    /*package*/ static final SReferenceLink class$ExdX = MetaAdapterFactory.getReferenceLink(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x5c7be90f2440b378L, 0x5c7be90f2440b37bL, "class");
  }
}
