コード例 #1
0
ファイル: SolutionIdea.java プロジェクト: norro/MPS
  @Override
  public Iterable<SDependency> getDeclaredDependencies() {
    if (myDependencies == null) {
      myDependencies = new ArrayList<SDependency>();

      ArrayList<Module> usedModules =
          new ArrayList<Module>(
              Arrays.asList(ModuleRootManager.getInstance(myModule).getDependencies()));
      for (Module usedModule : usedModules) {
        MPSFacet usedModuleMPSFacet =
            FacetManager.getInstance(usedModule).getFacetByType(MPSFacetType.ID);
        if (usedModuleMPSFacet != null && usedModuleMPSFacet.wasInitialized()) {
          myDependencies.add(
              new SDependencyImpl(
                  usedModuleMPSFacet.getSolution(), SDependencyScope.DEFAULT, false));
        }
      }

      addUsedSdk(myDependencies);
      addUsedLibraries(myDependencies);

      // adding JDK module to a set of dependencies
      // why, oh, why are we doing it?
      // FIXME, PLEASE!
      //      Solution jdkSolution = StubSolutionIdea.getJdkSolution();
      //      if (jdkSolution != null) {
      //        myDependencies.add(new Dependency(jdkSolution.getModuleReference(), false));
      //      }
    }
    return myDependencies;
  }
コード例 #2
0
ファイル: NewRootAction.java プロジェクト: sasundaresan/MPS
  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;
        }
      }
    }
  }