Esempio n. 1
0
 @NotNull
 protected final Project getProject() {
   Project mpsProject = ProjectHelper.toMPSProject(this.getConsoleTool().getProject());
   if (mpsProject == null) {
     throw new IllegalStateException("Cannot convert idea project to the mps project");
   }
   return mpsProject;
 }
Esempio n. 2
0
 public static IOperationContext getOperationContext(
     com.intellij.openapi.project.Project project, SModel model) {
   SModelDescriptor md = model.getModelDescriptor();
   assert md != null;
   IModule module = md.getModule();
   if (module instanceof DiffTemporaryModule) {
     return ((DiffTemporaryModule) module).createContext();
   } else {
     return new ModuleContext(module, ProjectHelper.toMPSProject(project));
   }
 }
Esempio n. 3
0
 public void init(Project project) {
   super.init(project);
   ModuleRepository_Tool.this.myComponent =
       new ModuleRepositoryComponent(ProjectHelper.toMPSProject(project));
   ModuleRepository_Tool.this.myPanel = new JPanel(new BorderLayout());
   ModuleRepository_Tool.this.myPanel.add(
       ModuleRepository_Tool.this.myComponent.getComponent(), BorderLayout.CENTER);
   DefaultActionGroup group = new DefaultActionGroup();
   group.add(new CloseAction(ModuleRepository_Tool.this));
   JComponent toolbar =
       ActionManager.getInstance()
           .createActionToolbar(ActionPlaces.UNKNOWN, group, false)
           .getComponent();
   ModuleRepository_Tool.this.myPanel.add(toolbar, BorderLayout.WEST);
 }
Esempio n. 4
0
  @NotNull
  protected IOperationContext createOperationContext() {
    if (myContext != null) {
      return myContext;
    }

    assert isValid()
        : "createOperationContext() was called for MPSFileNodeEditor with invalid file: " + myFile;
    SModelDescriptor sm = myFile.getNode().getModel().getModelDescriptor();
    assert sm != null : "Model descriptor is null for model: " + myFile.getNode().getModel();

    IOperationContext result =
        new ModuleContext(sm.getModule(), ProjectHelper.toMPSProject(myProject));
    assert result.getModule() == sm.getModule()
        : "Different modules: " + result.getModule() + "/" + sm.getModule();
    return result;
  }
 private static void execute_id7oNS25df64x(@NotNull SNode __thisNode__, Project project) {
   SNode targetNode =
       SLinkOperations.getTarget(
           __thisNode__,
           MetaAdapterFactory.getReferenceLink(
               0xde1ad86d6e504a02L,
               0xb306d4d17f64c375L,
               0x36ac6f29ae8c1fb5L,
               0x4904fd89e74fc6fL,
               "target"));
   jetbrains.mps.project.Project mpsProject = ProjectHelper.toMPSProject(project);
   if (mpsProject == null) {
     return;
   }
   NavigationSupport.getInstance()
       .openNode(mpsProject, targetNode, true, !(SNodeOperations.isRoot(targetNode)));
 }
Esempio n. 6
0
  private <T> T getModelProvider(
      AbstractTreeNode treeNode, ModelProviderFactory<T> createProvider) {
    if (!(treeNode instanceof MPSPsiModelTreeNode)) return null; // only model

    MPSPsiModel psiModel = ((MPSPsiModelTreeNode) treeNode).getModel();
    if (psiModel == null || !psiModel.isValid()) return null;

    Project project = treeNode.getProject();
    EditableSModel modelDescriptor = getModel(treeNode);

    jetbrains.mps.project.Project mpsProject = ProjectHelper.toMPSProject(project);
    if (mpsProject == null || modelDescriptor == null) return null;

    SModel sModel = modelDescriptor;
    if (sModel == null) return null;

    return createProvider.create(modelDescriptor, sModel, mpsProject);
  }
Esempio n. 7
0
  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]);
  }
Esempio n. 8
0
  protected IOperationContext createOperationContext() {
    if (myContext != null) {
      return myContext;
    }

    assert isValid()
        : "createOperationContext() was called for MPSFileNodeEditor with invalid file: " + myFile;
    SNode node = myFile.getNode();
    if (node == null || node.getModel() == null || node.getModel().getModelDescriptor() == null) {
      myIsValid = false;
      return null;
    }
    SModelDescriptor sm = node.getModel().getModelDescriptor();

    IOperationContext result =
        new ModuleContext(sm.getModule(), ProjectHelper.toMPSProject(myProject));
    assert result.getModule() == sm.getModule()
        : "Different modules: " + result.getModule() + "/" + sm.getModule();
    return result;
  }
Esempio n. 9
0
  public UnitTestViewComponent(
      Project project,
      ConsoleView console,
      TestRunState testRunState,
      _FunctionTypes._void_P0_E0 closeListener) {
    myProject = project;
    myTestState = testRunState;
    StatisticsTableModel statisticsModel = new StatisticsTableModel(myTestState);

    myTreeComponent = new TestTree(myTestState, ProjectHelper.toMPSProject(project), this);
    myTestNavigator = new FailedTestOccurrenceNavigator(myTreeComponent);
    myActionToolComponent = new TestToolbarPanel(myTreeComponent, myTestNavigator);

    JComponent leftPanel = createTreeComponent(myActionToolComponent, myTreeComponent);

    myProgressLineComponent = new ProgressLine(myTestState);
    myProgressLineComponent.setMinimumSize(
        new Dimension(0, myProgressLineComponent.getMinimumSize().height));
    myOutputComponent = new TestOutputComponent(myProject, this, console, myTestState);
    myTreeComponent.addTreeSelectionListener(
        new TestTreeSelectionListener(myTreeComponent, statisticsModel, myOutputComponent));
    myTreeComponent.addMouseListener(
        new TestTreeRootMouseListener(myTreeComponent, statisticsModel, myOutputComponent));

    JPanel rightPanel =
        createOutputComponent(
            console, myProgressLineComponent, myOutputComponent.getComponent(), statisticsModel);

    Splitter splitter = new Splitter(false);
    initSplitterProportion(splitter, 0.2f, "tree");
    splitter.setFirstComponent(leftPanel);
    splitter.setSecondComponent(rightPanel);
    setLayout(new BorderLayout());

    add(splitter, BorderLayout.CENTER);

    myTestState.addView(myTreeComponent);
    myTestState.addView(myProgressLineComponent);
    myTestState.addView(myOutputComponent);
    addCloseListener(closeListener);
  }
Esempio n. 10
0
 protected void createEditor() {
   this.myEditor =
       new UIEditorComponent(
           check_6q36mf_a0a0a0a82(ProjectHelper.toMPSProject(myTool.getProject())), null) {
         @Nullable
         @Override
         public Object getData(@NonNls String key) {
           if (PlatformDataKeys.FILE_EDITOR.is(key)) {
             return myFileEditor;
           }
           if (PlatformDataKeys.PASTE_PROVIDER.is(key)) {
             PasteProvider parentPasteProvider =
                 as_6q36mf_a0a0a1a0a0a0a0cb(super.getData(key), PasteProvider.class);
             return (myTool.getPasteAsRef()
                 ? new BaseConsoleTab.MyPasteProvider(parentPasteProvider)
                 : parentPasteProvider);
           }
           return super.getData(key);
         }
       };
   myEditor.editNode(myRoot);
 }
Esempio n. 11
0
  private <T> T getProvider(
      Collection<AbstractTreeNode> selected, ProviderFactory<T> createProvider) {
    if (selected.size() == 0) return null;

    List<SNodeReference> selectedNodePointers = new ArrayList<SNodeReference>();
    Project project = null;
    EditableSModel modelDescriptor = null;

    for (AbstractTreeNode treeNode : selected) {
      if (!(treeNode instanceof MPSPsiElementTreeNode)) return null; // only root nodes please

      MPSPsiRootNode mpsPsiNode = ((MPSPsiElementTreeNode) treeNode).getValue();
      if (!mpsPsiNode.isValid()) return null;

      selectedNodePointers.add(mpsPsiNode.getSNodeReference());

      if (project == null) {
        project = treeNode.getProject();
      } else if (project != treeNode.getProject()) {
        return null; // only same project
      }

      if (modelDescriptor == null) {
        modelDescriptor = getModel(mpsPsiNode);
      } else if (modelDescriptor != getModel(mpsPsiNode)) {
        return null; // only same model
      }
    }
    jetbrains.mps.project.Project mpsProject = ProjectHelper.toMPSProject(project);
    if (mpsProject == null || modelDescriptor == null) return null;

    SModel sModel = modelDescriptor;
    if (sModel == null) return null;

    return createProvider.create(selectedNodePointers, modelDescriptor, sModel, mpsProject);
  }
Esempio n. 12
0
  @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.instance()
        .runWriteActionInCommand(
            new Runnable() {
              public void run() {
                renamer.rename(needToRegenerate);
                renamer.update();
              }
            });
    if (needToRegenerate) {
      final Set<Language> langs = new LinkedHashSet<Language>();
      ModelAccess.instance()
          .runReadAction(
              new Runnable() {
                @Override
                public void run() {
                  langs.add(myLanguage);
                  langs.addAll(
                      ModuleRepositoryFacade.getInstance().getAllExtendingLanguages(myLanguage));
                }
              });
      for (final Language l : langs) {
        GenParameters params =
            ModelAccess.instance()
                .runReadAction(
                    new Computable<GenParameters>() {
                      @Override
                      public GenParameters compute() {
                        ModuleTestConfiguration languageConfig = new ModuleTestConfiguration();
                        languageConfig.setModuleRef(l.getModuleReference());
                        languageConfig.setName("tmp");
                        try {
                          return languageConfig.getGenParams(
                              myProject.getComponent(MPSProject.class), true);
                        } catch (IllegalGeneratorConfigurationException e) {
                          return null;
                        }
                      }
                    });
        if (params == null) {
          setErrorText("Rebuild configuration is invalid");
          return;
        }
        ModuleContext context =
            new ModuleContext(myLanguage, ProjectHelper.toMPSProject(myProject));
        MakeSession sess = new MakeSession(context);
        if (IMakeService.INSTANCE.get().openNewSession(sess)) {
          IMakeService.INSTANCE
              .get()
              .make(
                  sess,
                  new ModelsToResources(
                          context,
                          ListSequence.fromListWithValues(
                              new ArrayList<SModel>(),
                              (Iterable<SModel>) params.getModelDescriptors()))
                      .resources(false));
        }
        //         GeneratorUIFacade.getInstance().generateModels(new ModuleContext(myLanguage,
        // myProject), params.getModelDescriptors(),
        // GeneratorUIFacade.getInstance().getDefaultGenerationHandler(), true, false);
      }
    }
    super.doRefactoringAction();
  }
Esempio n. 13
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;
        }
      }
    }
  }
 public List<SNodePointer> getTestsToMake() {
   return this.getJUnitSettings().getTestsToMake(ProjectHelper.toMPSProject(this.getProject()));
 }