package jetbrains.mps.baseLanguage.editor;

/*Generated by MPS */

import jetbrains.mps.nodeEditor.menus.substitute.SubstituteMenuBase;
import jetbrains.mps.lang.editor.menus.EditorMenuDescriptorBase;
import jetbrains.mps.smodel.SNodePointer;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import jetbrains.mps.lang.editor.menus.MenuPart;
import jetbrains.mps.openapi.editor.menus.substitute.SubstituteMenuItem;
import jetbrains.mps.openapi.editor.menus.substitute.SubstituteMenuContext;
import java.util.ArrayList;
import jetbrains.mps.lang.editor.menus.GroupMenuPart;
import jetbrains.mps.util.Computable;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import java.util.Objects;
import java.util.Arrays;
import jetbrains.mps.lang.editor.menus.substitute.ConstraintsFilteringSubstituteMenuPartDecorator;
import jetbrains.mps.lang.editor.menus.ParameterizedMenuPart;
import org.jetbrains.mps.openapi.model.SNode;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.internal.collections.runtime.Sequence;
import jetbrains.mps.baseLanguage.scopes.ClassifierScopes;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import jetbrains.mps.baseLanguage.behavior.ClassConcept__BehaviorDescriptor;
import jetbrains.mps.lang.editor.menus.substitute.SingleItemSubstituteMenuPart;
import jetbrains.mps.lang.editor.menus.substitute.DefaultSubstituteMenuItem;
import jetbrains.mps.smodel.action.SNodeFactoryOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.editor.runtime.completion.CompletionItemInformation;
import jetbrains.mps.smodel.runtime.IconResource;
import jetbrains.mps.baseLanguage.behavior.Classifier__BehaviorDescriptor;
import jetbrains.mps.lang.editor.menus.ConceptMenusPart;
import java.util.Collection;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import jetbrains.mps.lang.editor.menus.substitute.DefaultSubstituteMenuLookup;
import jetbrains.mps.smodel.language.LanguageRegistry;
import jetbrains.mps.lang.editor.menus.substitute.IncludeSubstituteMenuSubstituteMenuPart;
import jetbrains.mps.openapi.editor.menus.substitute.SubstituteMenuLookup;
import jetbrains.mps.openapi.editor.EditorContext;
import jetbrains.mps.lang.editor.menus.substitute.NamedSubstituteMenuLookup;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import org.jetbrains.mps.openapi.language.SReferenceLink;
import org.jetbrains.mps.openapi.language.SProperty;

public class ClassifierType_SubstituteMenu extends SubstituteMenuBase {
  public ClassifierType_SubstituteMenu() {
    super(false, new EditorMenuDescriptorBase("default substitute menu for " + "ClassifierType", new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "1741258697586954859")));
  }
  @NotNull
  @Override
  protected List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> getParts(final SubstituteMenuContext _context) {
    List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> result = new ArrayList<MenuPart<SubstituteMenuItem, SubstituteMenuContext>>();
    result.add(new SMP_Group_6wdawe_a());
    return result;
  }

  public class SMP_Group_6wdawe_a extends GroupMenuPart<SubstituteMenuItem, SubstituteMenuContext> {
    private boolean superclass;
    private boolean implement;
    private boolean superinterface;
    public SMP_Group_6wdawe_a() {
      super(new EditorMenuDescriptorBase("substitute menu group", new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "1741258697586954860")));
    }
    @Override
    protected void initialize(SubstituteMenuContext _context) {
      super.initialize(_context);
      superclass = new Computable<Boolean>() {
        public Boolean compute() {
          return SNodeOperations.isInstanceOf(_context.getParentNode(), CONCEPTS.ClassConcept$bK) && Objects.equals(_context.getLink(), LINKS.superclass$Mp9$);
        }
      }.compute();
      implement = new Computable<Boolean>() {
        public Boolean compute() {
          return SNodeOperations.isInstanceOf(_context.getParentNode(), CONCEPTS.ClassConcept$bK) && Objects.equals(_context.getLink(), LINKS.implementedInterface$rujG);
        }
      }.compute();
      superinterface = new Computable<Boolean>() {
        public Boolean compute() {
          return SNodeOperations.isInstanceOf(_context.getParentNode(), CONCEPTS.Interface$db) && Objects.equals(_context.getLink(), LINKS.extendedInterface$PDVO);
        }
      }.compute();
    }
    @Override
    protected List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> getParts() {
      return Arrays.<MenuPart<SubstituteMenuItem, SubstituteMenuContext>>asList(new SMP_Group_6wdawe_a0(), new SMP_Group_6wdawe_b0(), new SMP_Group_6wdawe_c0(), new SMP_Group_6wdawe_d0());
    }
    public class SMP_Group_6wdawe_a0 extends GroupMenuPart<SubstituteMenuItem, SubstituteMenuContext> {
      public SMP_Group_6wdawe_a0() {
        super(new EditorMenuDescriptorBase("substitute menu group", new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "1741258697586955006")));
      }
      @Override
      protected boolean isApplicable(SubstituteMenuContext _context) {
        return superclass;
      }
      @Override
      protected List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> getParts() {
        return Arrays.<MenuPart<SubstituteMenuItem, SubstituteMenuContext>>asList(new ConstraintsFilteringSubstituteMenuPartDecorator(new SMP_Param_6wdawe_a0a(), CONCEPTS.ClassifierType$bL));
      }
      private class SMP_Param_6wdawe_a0a extends ParameterizedMenuPart<SNode, SubstituteMenuItem, SubstituteMenuContext> {
        /*package*/ SMP_Param_6wdawe_a0a() {
          super(new EditorMenuDescriptorBase("parameterized substitute menu part", new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "1741258697586955011")));
        }
        @NotNull
        @Override
        protected List<SubstituteMenuItem> createItems(SNode parameter, SubstituteMenuContext context) {
          return new SMP_Action_6wdawe_a0a0(parameter).createItems(context);
        }
        @Nullable
        @Override
        protected Iterable<? extends SNode> getParameters(final SubstituteMenuContext _context) {
          return (List<SNode>) Sequence.fromIterable(ClassifierScopes.getVisibleClassesScope(_context.getParentNode()).getAvailableElements(null)).where((it) -> !(SPropertyOperations.getBoolean(SNodeOperations.cast(it, CONCEPTS.ClassConcept$bK), PROPS.isFinal$f7C_)) && !(Objects.equals(it, _context.getParentNode())) && (boolean) ClassConcept__BehaviorDescriptor.canBeExtendedOrInstantiatedAt_id2YFkRQdLLqk.invoke(SNodeOperations.as(it, CONCEPTS.ClassConcept$bK), _context.getParentNode())).toList();
        }
        private class SMP_Action_6wdawe_a0a0 extends SingleItemSubstituteMenuPart {
          private final SNode myParameterObject;
          public SMP_Action_6wdawe_a0a0(SNode parameterObject) {
            myParameterObject = parameterObject;
          }

          @Nullable
          @Override
          protected SubstituteMenuItem createItem(SubstituteMenuContext _context) {
            Item item = new Item(_context);
            item.resetTraceInfo();
            return item;
          }
          private class Item extends DefaultSubstituteMenuItem {
            private final SubstituteMenuContext _context;
            public Item(SubstituteMenuContext context) {
              super(CONCEPTS.ClassifierType$bL, context);
              _context = context;
            }

            /*package*/ void resetTraceInfo() {
              String description = "Substitute item: " + getMatchingText("");
              description += ". Parameter object: " + myParameterObject;
              updateTraceInfo(description, new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "1741258697586955064"));
            }

            @Nullable
            @Override
            public SNode createNode(@NotNull String pattern) {
              SNode result = SNodeFactoryOperations.createNewNode(CONCEPTS.ClassifierType$bL, null);
              SLinkOperations.setTarget(result, LINKS.classifier$cxMr, myParameterObject);
              return result;
            }

            @NotNull
            protected CompletionItemInformation createInformation(String pattern) {
              return new CompletionItemInformation(myParameterObject, CONCEPTS.ClassifierType$bL, getMatchingText(pattern), getDescriptionText(pattern));
            }
            @Nullable
            @Override
            public String getDescriptionText(@NotNull String pattern) {
              return defaultDescriptionTextForParameter(myParameterObject, pattern);
            }
            @Nullable
            @Override
            public IconResource getIcon(@NotNull String pattern) {
              return defaultIconForParameter(myParameterObject, pattern);
            }
            @Nullable
            @Override
            public String getMatchingText(@NotNull String pattern) {
              return (String) Classifier__BehaviorDescriptor.getNestedNameInContext_id7q4lzBFjvF8.invoke(myParameterObject, _context.getCurrentTargetNode());
            }
          }
        }

      }
    }
    public class SMP_Group_6wdawe_b0 extends GroupMenuPart<SubstituteMenuItem, SubstituteMenuContext> {
      public SMP_Group_6wdawe_b0() {
        super(new EditorMenuDescriptorBase("substitute menu group", new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "1741258697586955148")));
      }
      @Override
      protected boolean isApplicable(SubstituteMenuContext _context) {
        return implement;
      }
      @Override
      protected List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> getParts() {
        return Arrays.<MenuPart<SubstituteMenuItem, SubstituteMenuContext>>asList(new ConstraintsFilteringSubstituteMenuPartDecorator(new SMP_Param_6wdawe_a1a(), CONCEPTS.ClassifierType$bL));
      }
      private class SMP_Param_6wdawe_a1a extends ParameterizedMenuPart<SNode, SubstituteMenuItem, SubstituteMenuContext> {
        /*package*/ SMP_Param_6wdawe_a1a() {
          super(new EditorMenuDescriptorBase("parameterized substitute menu part", new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "1741258697586955153")));
        }
        @NotNull
        @Override
        protected List<SubstituteMenuItem> createItems(SNode parameter, SubstituteMenuContext context) {
          return new SMP_Action_6wdawe_a0b0(parameter).createItems(context);
        }
        @Nullable
        @Override
        protected Iterable<? extends SNode> getParameters(SubstituteMenuContext _context) {
          return (List<SNode>) Sequence.fromIterable(ClassifierScopes.getVisibleInterfacesScope(_context.getParentNode()).getAvailableElements(null)).toList();
        }
        private class SMP_Action_6wdawe_a0b0 extends SingleItemSubstituteMenuPart {
          private final SNode myParameterObject;
          public SMP_Action_6wdawe_a0b0(SNode parameterObject) {
            myParameterObject = parameterObject;
          }

          @Nullable
          @Override
          protected SubstituteMenuItem createItem(SubstituteMenuContext _context) {
            Item item = new Item(_context);
            item.resetTraceInfo();
            return item;
          }
          private class Item extends DefaultSubstituteMenuItem {
            private final SubstituteMenuContext _context;
            public Item(SubstituteMenuContext context) {
              super(CONCEPTS.ClassifierType$bL, context);
              _context = context;
            }

            /*package*/ void resetTraceInfo() {
              String description = "Substitute item: " + getMatchingText("");
              description += ". Parameter object: " + myParameterObject;
              updateTraceInfo(description, new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "1741258697586955194"));
            }

            @Nullable
            @Override
            public SNode createNode(@NotNull String pattern) {
              SNode result = SNodeFactoryOperations.createNewNode(CONCEPTS.ClassifierType$bL, null);
              SLinkOperations.setTarget(result, LINKS.classifier$cxMr, myParameterObject);
              return result;
            }

            @NotNull
            protected CompletionItemInformation createInformation(String pattern) {
              return new CompletionItemInformation(myParameterObject, CONCEPTS.ClassifierType$bL, getMatchingText(pattern), getDescriptionText(pattern));
            }
            @Nullable
            @Override
            public String getDescriptionText(@NotNull String pattern) {
              return defaultDescriptionTextForParameter(myParameterObject, pattern);
            }
            @Nullable
            @Override
            public IconResource getIcon(@NotNull String pattern) {
              return defaultIconForParameter(myParameterObject, pattern);
            }
            @Nullable
            @Override
            public String getMatchingText(@NotNull String pattern) {
              return (String) Classifier__BehaviorDescriptor.getNestedNameInContext_id7q4lzBFjvF8.invoke(myParameterObject, _context.getCurrentTargetNode());
            }
          }
        }

      }
    }
    public class SMP_Group_6wdawe_c0 extends GroupMenuPart<SubstituteMenuItem, SubstituteMenuContext> {
      public SMP_Group_6wdawe_c0() {
        super(new EditorMenuDescriptorBase("substitute menu group", new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "1741258697586955278")));
      }
      @Override
      protected boolean isApplicable(SubstituteMenuContext _context) {
        return superinterface;
      }
      @Override
      protected List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> getParts() {
        return Arrays.<MenuPart<SubstituteMenuItem, SubstituteMenuContext>>asList(new ConstraintsFilteringSubstituteMenuPartDecorator(new SMP_Param_6wdawe_a2a(), CONCEPTS.ClassifierType$bL));
      }
      private class SMP_Param_6wdawe_a2a extends ParameterizedMenuPart<SNode, SubstituteMenuItem, SubstituteMenuContext> {
        /*package*/ SMP_Param_6wdawe_a2a() {
          super(new EditorMenuDescriptorBase("parameterized substitute menu part", new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "1741258697586955283")));
        }
        @NotNull
        @Override
        protected List<SubstituteMenuItem> createItems(SNode parameter, SubstituteMenuContext context) {
          return new SMP_Action_6wdawe_a0c0(parameter).createItems(context);
        }
        @Nullable
        @Override
        protected Iterable<? extends SNode> getParameters(final SubstituteMenuContext _context) {
          return (List<SNode>) Sequence.fromIterable(ClassifierScopes.getVisibleInterfacesScope(_context.getParentNode()).getAvailableElements(null)).where((it) -> !(Objects.equals(it, _context.getParentNode()))).toList();
        }
        private class SMP_Action_6wdawe_a0c0 extends SingleItemSubstituteMenuPart {
          private final SNode myParameterObject;
          public SMP_Action_6wdawe_a0c0(SNode parameterObject) {
            myParameterObject = parameterObject;
          }

          @Nullable
          @Override
          protected SubstituteMenuItem createItem(SubstituteMenuContext _context) {
            Item item = new Item(_context);
            item.resetTraceInfo();
            return item;
          }
          private class Item extends DefaultSubstituteMenuItem {
            private final SubstituteMenuContext _context;
            public Item(SubstituteMenuContext context) {
              super(CONCEPTS.ClassifierType$bL, context);
              _context = context;
            }

            /*package*/ void resetTraceInfo() {
              String description = "Substitute item: " + getMatchingText("");
              description += ". Parameter object: " + myParameterObject;
              updateTraceInfo(description, new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "1741258697586955324"));
            }

            @Nullable
            @Override
            public SNode createNode(@NotNull String pattern) {
              SNode result = SNodeFactoryOperations.createNewNode(CONCEPTS.ClassifierType$bL, null);
              SLinkOperations.setTarget(result, LINKS.classifier$cxMr, myParameterObject);
              return result;
            }

            @NotNull
            protected CompletionItemInformation createInformation(String pattern) {
              return new CompletionItemInformation(myParameterObject, CONCEPTS.ClassifierType$bL, getMatchingText(pattern), getDescriptionText(pattern));
            }
            @Nullable
            @Override
            public String getDescriptionText(@NotNull String pattern) {
              return defaultDescriptionTextForParameter(myParameterObject, pattern);
            }
            @Nullable
            @Override
            public IconResource getIcon(@NotNull String pattern) {
              return defaultIconForParameter(myParameterObject, pattern);
            }
            @Nullable
            @Override
            public String getMatchingText(@NotNull String pattern) {
              return (String) Classifier__BehaviorDescriptor.getNestedNameInContext_id7q4lzBFjvF8.invoke(myParameterObject, _context.getCurrentTargetNode());
            }
          }
        }

      }
    }
    public class SMP_Group_6wdawe_d0 extends GroupMenuPart<SubstituteMenuItem, SubstituteMenuContext> {
      public SMP_Group_6wdawe_d0() {
        super(new EditorMenuDescriptorBase("substitute menu group", new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "1741258697586964729")));
      }
      @Override
      protected boolean isApplicable(SubstituteMenuContext _context) {
        return !(superclass || implement || superinterface) && (_context.getLink() != null || !(SNodeOperations.isInstanceOf(_context.getParentNode(), CONCEPTS.StatementList$m_)));
      }
      @Override
      protected List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> getParts() {
        return Arrays.<MenuPart<SubstituteMenuItem, SubstituteMenuContext>>asList(new SMP_Subconcepts_6wdawe_a3a(), new SMP_Include_6wdawe_b3a());
      }
      public class SMP_Subconcepts_6wdawe_a3a extends ConceptMenusPart<SubstituteMenuItem, SubstituteMenuContext> {
        public SMP_Subconcepts_6wdawe_a3a() {
          super(new EditorMenuDescriptorBase("include menus for all the direct subconcepts of " + "ClassifierType", new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "1741258697586964733")));
        }

        @Override
        protected Collection<SAbstractConcept> getConcepts(final SubstituteMenuContext _context) {
          return getDirectDescendants(_context, CONCEPTS.ClassifierType$bL);
        }

        @Override
        protected Collection<SubstituteMenuItem> createItemsForConcept(SubstituteMenuContext context, SAbstractConcept concept) {
          return context.createItems(new DefaultSubstituteMenuLookup(LanguageRegistry.getInstance(context.getEditorContext().getRepository()), concept));
        }
      }
      public class SMP_Include_6wdawe_b3a extends IncludeSubstituteMenuSubstituteMenuPart {

        public SMP_Include_6wdawe_b3a() {
          super(new EditorMenuDescriptorBase("include " + "named substitute menu " + "ClassifierType_SmartReference", new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "4747359941571312305")));
        }

        @Nullable
        @Override
        protected SubstituteMenuLookup getMenuLookup(SubstituteMenuContext _context) {
          final EditorContext editorContext = _context.getEditorContext();
          SAbstractConcept conceptToFindMenuFor = getConceptToFindMenuFor(_context);
          return new NamedSubstituteMenuLookup(LanguageRegistry.getInstance(editorContext.getRepository()), conceptToFindMenuFor, "jetbrains.mps.baseLanguage.editor.ClassifierType_SmartReference");
        }
        private SAbstractConcept getConceptToFindMenuFor(SubstituteMenuContext _context) {
          return CONCEPTS.ClassifierType$bL;
        }
      }
    }
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept ClassConcept$bK = MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca66L, "jetbrains.mps.baseLanguage.structure.ClassConcept");
    /*package*/ static final SConcept Interface$db = MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101edd46144L, "jetbrains.mps.baseLanguage.structure.Interface");
    /*package*/ static final SConcept ClassifierType$bL = MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, "jetbrains.mps.baseLanguage.structure.ClassifierType");
    /*package*/ static final SConcept StatementList$m_ = MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b200L, "jetbrains.mps.baseLanguage.structure.StatementList");
  }

  private static final class LINKS {
    /*package*/ static final SContainmentLink superclass$Mp9$ = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca66L, 0x10f6353296dL, "superclass");
    /*package*/ static final SContainmentLink implementedInterface$rujG = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca66L, 0xff2ac0b419L, "implementedInterface");
    /*package*/ static final SContainmentLink extendedInterface$PDVO = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101edd46144L, 0x101eddadad7L, "extendedInterface");
    /*package*/ static final SReferenceLink classifier$cxMr = MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, 0x101de490babL, "classifier");
  }

  private static final class PROPS {
    /*package*/ static final SProperty isFinal$f7C_ = MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c108ca66L, 0x11c6af4b284L, "isFinal");
  }
}
