private AstRoot parse( String string, final String[] errors, final String[] warnings, boolean jsdoc) { TestErrorReporter testErrorReporter = new TestErrorReporter(errors, warnings) { @Override public EvaluatorException runtimeError( String message, String sourceName, int line, String lineSource, int lineOffset) { if (errors == null) { throw new UnsupportedOperationException(); } return new EvaluatorException(message, sourceName, line, lineSource, lineOffset); } }; environment.setErrorReporter(testErrorReporter); environment.setRecordingComments(true); environment.setRecordingLocalJsDocComments(jsdoc); Parser p = new Parser(environment, testErrorReporter); AstRoot script = null; try { script = p.parse(string, null, 0); } catch (EvaluatorException e) { if (errors == null) { // EvaluationExceptions should not occur when we aren't expecting // errors. throw e; } } assertTrue(testErrorReporter.hasEncounteredAllErrors()); assertTrue(testErrorReporter.hasEncounteredAllWarnings()); return script; }
private AstRoot parseAsReader(String string) throws IOException { TestErrorReporter testErrorReporter = new TestErrorReporter(null, null); environment.setErrorReporter(testErrorReporter); environment.setRecordingComments(true); environment.setRecordingLocalJsDocComments(true); Parser p = new Parser(environment, testErrorReporter); AstRoot script = p.parse(new StringReader(string), null, 0); assertTrue(testErrorReporter.hasEncounteredAllErrors()); assertTrue(testErrorReporter.hasEncounteredAllWarnings()); return script; }