package jetbrains.mps.lang.typesystem.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.lang.smodel.generator.smodelAdapter.SNodeOperations;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.baseLanguage.behavior.BaseMethodDeclaration__BehaviorDescriptor;
import java.util.Arrays;
import jetbrains.mps.lang.editor.menus.substitute.ConstraintsFilteringSubstituteMenuPartDecorator;
import jetbrains.mps.lang.editor.menus.ParameterizedMenuPart;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.internal.collections.runtime.ListSequence;
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.SPropertyOperations;
import jetbrains.mps.editor.runtime.completion.CompletionItemInformation;
import jetbrains.mps.smodel.runtime.IconResource;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SProperty;

public class EasyInferAndCheckingEntry_Contribution extends SubstituteMenuBase {
  public EasyInferAndCheckingEntry_Contribution() {
    super(true, new EditorMenuDescriptorBase("contribution to the " + "default substitute menu for " + "Statement", new SNodePointer("r:00000000-0000-4000-0000-011c895902b0(jetbrains.mps.lang.typesystem.editor)", "1741258697587166717")));
  }
  @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_myynyp_a());
    return result;
  }

  public class SMP_Group_myynyp_a extends GroupMenuPart<SubstituteMenuItem, SubstituteMenuContext> {
    public SMP_Group_myynyp_a() {
      super(new EditorMenuDescriptorBase("substitute menu group", new SNodePointer("r:00000000-0000-4000-0000-011c895902b0(jetbrains.mps.lang.typesystem.editor)", "1741258697587166720")));
    }
    @Override
    protected boolean isApplicable(SubstituteMenuContext _context) {
      if ((SNodeOperations.getNodeAncestor(_context.getParentNode(), CONCEPTS.InferenceRule$S3, false, false) != null)) {
        return true;
      }

      SNode method = SNodeOperations.getNodeAncestor(_context.getParentNode(), CONCEPTS.BaseMethodDeclaration$kD, false, false);
      if ((method != null) && (boolean) BaseMethodDeclaration__BehaviorDescriptor.hasAnnotation_id3WDGf12DPy8.invoke(method, new SNodePointer("r:00000000-0000-4000-0000-011c895902b5(jetbrains.mps.lang.typesystem.dependencies)", "1196177069451"))) {
        return true;
      }
      return false;
    }
    @Override
    protected List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> getParts() {
      return Arrays.<MenuPart<SubstituteMenuItem, SubstituteMenuContext>>asList(new ConstraintsFilteringSubstituteMenuPartDecorator(new SMP_Param_myynyp_a0(), CONCEPTS.CreateLessThanInequationStatement$Qs));
    }
    private class SMP_Param_myynyp_a0 extends ParameterizedMenuPart<String, SubstituteMenuItem, SubstituteMenuContext> {
      /*package*/ SMP_Param_myynyp_a0() {
        super(new EditorMenuDescriptorBase("parameterized substitute menu part", new SNodePointer("r:00000000-0000-4000-0000-011c895902b0(jetbrains.mps.lang.typesystem.editor)", "1741258697587166785")));
      }
      @NotNull
      @Override
      protected List<SubstituteMenuItem> createItems(String parameter, SubstituteMenuContext context) {
        return new SMP_Action_myynyp_a0a(parameter).createItems(context);
      }
      @Nullable
      @Override
      protected Iterable<? extends String> getParameters(SubstituteMenuContext _context) {
        return ListSequence.fromListAndArray(new ArrayList<String>(), "infer typeof", "check typeof");
      }
      private class SMP_Action_myynyp_a0a extends SingleItemSubstituteMenuPart {
        private final String myParameterObject;
        public SMP_Action_myynyp_a0a(String 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.CreateLessThanInequationStatement$Qs, context);
            _context = context;
          }

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

          @Nullable
          @Override
          public SNode createNode(@NotNull String pattern) {
            SNode rule = SNodeFactoryOperations.createNewNode(CONCEPTS.CreateLessThanInequationStatement$Qs, null);
            if (myParameterObject.equals("check typeof")) {
              SPropertyOperations.assign(rule, PROPS.checkOnly$2Mur, true);
            }
            return rule;
          }

          @NotNull
          protected CompletionItemInformation createInformation(String pattern) {
            return new CompletionItemInformation(myParameterObject, CONCEPTS.CreateLessThanInequationStatement$Qs, 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 InferenceRule$S3 = MetaAdapterFactory.getConcept(0x7a5dda6291404668L, 0xab76d5ed1746f2b2L, 0x1117e2f5efaL, "jetbrains.mps.lang.typesystem.structure.InferenceRule");
    /*package*/ static final SConcept BaseMethodDeclaration$kD = MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, "jetbrains.mps.baseLanguage.structure.BaseMethodDeclaration");
    /*package*/ static final SConcept CreateLessThanInequationStatement$Qs = MetaAdapterFactory.getConcept(0x7a5dda6291404668L, 0xab76d5ed1746f2b2L, 0x1117f60bfd5L, "jetbrains.mps.lang.typesystem.structure.CreateLessThanInequationStatement");
  }

  private static final class PROPS {
    /*package*/ static final SProperty checkOnly$2Mur = MetaAdapterFactory.getProperty(0x7a5dda6291404668L, 0xab76d5ed1746f2b2L, 0x1117f3c1ffaL, 0x118e0a511a0L, "checkOnly");
  }
}
