/*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;
  }
Пример #2
0
  public ProcessHandler createProcess(SNode file) throws ExecutionException {
    if ((myGccLocation_String == null || myGccLocation_String.length() == 0)
        || !(new File(myGccLocation_String).exists())) {
      throw new ExecutionException("Could not find gcc by path " + myGccLocation_String);
    }

    IFile sourceFile = Gcc_Command.getSourceFile(file);
    if (!((sourceFile.exists()))) {
      throw new ExecutionException(
          "Source file " + sourceFile + " does not exist. Can't compile it.");
    }
    final IFile executableFile = Gcc_Command.getExecutableFile(file);
    ThreadUtils.runInUIThreadAndWait(
        new Runnable() {
          public void run() {
            ModelAccess.instance()
                .requireWrite(
                    new Runnable() {
                      public void run() {
                        executableFile.getParent().mkdirs();
                      }
                    });
          }
        });

    // -xc -- specifies source language (c)
    // -g -- save debug information
    return new Exec_Command()
        .setWorkingDirectory_File(new File(sourceFile.getParent().getAbsolutePath()))
        .setProgramParameters_String(
            "-xc"
                + " "
                + "-g"
                + " "
                + Gcc_Command.protect(sourceFile.getAbsolutePath())
                + " "
                + "-o "
                + Gcc_Command.protect(executableFile.getAbsolutePath()))
        .createProcess(new File(myGccLocation_String));
  }
Пример #3
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;
  }