/plugins/mps-build/languages/build/source_gen/jetbrains/mps/build/editor/BuildStringPart_SubstituteMenu.java
Java | 303 lines | 279 code | 23 blank | 1 comment | 14 complexity | fc02dd2524a7db55f06653acc8ec9a73 MD5 | raw file
- package jetbrains.mps.build.editor;
- /*Generated by MPS */
- import jetbrains.mps.nodeEditor.menus.substitute.SubstituteMenuBase;
- 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.EditorMenuDescriptorBase;
- import jetbrains.mps.smodel.SNodePointer;
- import jetbrains.mps.lang.editor.menus.ParameterizedMenuPart;
- import org.jetbrains.mps.openapi.model.SNode;
- import org.jetbrains.annotations.Nullable;
- import jetbrains.mps.scope.Scope;
- import jetbrains.mps.internal.collections.runtime.Sequence;
- import jetbrains.mps.internal.collections.runtime.IWhereFilter;
- import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
- import jetbrains.mps.internal.collections.runtime.ISelector;
- import jetbrains.mps.lang.editor.menus.substitute.SingleItemSubstituteMenuPart;
- import org.apache.log4j.Logger;
- import jetbrains.mps.lang.editor.menus.substitute.DefaultSubstituteMenuItem;
- import jetbrains.mps.openapi.editor.menus.EditorMenuTraceInfo;
- 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.presentation.NodePresentationUtil;
- import jetbrains.mps.smodel.runtime.IconResource;
- import jetbrains.mps.smodel.runtime.IconResourceUtil;
- import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
- import java.util.regex.Pattern;
- import java.util.regex.Matcher;
- import jetbrains.mps.build.behavior.BuildStringContainer__BehaviorDescriptor;
- import jetbrains.mps.lang.editor.menus.ConceptMenusPart;
- import java.util.Collection;
- import jetbrains.mps.smodel.ConceptDescendantsCache;
- import org.jetbrains.mps.openapi.language.SAbstractConcept;
- import jetbrains.mps.lang.editor.menus.substitute.DefaultSubstituteMenuLookup;
- import jetbrains.mps.smodel.language.LanguageRegistry;
- import org.jetbrains.mps.openapi.language.SConcept;
- import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
- import org.jetbrains.mps.openapi.language.SInterfaceConcept;
- import org.jetbrains.mps.openapi.language.SReferenceLink;
- import org.jetbrains.mps.openapi.language.SProperty;
- public class BuildStringPart_SubstituteMenu extends SubstituteMenuBase {
- @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_fvo6kj_a(), CONCEPTS.BuildVarRefStringPart$2T));
- result.add(new ConstraintsFilteringSubstituteMenuPartDecorator(new SMP_Action_fvo6kj_b(), CONCEPTS.BuildTextStringPart$3R));
- result.add(new SMP_Subconcepts_fvo6kj_c());
- return result;
- }
- @NotNull
- @Override
- public List<SubstituteMenuItem> createMenuItems(@NotNull SubstituteMenuContext context) {
- context.getEditorMenuTrace().pushTraceInfo();
- context.getEditorMenuTrace().setDescriptor(new EditorMenuDescriptorBase("default substitute menu for " + "BuildStringPart", new SNodePointer("r:00f69407-23a8-49a2-a236-9e89a32679aa(jetbrains.mps.build.editor)", "1741258697587202349")));
- try {
- return super.createMenuItems(context);
- } finally {
- context.getEditorMenuTrace().popTraceInfo();
- }
- }
- private class SMP_Param_fvo6kj_a extends ParameterizedMenuPart<SNode, SubstituteMenuItem, SubstituteMenuContext> {
- @NotNull
- @Override
- protected List<SubstituteMenuItem> createItems(SNode parameter, SubstituteMenuContext context) {
- return new SMP_Action_fvo6kj_a0(parameter).createItems(context);
- }
- @NotNull
- @Override
- public List<SubstituteMenuItem> createItems(@NotNull SubstituteMenuContext context) {
- context.getEditorMenuTrace().pushTraceInfo();
- context.getEditorMenuTrace().setDescriptor(new EditorMenuDescriptorBase("parameterized substitute menu part", new SNodePointer("r:00f69407-23a8-49a2-a236-9e89a32679aa(jetbrains.mps.build.editor)", "1741258697587202351")));
- try {
- return super.createItems(context);
- } finally {
- context.getEditorMenuTrace().popTraceInfo();
- }
- }
- @Nullable
- @Override
- protected Iterable<? extends SNode> getParameters(SubstituteMenuContext _context) {
- Scope scope = Scope.getScope(((_context.getCurrentTargetNode() != null) ? _context.getCurrentTargetNode() : _context.getParentNode()), null, CONCEPTS.BuildMacro$qd);
- if (scope == null) {
- return null;
- }
- return Sequence.fromIterable(scope.getAvailableElements(null)).where(new IWhereFilter<SNode>() {
- public boolean accept(SNode it) {
- return SNodeOperations.isInstanceOf(it, CONCEPTS.BuildVariableMacro$Rk);
- }
- }).select(new ISelector<SNode, SNode>() {
- public SNode select(SNode it) {
- return SNodeOperations.cast(it, CONCEPTS.BuildVariableMacro$Rk);
- }
- }).toListSequence();
- }
- private class SMP_Action_fvo6kj_a0 extends SingleItemSubstituteMenuPart {
- private final SNode myParameterObject;
- public SMP_Action_fvo6kj_a0(SNode parameterObject) {
- myParameterObject = parameterObject;
- }
- @Nullable
- @Override
- protected SubstituteMenuItem createItem(SubstituteMenuContext _context) {
- Item item = new Item(_context);
- String description;
- try {
- description = "Substitute item: " + item.getMatchingText("");
- description += ". Parameter object: " + myParameterObject;
- } catch (Throwable t) {
- Logger.getLogger(getClass()).error("Exception while executing getMatchingText() of the item " + item, t);
- return null;
- }
- _context.getEditorMenuTrace().pushTraceInfo();
- try {
- _context.getEditorMenuTrace().setDescriptor(new EditorMenuDescriptorBase(description, new SNodePointer("r:00f69407-23a8-49a2-a236-9e89a32679aa(jetbrains.mps.build.editor)", "1741258697587202430")));
- item.setTraceInfo(_context.getEditorMenuTrace().getTraceInfo());
- } finally {
- _context.getEditorMenuTrace().popTraceInfo();
- }
- return item;
- }
- private class Item extends DefaultSubstituteMenuItem {
- private final SubstituteMenuContext _context;
- private EditorMenuTraceInfo myTraceInfo;
- public Item(SubstituteMenuContext context) {
- super(CONCEPTS.BuildVarRefStringPart$2T, context);
- _context = context;
- }
- private void setTraceInfo(EditorMenuTraceInfo traceInfo) {
- myTraceInfo = traceInfo;
- }
- @Nullable
- @Override
- public SNode createNode(@NotNull String pattern) {
- SNode res = SNodeFactoryOperations.createNewNode(_context.getModel(), CONCEPTS.BuildVarRefStringPart$2T, null);
- SLinkOperations.setTarget(res, LINKS.macro$zsHz, myParameterObject);
- return res;
- }
- @Override
- public EditorMenuTraceInfo getTraceInfo() {
- return myTraceInfo;
- }
- @NotNull
- protected CompletionItemInformation createInformation(String pattern) {
- return new CompletionItemInformation(myParameterObject, CONCEPTS.BuildVarRefStringPart$2T, getMatchingText(pattern), getDescriptionText(pattern));
- }
- @Nullable
- @Override
- public String getDescriptionText(@NotNull String pattern) {
- if (myParameterObject instanceof SNode) {
- return NodePresentationUtil.descriptionText((SNode) myParameterObject);
- }
- return "" + myParameterObject;
- }
- @Nullable
- @Override
- public IconResource getIcon(@NotNull String pattern) {
- if (myParameterObject instanceof SNode) {
- return IconResourceUtil.getIconResourceForNode(((SNode) myParameterObject));
- }
- return null;
- }
- @Nullable
- @Override
- public String getMatchingText(@NotNull String pattern) {
- return "$" + SPropertyOperations.getString(myParameterObject, PROPS.name$MnvL);
- }
- }
- }
- }
- private class SMP_Action_fvo6kj_b extends SingleItemSubstituteMenuPart {
- @Nullable
- @Override
- protected SubstituteMenuItem createItem(SubstituteMenuContext _context) {
- Item item = new Item(_context);
- String description;
- try {
- description = "Substitute item: " + item.getMatchingText("");
- } catch (Throwable t) {
- Logger.getLogger(getClass()).error("Exception while executing getMatchingText() of the item " + item, t);
- return null;
- }
- _context.getEditorMenuTrace().pushTraceInfo();
- try {
- _context.getEditorMenuTrace().setDescriptor(new EditorMenuDescriptorBase(description, new SNodePointer("r:00f69407-23a8-49a2-a236-9e89a32679aa(jetbrains.mps.build.editor)", "1741258697587202512")));
- item.setTraceInfo(_context.getEditorMenuTrace().getTraceInfo());
- } finally {
- _context.getEditorMenuTrace().popTraceInfo();
- }
- return item;
- }
- private class Item extends DefaultSubstituteMenuItem {
- private final SubstituteMenuContext _context;
- private EditorMenuTraceInfo myTraceInfo;
- public Item(SubstituteMenuContext context) {
- super(CONCEPTS.BuildTextStringPart$3R, context);
- _context = context;
- }
- private void setTraceInfo(EditorMenuTraceInfo traceInfo) {
- myTraceInfo = traceInfo;
- }
- @Nullable
- @Override
- public SNode createNode(@NotNull String pattern) {
- SNode buildText = SNodeFactoryOperations.createNewNode(_context.getModel(), CONCEPTS.BuildTextStringPart$3R, null);
- SPropertyOperations.set(buildText, PROPS.text$lRuU, pattern);
- return buildText;
- }
- @Override
- public EditorMenuTraceInfo getTraceInfo() {
- return myTraceInfo;
- }
- @Nullable
- @Override
- public String getMatchingText(@NotNull String pattern) {
- if ((pattern == null || pattern.length() == 0)) {
- return "text";
- }
- {
- Pattern _pattern_0 = REGEXP;
- Matcher _matcher_0 = _pattern_0.matcher(pattern);
- if (_matcher_0.find()) {
- SNode container = (SNodeOperations.isInstanceOf(_context.getParentNode(), CONCEPTS.BuildString$bl) ? SNodeOperations.getParent(_context.getParentNode()) : _context.getParentNode());
- if (SNodeOperations.isInstanceOf(container, CONCEPTS.BuildStringContainer$o9)) {
- if ((boolean) BuildStringContainer__BehaviorDescriptor.isValidPart_id7XQqoCTkVIS.invoke(SNodeOperations.cast(container, CONCEPTS.BuildStringContainer$o9), pattern, (SNodeOperations.isInstanceOf(_context.getParentNode(), CONCEPTS.BuildString$bl) ? _context.getParentNode().getContainmentLink() : _context.getCurrentTargetNode().getContainmentLink()))) {
- return pattern;
- }
- } else if (!(pattern.contains("$"))) {
- return pattern;
- }
- return "text";
- }
- }
- return null;
- }
- }
- }
- public class SMP_Subconcepts_fvo6kj_c extends ConceptMenusPart<SubstituteMenuItem, SubstituteMenuContext> {
- protected Collection getConcepts(final SubstituteMenuContext _context) {
- return ConceptDescendantsCache.getInstance().getDirectDescendants(CONCEPTS.BuildStringPart$1V);
- }
- @NotNull
- @Override
- public List<SubstituteMenuItem> createItems(SubstituteMenuContext context) {
- context.getEditorMenuTrace().pushTraceInfo();
- context.getEditorMenuTrace().setDescriptor(new EditorMenuDescriptorBase("include menus for all the direct subconcepts of " + "BuildStringPart", new SNodePointer("r:00f69407-23a8-49a2-a236-9e89a32679aa(jetbrains.mps.build.editor)", "1741258697587202743")));
- try {
- return super.createItems(context);
- } finally {
- context.getEditorMenuTrace().popTraceInfo();
- }
- }
- @Override
- protected Collection<SubstituteMenuItem> createItemsForConcept(SubstituteMenuContext context, SAbstractConcept concept) {
- return context.createItems(new DefaultSubstituteMenuLookup(LanguageRegistry.getInstance(context.getEditorContext().getRepository()), concept));
- }
- }
- private static final Pattern REGEXP = Pattern.compile("[^\\$].*", 0);
- private static final class CONCEPTS {
- /*package*/ static final SConcept BuildVarRefStringPart$2T = MetaAdapterFactory.getConcept(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x440d7ea3b68b7d01L, "jetbrains.mps.build.structure.BuildVarRefStringPart");
- /*package*/ static final SConcept BuildTextStringPart$3R = MetaAdapterFactory.getConcept(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x440d7ea3b68b7d03L, "jetbrains.mps.build.structure.BuildTextStringPart");
- /*package*/ static final SConcept BuildMacro$qd = MetaAdapterFactory.getConcept(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x4df58c6f18f84a1fL, "jetbrains.mps.build.structure.BuildMacro");
- /*package*/ static final SConcept BuildVariableMacro$Rk = MetaAdapterFactory.getConcept(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x3449288aa0d560e2L, "jetbrains.mps.build.structure.BuildVariableMacro");
- /*package*/ static final SConcept BuildString$bl = MetaAdapterFactory.getConcept(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x3cca41cd0fe51d4fL, "jetbrains.mps.build.structure.BuildString");
- /*package*/ static final SInterfaceConcept BuildStringContainer$o9 = MetaAdapterFactory.getInterfaceConcept(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x7f76698a3953bbb4L, "jetbrains.mps.build.structure.BuildStringContainer");
- /*package*/ static final SConcept BuildStringPart$1V = MetaAdapterFactory.getConcept(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x440d7ea3b68b7cffL, "jetbrains.mps.build.structure.BuildStringPart");
- }
- private static final class LINKS {
- /*package*/ static final SReferenceLink macro$zsHz = MetaAdapterFactory.getReferenceLink(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x440d7ea3b68b7d01L, 0x440d7ea3b68b7d02L, "macro");
- }
- private static final class PROPS {
- /*package*/ static final SProperty name$MnvL = MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name");
- /*package*/ static final SProperty text$lRuU = MetaAdapterFactory.getProperty(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x440d7ea3b68b7d03L, 0x440d7ea3b68c4d56L, "text");
- }
- }