Example #1
0
 protected void readModules(FileMPSProject.ProjectDescriptor projDesc) {
   myErrors = null;
   //  load solutions
   Set<ModuleReference> existingModules = getModuleReferences();
   for (Path modulePath : projDesc.getModules()) {
     String path = modulePath.getPath();
     IFile descriptorFile = FileSystem.getInstance().getFileByPath(path);
     if (descriptorFile.exists()) {
       ModuleDescriptor descriptor =
           ModulesMiner.getInstance().loadModuleDescriptor(descriptorFile);
       if (descriptor != null) {
         ModulesMiner.ModuleHandle moduleHandle =
             new ModulesMiner.ModuleHandle(descriptorFile, descriptor);
         IModule m = ModuleRepositoryFacade.createModule(moduleHandle, this);
         ModuleReference moduleReference = m.getModuleReference();
         if (!(existingModules.remove(moduleReference))) {
           super.addModule(moduleReference);
         }
       } else {
         error("Can't load module from " + descriptorFile.getPath() + " Unknown file type.");
       }
     } else {
       error("Can't load module from " + descriptorFile.getPath() + " File doesn't exist.");
     }
   }
   for (ModuleReference ref : existingModules) {
     super.removeModule(ref);
   }
 }
Example #2
0
 public void showItemInHierarchy(SNode node) {
   myHierarchyTree.setHierarchyNode(node);
   final jetbrains.mps.project.Project mpsProject = getMPSProject();
   mpsProject
       .getModelAccess()
       .runReadInEDT(
           new Runnable() {
             @Override
             public void run() {
               Project project = getProject();
               if (project == null || project.isDisposed()) {
                 return;
               }
               myHierarchyTree.rebuildNow();
               if (myHierarchyTree.getActiveTreeNode() != null) {
                 myHierarchyTree.setRootNodeText(
                     "<html>Hierarchy for <font color=\"#400090\"><b>"
                         + StringUtil.escapeXml(
                             myHierarchyTree.getActiveTreeNode().calculateNodeIdentifier())
                         + "</b></font>",
                     getIcon());
                 myHierarchyTree.selectNode(myHierarchyTree.getActiveTreeNode());
               }
               if (!(isTreeInfinite())) {
                 myHierarchyTree.expandAll();
               }
             }
           });
 }
Example #3
0
 private SModelDescriptor findModel(SModelReference reference) {
   if (reference.equals(myModel.getSModelReference())) {
     return myModel.getModelDescriptor();
   }
   List<IScope> scopes = ListSequence.fromList(new ArrayList<IScope>());
   IScope ps = myProject.getScope();
   if (ps != null) {
     ListSequence.fromList(scopes).addElement(ps);
   }
   ListSequence.fromList(scopes).addElement(GlobalScope.getInstance());
   for (IScope scope : ListSequence.fromList(scopes)) {
     SModelDescriptor md = scope.getModelDescriptor(reference);
     if (md != null) {
       return md;
     }
   }
   // if we can't find model using full reference, try to find by fq-name
   // this is needed for viewing diff on models saved before MPS 2.0 M5
   for (IScope scope : ListSequence.fromList(scopes)) {
     SModelDescriptor md = scope.getModelDescriptor(reference.getSModelFqName());
     if (md != null) {
       return md;
     }
   }
   return null;
 }
Example #4
0
  /**
   * @deprecated use {@link #process(ProgressMonitor, List)} or {@link #process(ProgressMonitor,
   *     SModel)} instead
   * @param invocationContext ignored, may be null
   */
  @Deprecated
  @ToRemove(version = 3.4)
  public static boolean generateModels(
      final Project p,
      final List<? extends SModel> inputModels,
      final IOperationContext invocationContext,
      final IGenerationHandler generationHandler,
      final ProgressMonitor monitor,
      final IMessageHandler messages,
      final GenerationOptions options,
      @NotNull final TransientModelsProvider tmProvider) {

    final GenerationFacade generationFacade = new GenerationFacade(p.getRepository(), options);
    generationFacade
        .taskHandler(new LegacyTaskListener(generationHandler))
        .messages(messages)
        .transients(tmProvider);
    generationFacade.modelStreams(new ModelStreamProviderImpl());
    final DefaultTaskBuilder<GeneratorTaskBase> tb =
        new DefaultTaskBuilder<GeneratorTaskBase>(
            new Factory<GeneratorTaskBase>() {
              @Override
              public GeneratorTaskBase create(SModel inputModel) {
                return new GeneratorTaskBase(inputModel);
              }
            });
    tb.addAll(inputModels);
    return generationFacade.process0(monitor, tb.getResult());
  }
Example #5
0
 @Override
 protected ActionGroup createPopupActionGroup(final MPSTreeNode treeNode) {
   final TypeSystemStateTreeNode stateNode = (TypeSystemStateTreeNode) treeNode;
   final DefaultActionGroup group = ActionUtils.groupFromActions();
   myProject
       .getModelAccess()
       .runReadAction(
           new Runnable() {
             @Override
             public void run() {
               NodeMaps maps = myState.getNodeMaps();
               List<SNode> vars = stateNode.getVariables();
               if (null == vars) {
                 return;
               }
               for (SNode var : vars) {
                 SNode node = check_x8yvv7_a0a0d0a0a0a0d0u(maps, var);
                 if (node != null && node.getModel() != null) {
                   final SNodeReference pointer = new jetbrains.mps.smodel.SNodePointer(node);
                   group.add(
                       new BaseAction("Go to node with type " + var) {
                         @Override
                         public void doExecute(AnActionEvent e, Map<String, Object> _params) {
                           new EditorNavigator(myProject)
                               .shallFocus(true)
                               .shallSelect(true)
                               .open(pointer);
                         }
                       });
                 }
               }
             }
           });
   return group;
 }
Example #6
0
 private void highlightNodesWithTypes(final Collection<? extends MPSTreeNode> treeNodes) {
   clearHighlighting();
   myProject
       .getModelAccess()
       .runReadAction(
           new Runnable() {
             @Override
             public void run() {
               NodeMaps maps = myState.getNodeMaps();
               List<EditorMessage> messages = new ArrayList<EditorMessage>();
               for (MPSTreeNode treeNode : treeNodes) {
                 TypeSystemStateTreeNode stateNode = (TypeSystemStateTreeNode) treeNode;
                 List<SNode> vars = stateNode.getVariables();
                 if (null == vars) {
                   continue;
                 }
                 for (SNode var : vars) {
                   SNode node = check_x8yvv7_a0a0d0c0a0a0a0b0t(maps, var);
                   if (node != null && node.getModel() != null) {
                     EditorCell nodeCell = myEditorComponent.findNodeCell(node);
                     if (nodeCell != null) {
                       messages.add(
                           new TypeSystemStateTree.TypeEditorMessage(
                               nodeCell, String.valueOf(var)));
                     }
                   }
                 }
                 if (messages.size() > 0) {
                   myHighlightManager.mark(messages);
                 }
               }
             }
           });
 }
Example #7
0
 @Override
 public void read(Element element, Project project) throws CantLoadSomethingException {
   super.read(element, project);
   Element filterXML = element.getChild(FILTER);
   String filterName = filterXML.getAttribute(CLASS_NAME).getValue();
   try {
     Class filterClass = null;
     for (Language l : project.getProjectModules(Language.class)) {
       filterClass = ClassLoaderManager.getInstance().getClass(l, filterName);
       if (filterClass != null) break;
     }
     if (filterClass == null) {
       try {
         filterClass = Class.forName(filterName);
       } catch (ClassNotFoundException e) {
         filterClass = null;
       }
     }
     if (filterClass != null) {
       myFilter = (BaseFilter) filterClass.newInstance();
     } else {
       throw new CantLoadSomethingException("Can't find filter class " + filterName);
     }
   } catch (Throwable t) {
     throw new CantLoadSomethingException("Can't instantiate or read filter " + filterName, t);
   }
 }
 private String newSessionId() {
   File projectFile = myProject.getProjectFile();
   return (projectFile != null
           ? projectFile.getAbsolutePath().hashCode()
           : System.identityHashCode(myProject))
       + Long.toHexString(System.currentTimeMillis());
 }
Example #9
0
 @Override
 public Description getDescription() {
   if (myDescription == null) {
     myDescription =
         Description.createSuiteDescription("\"" + ourMPSProject.getName() + "\" project opened");
   }
   return myDescription;
 }
Example #10
0
 private void invokeTest(final _FunctionTypes._void_P0_E0 test) {
   Project project =
       BaseMpsTest.openProject(
           new File(PathManager.getHomePath() + "/languages/languageDesign/traceinfo"));
   try {
     project
         .getRepository()
         .getModelAccess()
         .runReadAction(
             new Runnable() {
               public void run() {
                 test.invoke();
               }
             });
   } finally {
     cleanup(project);
   }
 }
Example #11
0
 final void process() {
   if (!myGuard.tryAcquire()) {
     return;
   }
   try {
     do {
       int batchProcessMax =
           20; // do not process more than X at once, not to block any write actions nor UI thread
       // for too long
       final ArrayList<Pair<MPSTreeNode, NodeUpdate>> updates =
           new ArrayList<Pair<MPSTreeNode, NodeUpdate>>(batchProcessMax);
       Pair<MPSTreeNode, NodeUpdate> u;
       while ((u = myUpdates.poll()) != null && batchProcessMax > 0) {
         if (u.o1.getTree() == null) {
           // no reason to update element which is not in the tree
           continue;
         }
         updates.add(u);
         batchProcessMax--;
       }
       if (updates.isEmpty()) {
         break;
       }
       myProject
           .getModelAccess()
           .runReadInEDT(
               new Runnable() {
                 @Override
                 public void run() {
                   final HashSet<MPSTreeNode> toRefresh = new HashSet<MPSTreeNode>();
                   for (Pair<MPSTreeNode, NodeUpdate> next : updates) {
                     MPSTreeNode node = next.o1;
                     if (node.getTree() == null) {
                       // once again, no reason to update element which is not in the tree
                       continue;
                     }
                     next.o2.update(node);
                     toRefresh.add(node);
                   }
                   for (MPSTreeNode node : toRefresh) {
                     node.updateNodePresentationInTree();
                   }
                 }
               });
     } while (!myUpdates.isEmpty());
     myTimer.suspend();
   } finally {
     myGuard.release();
   }
 }
Example #12
0
 @Override
 public void dispose() {
   super.dispose();
   ModelAccess.instance()
       .runWriteAction(
           new Runnable() {
             public void run() {
               ClassLoaderManager.getInstance().unloadAll(new EmptyProgressMonitor());
               ModuleRepositoryFacade.getInstance().unregisterModules(FileMPSProject.this);
               CleanupManager.getInstance().cleanup();
               if (ProjectManager.getInstance().getOpenProjects().length > 0) {
                 ClassLoaderManager.getInstance().reloadAll(new EmptyProgressMonitor());
               }
               ClassLoaderManager.getInstance().updateClassPath();
             }
           });
 }
  @Override
  protected void doRefactoringAction() {
    final boolean needToRegenerate = myRegenerateLanguage.getModel().isSelected();

    final String fqName = getCurrentValue();
    if (MPSModuleRepository.getInstance().getModuleByFqName(fqName) != null) {
      setErrorText("Duplicate language name");
      return;
    }
    if (!((SourceVersion.isName(fqName)))) {
      setErrorText("Language namespace should be valid Java package");
      return;
    }
    final LanguageRenamer renamer = new LanguageRenamer(myProject, myLanguage, fqName);
    ModelAccess modelAccess = myProject.getRepository().getModelAccess();
    modelAccess.executeCommand(
        new Runnable() {
          public void run() {
            renamer.rename(needToRegenerate);
            renamer.update();
          }
        });
    if (needToRegenerate) {
      final Map<SModule, List<SModel>> langs = new LinkedHashMap<SModule, List<SModel>>();
      modelAccess.runReadAction(
          new Runnable() {
            public void run() {
              RefactoringUtil.fillLanguageAndItsExtendingLanguageModels(myLanguage, langs);
            }
          });
      for (final List<SModel> models : langs.values()) {
        ModuleContext context = new ModuleContext(myLanguage, myProject);
        MakeSession sess = new MakeSession(context);
        if (IMakeService.INSTANCE.get().openNewSession(sess)) {
          IMakeService.INSTANCE
              .get()
              .make(sess, new ModelsToResources(context, models).resources(false));
        }
        //         GeneratorUIFacade.getInstance().generateModels(new ModuleContext(myLanguage,
        // myProject), params.getModelDescriptors(),
        // GeneratorUIFacade.getInstance().getDefaultGenerationHandler(), true, false);
      }
    }
    super.doRefactoringAction();
  }
  public RenameLanguageDialog(com.intellij.openapi.project.Project project, Language language)
      throws HeadlessException {
    super(project, language.getModuleName(), "language");
    myLanguage = language;
    myProject = ProjectHelper.toMPSProject(project);
    setTitle("Rename Language");

    final boolean[] regenerateHolder = new boolean[] {false};
    myProject
        .getRepository()
        .getModelAccess()
        .runReadAction(
            new Runnable() {
              public void run() {
                regenerateHolder[0] = !(myLanguage.isBootstrap());
              }
            });
    myRegenerateLanguage.getModel().setSelected(regenerateHolder[0]);
  }
Example #15
0
 private List<Runner> createChildRunners(Project project, final RunnerBuilder builder) {
   final List<Runner> result = new ArrayList<Runner>();
   project
       .getModelAccess()
       .runReadAction(
           new Runnable() {
             public void run() {
               for (SModule module : ListSequence.fromList(myContextProject.getProjectModules())) {
                 for (SModel model : Sequence.fromIterable(module.getModels())) {
                   for (SNode testCase :
                       ListSequence.fromList(
                           SModelOperations.roots(
                               ((SModel) model),
                               MetaAdapterFactory.getInterfaceConcept(
                                   0xf61473f9130f42f6L,
                                   0xb98d6c438812c2f6L,
                                   0x11b2709bd56L,
                                   "jetbrains.mps.baseLanguage.unitTest.structure.ITestCase")))) {
                     String testClassName =
                         ((String)
                             BHReflection.invoke(
                                 testCase,
                                 SMethodTrimmedId.create("getClassName", null, "hGBnqtL")));
                     try {
                       Class<?> testClass = myClassLoader.loadClass(testClassName);
                       result.add(new DelegatingRunner(builder, testClass));
                     } catch (ClassNotFoundException e) {
                       if (LOG.isEnabledFor(Level.WARN)) {
                         LOG.warn(
                             "Cannot find the test class "
                                 + testClassName
                                 + "; will skip this test class");
                       }
                     }
                   }
                 }
               }
             }
           });
   return result;
 }
Example #16
0
 @Nullable
 public JComponent createCenterPanel() {
   if (mySolutionSettings == null) {
     mySolutionSettings =
         new NewSolutionSettings(
             (myProject != null
                 ? ((((ProjectEx) ProjectHelper.toIdeaProject(myProject))
                             .getStateStore()
                             .getStorageScheme()
                         != StorageScheme.DIRECTORY_BASED
                     ? myProject.getProjectFile().getParentFile().getAbsolutePath()
                     : myProject.getProjectFile().getAbsolutePath()))
                 : null));
     mySolutionSettings.setListener(
         new NewSolutionSettings.SolutionSettingsChangedListener() {
           @Override
           public void changed() {
             NewSolutionDialog.this.check();
           }
         });
   }
   return mySolutionSettings;
 }
Example #17
0
  protected void init(Class<?> testClass) throws InitializationError {
    String projectPath = getProjectPath(testClass);
    MpsTestsSupport.initEnv(true);
    IdeMain.setTestMode(IdeMain.TestMode.CORE_TEST);
    initPathMacros();
    if (ourMPSProject != null) {
      throw new InitializationError(
          "One MPS project was already openned in this java process: "
              + ourMPSProject.getName()
              + " (on trying to open: "
              + projectPath
              + ")");
    }
    ourMPSProject = TestMain.PROJECT_CONTAINER.getProject(projectPath);

    // TODO:
    //
    // 2. Libraries?
    // 3. Cache location ?
    // 4. creste separate suite generating (making) all modules in this project by using
    // ProjectTestHelper?
    ModelAccess.instance().flushEventQueue();
  }
Example #18
0
 @Override
 public void projectClosed() {
   super.projectClosed();
 }
Example #19
0
 @Override
 public void projectOpened() {
   super.projectOpened();
 }
  @Override
  public boolean testRefactoring(
      final Project project,
      final SModel sandbox1,
      final SModel sandbox2,
      final Language testRefactoringLanguage,
      final Language testRefactoringTargetLanguage) {
    final String newConceptName = "MyVeryGoodConcept2";
    final ModelAccess modelAccess = project.getRepository().getModelAccess();
    final Wrappers._T<IRefactoring> refactoring = new Wrappers._T<IRefactoring>();
    modelAccess.runReadAction(
        new Runnable() {
          public void run() {
            refactoring.value =
                RefactoringUtil.getRefactoringByClassName(
                    BehaviorReflection.invokeVirtual(
                        String.class,
                        SNodeOperations.getNode(
                            "r:de5b7214-45ee-4f6d-89bf-acde59cdb050(jetbrains.mps.lang.structure.refactorings)",
                            "1347577327951781517"),
                        "virtual_getFqName_1213877404258",
                        new Object[] {}));
          }
        });

    final RefactoringContext refactoringContext =
        new RefactoringContext(project, refactoring.value);
    refactoringContext.setCurrentOperationContext(new ProjectOperationContext(project));

    modelAccess.runReadAction(
        new Runnable() {
          public void run() {
            final SModel structureModelDescriptor =
                testRefactoringLanguage.getStructureModelDescriptor();
            refactoringContext.setParameter(
                RenameConceptRefactoringTester.STRMD, structureModelDescriptor);
            SModel model = structureModelDescriptor;
            SNode concept = SModelOperations.getRootByName(model, "MyVeryGoodConcept1");
            refactoringContext.setSelectedNode(concept);
            refactoringContext.setSelectedModel(structureModelDescriptor);
            refactoringContext.setParameter("newName", newConceptName);
          }
        });
    new RefactoringTestFacade().doExecuteInTest(refactoringContext);
    final boolean[] result = new boolean[] {false};
    ThreadUtils.runInUIThreadAndWait(
        new Runnable() {
          @Override
          public void run() {
            modelAccess.runReadAction(
                new Runnable() {
                  public void run() {
                    try {
                      if (sandbox1.isLoaded()) {
                        System.err.println(
                            "test environment is invalid: model sandbox1 is already initialized, should be not");
                        result[0] = false;
                        return;
                      }
                      SModel sModel = sandbox1;
                      String conceptFqName =
                          sModel.getRootNodes().iterator().next().getConcept().getConceptId();
                      SModel structureModelDescriptor =
                          (SModel)
                              refactoringContext.getParameter(RenameConceptRefactoringTester.STRMD);
                      result[0] =
                          conceptFqName.equals(
                              structureModelDescriptor.getReference().getModelName()
                                  + "."
                                  + newConceptName);
                    } catch (Throwable t) {
                      t.printStackTrace();
                      result[0] = false;
                    }
                  }
                });
          }
        });
    return result[0];
  }
Example #21
0
  private void updateFields(AnActionEvent e) {
    // cleaning all local fields
    myOperationContext = null;
    myModelDescriptor = null;
    myConceptFqNameToNodePointerMap.clear();
    myProject = e.getData(PlatformDataKeys.PROJECT);

    if (myProject == null) {
      return;
    }
    jetbrains.mps.project.Project mpsProject = ProjectHelper.toMPSProject(myProject);
    if (mpsProject == null) {
      return;
    }

    Module module = e.getData(LangDataKeys.MODULE);
    VirtualFile[] vFiles = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
    if (module == null || vFiles == null || vFiles.length != 1) {
      return;
    }

    MPSFacet mpsFacet = FacetManager.getInstance(module).getFacetByType(MPSFacetType.ID);
    if (mpsFacet == null || !mpsFacet.wasInitialized()) {
      return;
    }

    String url = vFiles[0].getUrl();
    if (!LocalFileSystem.PROTOCOL.equals(VirtualFileManager.extractProtocol(url))) {
      return;
    }
    String path = VirtualFileManager.extractPath(url);
    for (ModelRoot root : mpsFacet.getSolution().getModelRoots()) {
      if (!(root instanceof DefaultModelRoot)) continue;
      DefaultModelRoot modelRoot = (DefaultModelRoot) root;
      for (String sourceRoot : modelRoot.getFiles(DefaultModelRoot.SOURCE_ROOTS)) {
        if (path.startsWith(sourceRoot)) {
          Solution solution = mpsFacet.getSolution();
          myOperationContext = new ModuleContext(solution, mpsProject);
          myModelDescriptor =
              (EditableSModel)
                  SModelFileTracker.getInstance()
                      .findModel(FileSystem.getInstance().getFileByPath(vFiles[0].getPath()));
          if (myModelDescriptor != null) {
            mpsProject
                .getModelAccess()
                .runReadAction(
                    new Runnable() {
                      @Override
                      public void run() {
                        SModel model = myModelDescriptor;
                        List<Language> modelLanguages = SModelOperations.getLanguages(model);
                        for (Language language : modelLanguages) {
                          for (SNode concept : language.getConceptDeclarations()) {
                            String conceptFqName = NameUtil.nodeFQName(concept);
                            if (ModelConstraints.canBeRoot(conceptFqName, model, null)) {
                              myConceptFqNameToNodePointerMap.put(
                                  conceptFqName, new jetbrains.mps.smodel.SNodePointer(concept));
                            }
                          }
                        }
                      }
                    });
          } else {
            myNewModel = true;
          }
          return;
        }
      }
    }
  }
Example #22
0
 private static SRepository check_6q36mf_a0a0a0a82(Project checkedDotOperand) {
   if (null != checkedDotOperand) {
     return checkedDotOperand.getRepository();
   }
   return null;
 }
Example #23
0
 public static Language getLanguage(Project project, String languageName) {
   return project.getScope().getLanguage(languageName);
 }
  public void run() {
    ModelAccessHelper mah = new ModelAccessHelper(myProject.getModelAccess());
    final SNode contextEnumConstant =
        mah.runReadAction(
            new Computable<SNode>() {
              public SNode compute() {
                return SNodeOperations.getAncestor(
                    mySelectedNode,
                    "jetbrains.mps.baseLanguage.structure.EnumConstantDeclaration",
                    true,
                    false);
              }
            });
    final SNode contextMember =
        mah.runReadAction(
            new Computable<SNode>() {
              public SNode compute() {
                return SNodeOperations.getAncestor(
                    mySelectedNode,
                    "jetbrains.mps.baseLanguage.structure.ClassifierMember",
                    true,
                    false);
              }
            });
    final SNodeReference[] methods =
        mah.runReadAction(
            new Computable<SNodeReference[]>() {
              @Override
              public SNodeReference[] compute() {
                List<SNode> methodsToOverride =
                    (myIsOverride
                        ? BehaviorReflection.invokeVirtual(
                            (Class<List<SNode>>) ((Class) Object.class),
                            contextEnumConstant,
                            "virtual_getMethodsToOverride_5418393554803767537",
                            new Object[] {})
                        : BehaviorReflection.invokeVirtual(
                            (Class<List<SNode>>) ((Class) Object.class),
                            contextEnumConstant,
                            "virtual_getMethodsToImplement_5418393554803775106",
                            new Object[] {}));
                List<SNode> allSuperClassifiers =
                    BehaviorReflection.invokeNonVirtual(
                        (Class<List<SNode>>) ((Class) Object.class),
                        SNodeOperations.cast(
                            SNodeOperations.getParent(contextEnumConstant),
                            "jetbrains.mps.baseLanguage.structure.EnumClass"),
                        "jetbrains.mps.baseLanguage.structure.ClassConcept",
                        "call_getAllSuperClassifiers_4892662966716545618",
                        new Object[] {});
                ListSequence.fromList(allSuperClassifiers)
                    .addElement(
                        SNodeOperations.cast(
                            SNodeOperations.getParent(contextEnumConstant),
                            "jetbrains.mps.baseLanguage.structure.Classifier"));
                return OverrideImplementMethodsDialog.toNodePointers(
                    OverrideImplementMethodsDialog.sortMethods(
                        allSuperClassifiers, methodsToOverride));
              }
            });

    final OverrideImplementMethodsDialog dialog =
        new OverrideImplementMethodsDialog(methods, ProjectHelper.toIdeaProject(myProject)) {
          @Override
          protected boolean showInsertOverride() {
            return myIsOverride;
          }
        };

    dialog.setTitle((myIsOverride ? "Select Methods to Override" : "Select Methods to Implement"));
    dialog.show();

    if (dialog.isOK()) {
      final Iterable<SNodeReference> selectedElements =
          (Iterable<SNodeReference>) dialog.getSelectedElements();

      myProject
          .getModelAccess()
          .executeCommandInEDT(
              new Runnable() {
                @Override
                public void run() {
                  List<SNode> selection =
                      Sequence.fromIterable(selectedElements)
                          .select(
                              new ISelector<SNodeReference, SNode>() {
                                public SNode select(SNodeReference it) {
                                  return SNodeOperations.cast(
                                      ((SNodePointer) it)
                                          .resolve(MPSModuleRepository.getInstance()),
                                      "jetbrains.mps.baseLanguage.structure.BaseMethodDeclaration");
                                }
                              })
                          .toListSequence();
                  OverrideImplementMethodsHelper helper =
                      new OverrideImplementMethodsInEnumHelper(
                          myProject,
                          SNodeOperations.cast(
                              SNodeOperations.getParent(contextEnumConstant),
                              "jetbrains.mps.baseLanguage.structure.EnumClass"),
                          contextEnumConstant,
                          contextMember,
                          dialog.isRemoveAttributes(),
                          dialog.isInsertOverrideAnnotation(),
                          dialog.isAddReturn());
                  List<SNode> insertedMethods = helper.insertMethods(selection);
                  if (insertedMethods.isEmpty()) {
                    return;
                  }
                  SNode firstMethod = ListSequence.fromList(insertedMethods).first();
                  SNode nodeToSelect;
                  if (ListSequence.fromList(
                          SLinkOperations.getTargets(
                              SLinkOperations.getTarget(firstMethod, "body", true),
                              "statement",
                              true))
                      .isNotEmpty()) {
                    nodeToSelect =
                        ListSequence.fromList(
                                SLinkOperations.getTargets(
                                    SLinkOperations.getTarget(firstMethod, "body", true),
                                    "statement",
                                    true))
                            .first();
                  } else {
                    nodeToSelect = firstMethod;
                  }
                  myEditorContext.flushEvents();
                  myEditorContext.getSelectionManager().setSelection(nodeToSelect);
                }
              });
    }
  }
Example #25
0
 public static SModelDescriptor getModel(Project project, String modelName) {
   return project.getScope().getModelDescriptor(SModelReference.fromString(modelName));
 }
Example #26
0
 /**
  * @deprecated see {@link GenerationSessionContext#getRepository()} for reasons. It's not the idea
  *     that generator knows about the context repository is bad, we just need better story around
  *     it.
  */
 @Deprecated
 public SRepository getRepository() {
   return myProject.getRepository();
 }