示例#1
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());
  }
  @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();
  }
示例#3
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);
   }
 }
  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]);
  }
  @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];
  }
示例#6
0
 private static SRepository check_6q36mf_a0a0a0a82(Project checkedDotOperand) {
   if (null != checkedDotOperand) {
     return checkedDotOperand.getRepository();
   }
   return null;
 }
示例#7
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();
 }