Пример #1
0
 private static boolean hasModule(Library library, SModule module) {
   if (!isSuitableModule(module) || !ModuleLibraryType.isModuleLibrary(library)) {
     return false;
   }
   Solution solution = (Solution) module;
   return Arrays.asList(library.getFiles(ModuleXmlRootDetector.MPS_MODULE_XML))
       .contains(VirtualFileUtils.getOrCreateVirtualFile(solution.getDescriptorFile()));
 }
  /*package*/ Solution createNewSolution(final IFile solutionDescriptorFile) {
    MPSProject mpsProject = myThis.getProject();

    // Prepare files
    File dir = new File(solutionDescriptorFile.getAbsolutePath()).getParentFile();
    if (!(dir.exists())) {
      dir.mkdirs();
    }
    String solutionFileName = solutionDescriptorFile.getName();
    String solutionName = solutionFileName.substring(0, solutionFileName.length() - 4);

    // Create
    // RE-2448
    ModelRoot modelRoot = new ModelRoot();
    modelRoot.setPrefix("");
    modelRoot.setPath(solutionDescriptorFile.getParent().getAbsolutePath());
    final Solution solution =
        Solution.createStubSolution(solutionName, solutionDescriptorFile, mpsProject, modelRoot);

    SolutionDescriptor solutionDescriptor = solution.getModuleDescriptor();
    solutionDescriptor.setCompileInMPS(myThis.getCompileInMPS());

    // Add SWC file to the classpath
    ModelRoot stubModelEntry = new ModelRoot();
    stubModelEntry.setPath(myThis.getSourcesPath());
    stubModelEntry.setManager(LanguageID.AS_MANAGER);
    solutionDescriptor.getStubModelEntries().add(stubModelEntry);

    // Add languages refs
    solutionDescriptor
        .getUsedLanguages()
        .add(ModuleReference.fromString(Languages.ACTION_SCRIPT_INTERNAL));
    solutionDescriptor
        .getUsedLanguages()
        .add(ModuleReference.fromString(Languages.ACTION_SCRIPT_LOGGING));
    solutionDescriptor
        .getUsedLanguages()
        .add(ModuleReference.fromString(Languages.ACTION_SCRIPT_ASSETS));

    // Add playerglobal reference
    Dependency playerGlobalDependency = new Dependency();
    playerGlobalDependency.setModuleRef(ModuleReference.fromString(PLAYERGLOBAL_SWC));
    solutionDescriptor.getDependencies().add(playerGlobalDependency);

    // Save the solution descriptor
    ModelAccess.instance()
        .writeFilesInEDT(
            new Runnable() {
              public void run() {
                solution.save();
              }
            });
    mpsProject.addProjectModule(solution);

    return solution;
  }
Пример #3
0
  @Override
  protected void doSetModuleDescriptor(ModuleDescriptor moduleDescriptor) {
    assert moduleDescriptor instanceof SolutionDescriptor;
    SolutionDescriptor newDescriptor = (SolutionDescriptor) moduleDescriptor;
    newDescriptor.setNamespace(myModule.getName());
    //    addLibs(newDescriptor);
    super.doSetModuleDescriptor(newDescriptor);

    try {
      ApplicationManager.getApplication()
          .getComponent(JdkStubSolutionManager.class)
          .claimSdk(myModule);
    } catch (final DifferentSdkException e) {

      // TODO this seems to behave suspiciously in tests
      StartupManager.getInstance(myModule.getProject())
          .runWhenProjectIsInitialized(
              new Runnable() {
                @Override
                public void run() {
                  Messages.showErrorDialog(
                      myModule.getProject(),
                      "There are more than one different SDKs used in modules with MPS facets.\n"
                          + "Trying to use "
                          + e.getRequestedSdk().getName()
                          + " while "
                          + e.getCurrentSdk().getName()
                          + " is already used."
                          + "\n",
                      "Multiple SDKs not supported in MPS plugin");
                }
              });
    }
  }
Пример #4
0
 @Override
 public void dispose() {
   final ProjectLibraryTable projectLibraryTable =
       (ProjectLibraryTable) ProjectLibraryTable.getInstance(myModule.getProject());
   ModelAccess.instance()
       .runReadAction(
           new Runnable() {
             @Override
             public void run() {
               for (final Library library : projectLibraryTable.getLibraries()) {
                 if (ModuleLibraryType.isModuleLibrary(library)) {
                   library.getRootProvider().removeRootSetChangedListener(myRootSetListener);
                 }
               }
             }
           });
   projectLibraryTable.removeListener(myLibrariesListener);
   ApplicationManager.getApplication()
       .getComponent(JdkStubSolutionManager.class)
       .releaseSdk(myModule);
   super.dispose();
   myConnection.disconnect();
 }
Пример #5
0
 @Override
 protected void dependenciesChanged() {
   super.dependenciesChanged();
   myDependencies = null;
 }
Пример #6
0
  public int getModelKind(SModel model, @Nullable SReference reference) {
    DataSource source = (model != null ? model.getSource() : null);
    IFile modelFile =
        (source instanceof FileDataSource ? ((FileDataSource) source).getFile() : null);
    if (modelFile != null) {
      String filePath = modelFile.getAbsolutePath().replace('\\', '/');
      if (filePath.startsWith(languagesUtilPath)) {
        return OTHER;
      }
    }

    SModule module = model.getModule();
    if (module instanceof Language) {
      LanguageAspect aspect = Language.getModelAspect(model);
      if (aspect != null) {
        switch (aspect) {
          case ACTIONS:
            return EDITOR;
          case BEHAVIOR:
            return CORE;
          case CONSTRAINTS:
            return CORE;
          case DATA_FLOW:
            return CORE;
          case EDITOR:
            return EDITOR;
          case FIND_USAGES:
            return CORE;
          case INTENTIONS:
            return EDITOR;
          case PLUGIN:
            return WORKBENCH;
          case REFACTORINGS:
            return CORE;
          case SCRIPTS:
            return CORE;
          case STRUCTURE:
            return CORE;
          case STUBS:
            return CORE;
          case TEST:
            return EDITOR;
          case TEXT_GEN:
            return CORE;
          case TYPESYSTEM:
            return CORE;
          default:
        }
      }
      return CORE;

    } else if (module instanceof Solution) {

      String moduleFqName = module.getModuleName();
      if (moduleFqName.equals("JDK")) {
        return CORE;
      }
      if (moduleFqName.equals("MPS.Core")) {
        return CORE;
      }
      if (moduleFqName.equals("MPS.Editor")) {
        return EDITOR;
      }
      if (moduleFqName.equals("MPS.Workbench")) {
        return WORKBENCH;
      }
      if (moduleFqName.equals("MPS.Classpath")) {
        SNode refTargetRoot = reference.getTargetNode().getContainingRoot();
        if (SNodeOperations.isInstanceOf(
            refTargetRoot, "jetbrains.mps.baseLanguage.structure.Classifier")) {
          String cName =
              SPropertyOperations.getString(
                  SNodeOperations.cast(
                      refTargetRoot, "jetbrains.mps.baseLanguage.structure.Classifier"),
                  "name");
          String modelName = model.getModelName();
          if (findInModule(coreModule, modelName, cName)) {
            return CORE;
          }
          if (findInModule(editorModule, modelName, cName)) {
            return EDITOR;
          }
          return WORKBENCH;
        }
        return OTHER;
      }

      Solution sol = (Solution) module;
      switch (sol.getKind()) {
        case NONE:
          return OTHER;
        case PLUGIN_CORE:
          return CORE;
        case PLUGIN_EDITOR:
          return EDITOR;
        case PLUGIN_OTHER:
          return WORKBENCH;
        default:
      }
    }
    return OTHER;
  }