Exemple #1
0
  public static List<String> loadBeforeAfterText(String filePath) {
    String content;

    try {
      content = FileUtil.loadFile(new File(filePath), true);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    List<String> files =
        createTestFiles(
            "",
            content,
            new TestFileFactoryNoModules<String>() {
              @NotNull
              @Override
              public String create(
                  @NotNull String fileName,
                  @NotNull String text,
                  @NotNull Map<String, String> directives) {
                int firstLineEnd = text.indexOf('\n');
                return StringUtil.trimTrailing(text.substring(firstLineEnd + 1));
              }
            });

    Assert.assertTrue("Exactly two files expected: ", files.size() == 2);

    return files;
  }
Exemple #2
0
  public static TestRun compileAndCheck(
      Iterable<? extends JavaFileObject> files, String processor, String[] options) {
    List<String> opts = new LinkedList<String>();
    if (processor != null) {
      opts.add("-processor");
      opts.add(processor);
    }
    opts.add("-source");
    opts.add("1.8");
    for (String option : options) opts.add(option);

    TestInput input =
        new TestInput(files, Collections.<String>emptySet(), opts.toArray(new String[opts.size()]));
    return input.run();
  }
Exemple #3
0
 /** Return true if all is ok, no errors */
 protected boolean antlr(
     String fileName, String grammarFileName, String grammarStr, boolean debug) {
   boolean allIsWell = true;
   mkdir(tmpdir);
   writeFile(tmpdir, fileName, grammarStr);
   try {
     final List options = new ArrayList();
     if (debug) {
       options.add("-debug");
     }
     options.add("-o");
     options.add(tmpdir);
     options.add("-lib");
     options.add(tmpdir);
     options.add(new File(tmpdir, grammarFileName).toString());
     final String[] optionsA = new String[options.size()];
     options.toArray(optionsA);
     ErrorQueue equeue = new ErrorQueue();
     Tool antlr = newTool(optionsA);
     antlr.addListener(equeue);
     antlr.processGrammarsOnCommandLine();
     if (equeue.errors.size() > 0) {
       allIsWell = false;
       System.err.println("antlr reports errors from " + options);
       for (int i = 0; i < equeue.errors.size(); i++) {
         ANTLRMessage msg = (ANTLRMessage) equeue.errors.get(i);
         System.err.println(msg);
       }
       System.out.println("!!!\ngrammar:");
       System.out.println(grammarStr);
       System.out.println("###");
     }
   } catch (Exception e) {
     allIsWell = false;
     System.err.println("problems building grammar: " + e);
     e.printStackTrace(System.err);
   }
   return allIsWell;
 }
Exemple #4
0
 public Token LT(int i) {
   if ((p + i - 1) >= types.size()) return new CommonToken(-1);
   return new CommonToken(types.get(p + i - 1));
 }
Exemple #5
0
 public int size() {
   return types.size();
 }