Beispiel #1
0
 protected void checkGrammarSemanticsWarning(
     ErrorQueue equeue, GrammarSemanticsMessage expectedMessage) throws Exception {
   ANTLRMessage foundMsg = null;
   for (int i = 0; i < equeue.warnings.size(); i++) {
     ANTLRMessage m = equeue.warnings.get(i);
     if (m.errorType == expectedMessage.errorType) {
       foundMsg = m;
     }
   }
   assertNotNull("no error; " + expectedMessage.errorType + " expected", foundMsg);
   assertTrue(
       "error is not a GrammarSemanticsMessage", foundMsg instanceof GrammarSemanticsMessage);
   assertEquals(Arrays.toString(expectedMessage.args), Arrays.toString(foundMsg.args));
   if (equeue.size() != 1) {
     System.err.println(equeue);
   }
 }
Beispiel #2
0
 protected void checkError(ErrorQueue equeue, ANTLRMessage expectedMessage) throws Exception {
   // System.out.println("errors="+equeue);
   ANTLRMessage foundMsg = null;
   for (int i = 0; i < equeue.errors.size(); i++) {
     ANTLRMessage m = (ANTLRMessage) equeue.errors.get(i);
     if (m.errorType == expectedMessage.errorType) {
       foundMsg = m;
     }
   }
   assertTrue("no error; " + expectedMessage.errorType + " expected", equeue.errors.size() > 0);
   assertTrue("too many errors; " + equeue.errors, equeue.errors.size() <= 1);
   assertNotNull("couldn't find expected error: " + expectedMessage.errorType, foundMsg);
   /*
   assertTrue("error is not a GrammarSemanticsMessage",
   		   foundMsg instanceof GrammarSemanticsMessage);
    */
   assertTrue(Arrays.equals(expectedMessage.args, foundMsg.args));
 }
Beispiel #3
0
  /**
   * Wow! much faster than compiling outside of VM. Finicky though. Had rules called r and modulo.
   * Wouldn't compile til I changed to 'a'.
   */
  protected boolean compile(String fileName) {
    String classpathOption = "-classpath";

    String[] args =
        new String[] {
          "javac",
          "-d",
          tmpdir,
          classpathOption,
          tmpdir + pathSep + CLASSPATH,
          tmpdir + "/" + fileName
        };
    String cmdLine =
        "javac"
            + " -d "
            + tmpdir
            + " "
            + classpathOption
            + " "
            + tmpdir
            + pathSep
            + CLASSPATH
            + " "
            + fileName;
    // System.out.println("compile: "+cmdLine);

    File f = new File(tmpdir, fileName);
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    //		DiagnosticCollector<JavaFileObject> diagnostics =
    //			new DiagnosticCollector<JavaFileObject>();

    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);

    Iterable<? extends JavaFileObject> compilationUnits =
        fileManager.getJavaFileObjectsFromFiles(Arrays.asList(f));

    Iterable<String> compileOptions =
        Arrays.asList(new String[] {"-d", tmpdir, "-cp", tmpdir + pathSep + CLASSPATH});

    JavaCompiler.CompilationTask task =
        compiler.getTask(null, fileManager, null, compileOptions, null, compilationUnits);
    boolean ok = task.call();

    try {
      fileManager.close();
    } catch (IOException ioe) {
      ioe.printStackTrace(System.err);
    }

    //		List<String> errors = new ArrayList<String>();
    //		for (Diagnostic diagnostic : diagnostics.getDiagnostics()) {
    //			errors.add(
    //				String.valueOf(diagnostic.getLineNumber())+
    //				": " + diagnostic.getMessage(null));
    //		}
    //		if ( errors.size()>0 ) {
    //			System.err.println("compile stderr from: "+cmdLine);
    //			System.err.println(errors);
    //			return false;
    //		}
    return ok;

    /*
    File outputDir = new File(tmpdir);
    try {
    	Process process =
    		Runtime.getRuntime().exec(args, null, outputDir);
    	StreamVacuum stdout = new StreamVacuum(process.getInputStream());
    	StreamVacuum stderr = new StreamVacuum(process.getErrorStream());
    	stdout.start();
    	stderr.start();
    	process.waitFor();
              stdout.join();
              stderr.join();
    	if ( stdout.toString().length()>0 ) {
    		System.err.println("compile stdout from: "+cmdLine);
    		System.err.println(stdout);
    	}
    	if ( stderr.toString().length()>0 ) {
    		System.err.println("compile stderr from: "+cmdLine);
    		System.err.println(stderr);
    	}
    	int ret = process.exitValue();
    	return ret==0;
    }
    catch (Exception e) {
    	System.err.println("can't exec compilation");
    	e.printStackTrace(System.err);
    	return false;
    }
    */
  }