Ejemplo n.º 1
0
  /** Compiles a {@code *.str} file to a single {@code *.java} file. */
  private static void strj(
      boolean normalize,
      Path str,
      Path out,
      String main,
      Collection<Path> paths,
      AbstractBaseProcessor baseProcessor)
      throws IOException {

    /*
     * We can include as many paths as we want here, checking the
     * adequacy of the occurring imports is done elsewhere.
     */
    List<String> cmd =
        new ArrayList<String>(
            Arrays.asList(
                new String[] {
                  "-i",
                  toWindowsPath(str.getAbsolutePath()),
                  "-o",
                  toWindowsPath(out.getAbsolutePath()),
                  "-m",
                  main,
                  "-p",
                  "sugarj",
                  "--library",
                  "-O",
                  "0",
                }));

    if (normalize) cmd.add("-F");

    cmd.add("-I");
    cmd.add(StdLib.stdLibDir.getAbsolutePath());
    cmd.add("-I");
    cmd.add(baseProcessor.getLanguage().getPluginDirectory().getAbsolutePath());

    for (Path path : paths)
      if (path.getFile().isDirectory()) {
        cmd.add("-I");
        cmd.add(path.getAbsolutePath());
      }

    final ByteArrayOutputStream log = new ByteArrayOutputStream();

    // Strj requires a fresh context each time.
    Context ctx = org.strategoxt.strj.strj.init();
    try {
      ctx.setIOAgent(strjIOAgent);
      ctx.invokeStrategyCLI(main_strj_0_0.instance, "strj", cmd.toArray(new String[cmd.size()]));
    } catch (StrategoExit e) {
      if (e.getValue() != 0) throw new StrategoException("STRJ failed", e);
    } finally {
      if (log.size() > 0 && !log.toString().contains("Abstract syntax in"))
        throw new StrategoException(log.toString());
    }
  }
Ejemplo n.º 2
0
 /**
  * Filters Spoofax editor-service declarations.
  *
  * @param term a SugarJ extension declaration.
  */
 public static IStrategoTerm extractEditor(IStrategoTerm term) throws IOException {
   IStrategoTerm result = null;
   Context extractionContext = SugarJContexts.extractionContext();
   try {
     result = extract_editor_0_0.instance.invoke(extractionContext, term);
   } catch (StrategoExit e) {
     if (e.getValue() != 0 || result == null)
       throw new RuntimeException("Editor service extraction failed", e);
   } finally {
     SugarJContexts.releaseContext(extractionContext);
   }
   return result;
 }
Ejemplo n.º 3
0
 public static IStrategoTerm renameRules(IStrategoTerm term, String oldName, String newName)
     throws IOException {
   IStrategoTerm result = null;
   Context renameRulesContext = SugarJContexts.renameRulesContext();
   try {
     IStrategoTerm toldName = renameRulesContext.getFactory().makeString(oldName);
     IStrategoTerm tnewName = renameRulesContext.getFactory().makeString(newName);
     result = rename_rules_0_2.instance.invoke(renameRulesContext, term, toldName, tnewName);
   } catch (StrategoExit e) {
     if (e.getValue() != 0 || result == null)
       throw new RuntimeException("Stratego extraction failed", e);
   } finally {
     SugarJContexts.releaseContext(renameRulesContext);
   }
   return result;
 }