package jetbrains.mps.lang.editor.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.substitute.ConstraintsFilteringSubstituteMenuPartDecorator;
import jetbrains.mps.lang.editor.menus.ParameterizedMenuPart;
import org.jetbrains.mps.openapi.language.SConcept;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.typechecking.TypecheckingFacade;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SConceptOperations;
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.editor.runtime.completion.CompletionItemInformation;
import jetbrains.mps.smodel.runtime.IconResource;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SContainmentLink;

public class SubstituteAbstractStyledTextOperation_Contribution extends SubstituteMenuBase {
  public SubstituteAbstractStyledTextOperation_Contribution() {
    super(true, new EditorMenuDescriptorBase("contribution to the " + "default substitute menu for " + "IOperation", new SNodePointer("r:00000000-0000-4000-0000-011c89590299(jetbrains.mps.lang.editor.editor)", "1741258697587153197")));
  }
  @NotNull
  @Override
  protected List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> getParts(final SubstituteMenuContext _context) {
    List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> result = new ArrayList<MenuPart<SubstituteMenuItem, SubstituteMenuContext>>();
    result.add(new ConstraintsFilteringSubstituteMenuPartDecorator(new SMP_Param_86ir5e_a(), CONCEPTS.AbstractStyledTextOperation$j9));
    return result;
  }

  private class SMP_Param_86ir5e_a extends ParameterizedMenuPart<SConcept, SubstituteMenuItem, SubstituteMenuContext> {
    /*package*/ SMP_Param_86ir5e_a() {
      super(new EditorMenuDescriptorBase("parameterized substitute menu part", new SNodePointer("r:00000000-0000-4000-0000-011c89590299(jetbrains.mps.lang.editor.editor)", "1741258697587153200")));
    }
    @NotNull
    @Override
    protected List<SubstituteMenuItem> createItems(SConcept parameter, SubstituteMenuContext context) {
      return new SMP_Action_86ir5e_a0(parameter).createItems(context);
    }
    @Nullable
    @Override
    protected Iterable<? extends SConcept> getParameters(SubstituteMenuContext _context) {
      List<SConcept> emptyList = ListSequence.fromList(new ArrayList<SConcept>());
      if (!(SNodeOperations.isInstanceOf(_context.getParentNode(), CONCEPTS.DotExpression$yW))) {
        return emptyList;
      }
      SNode operand = SLinkOperations.getTarget(SNodeOperations.cast(_context.getParentNode(), CONCEPTS.DotExpression$yW), LINKS.operand$w6IR);
      if (operand == null) {
        return emptyList;
      }
      final SNode type = TypecheckingFacade.getFromContext().getTypeOf(operand);
      List<SConcept> list = SConceptOperations.getAllSubConcepts2(CONCEPTS.AbstractStyledTextOperation$j9, _context.getModel());
      ListSequence.fromList(list).removeElement(CONCEPTS.AbstractStyledTextOperation$j9);
      return ListSequence.fromList(list).where((it) -> SNodeOperations.isInstanceOf(type, CONCEPTS.StyledTextType$L7)).toList();
    }
    private class SMP_Action_86ir5e_a0 extends SingleItemSubstituteMenuPart {
      private final SConcept myParameterObject;
      public SMP_Action_86ir5e_a0(SConcept 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.AbstractStyledTextOperation$j9, context);
          _context = context;
        }

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

        @Nullable
        @Override
        public SNode createNode(@NotNull String pattern) {
          SNode abstractOperation = SNodeFactoryOperations.createNewNode(myParameterObject, null);
          return abstractOperation;
        }

        @NotNull
        protected CompletionItemInformation createInformation(String pattern) {
          return new CompletionItemInformation(myParameterObject, CONCEPTS.AbstractStyledTextOperation$j9, getMatchingText(pattern), getDescriptionText(pattern));
        }
        @Nullable
        @Override
        public String getMatchingText(@NotNull String pattern) {
          return defaultMatchingTextForParameter(myParameterObject, 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);
        }
      }
    }

  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept AbstractStyledTextOperation$j9 = MetaAdapterFactory.getConcept(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x3ee423fc2ad10eceL, "jetbrains.mps.lang.editor.structure.AbstractStyledTextOperation");
    /*package*/ static final SConcept DotExpression$yW = MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x116b46a08c4L, "jetbrains.mps.baseLanguage.structure.DotExpression");
    /*package*/ static final SConcept StyledTextType$L7 = MetaAdapterFactory.getConcept(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x362b8be848e5c49bL, "jetbrains.mps.lang.editor.structure.StyledTextType");
  }

  private static final class LINKS {
    /*package*/ static final SContainmentLink operand$w6IR = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x116b46a08c4L, 0x116b46a4416L, "operand");
  }
}
