本文整理汇总了Java中org.mozilla.javascript.ast.ErrorCollector类的典型用法代码示例。如果您正苦于以下问题:Java ErrorCollector类的具体用法?Java ErrorCollector怎么用?Java ErrorCollector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ErrorCollector类属于org.mozilla.javascript.ast包,在下文中一共展示了ErrorCollector类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: gatherParserErrorsRhino
import org.mozilla.javascript.ast.ErrorCollector; //导入依赖的package包/类
/**
* Gathers the syntax errors found by Rhino in-process when parsing the
* document.
*
* @param errorHandler The errors found by Rhino.
* @param root The root element of the document parsed.
* @see #gatherParserErrorsJsHint(RSyntaxDocument)
*/
private void gatherParserErrorsRhino(ErrorCollector errorHandler,
Element root) {
List<ParseProblem> errors = errorHandler.getErrors();
if (errors != null && errors.size() > 0) {
for (ParseProblem problem : errors) {
int offs = problem.getFileOffset();
int len = problem.getLength();
int line = root.getElementIndex(offs);
String desc = problem.getMessage();
DefaultParserNotice notice = new DefaultParserNotice(this,
desc, line, offs, len);
if (problem.getType() == ParseProblem.Type.Warning) {
notice.setLevel(ParserNotice.Level.WARNING);
}
result.addNotice(notice);
}
}
}
示例2: ideEnvirons
import org.mozilla.javascript.ast.ErrorCollector; //导入依赖的package包/类
/**
* Returns a {@code CompilerEnvirons} suitable for using Rhino
* in an IDE environment. Most features are enabled by default.
* The {@link ErrorReporter} is set to an {@link ErrorCollector}.
*/
public static CompilerEnvirons ideEnvirons() {
CompilerEnvirons env = new CompilerEnvirons();
env.setRecoverFromErrors(true);
env.setRecordingComments(true);
env.setStrictMode(true);
env.setWarnTrailingComma(true);
env.setLanguageVersion(170);
env.setReservedKeywordAsIdentifier(true);
env.setIdeMode(true);
env.setErrorReporter(new ErrorCollector());
return env;
}
示例3: ideEnvirons
import org.mozilla.javascript.ast.ErrorCollector; //导入依赖的package包/类
/**
* Returns a {@code CompilerEnvirons} suitable for using Rhino
* in an IDE environment. Most features are enabled by default.
* The {@link ErrorReporter} is set to an {@link ErrorCollector}.
*/
public static CompilerEnvirons ideEnvirons() {
CompilerEnvirons env = new CompilerEnvirons();
env.setRecoverFromErrors(true);
env.setRecordingComments(true);
env.setStrictMode(true);
env.setWarnTrailingComma(true);
env.setLanguageVersion(170);
env.setReservedKeywordAsIdentifier(true);
env.setIdeMode(true);
env.setErrorReporter(new ErrorCollector());
return env;
}
示例4: ideEnvirons
import org.mozilla.javascript.ast.ErrorCollector; //导入依赖的package包/类
/**
* Returns a {@code CompilerEnvirons} suitable for using Rhino
* in an IDE environment. Most features are enabled by default.
* The {@link org.mozilla.javascript.ErrorReporter} is set to an {@link org.mozilla.javascript.ast.ErrorCollector}.
*/
public static CompilerEnvirons ideEnvirons() {
CompilerEnvirons env = new CompilerEnvirons();
env.setRecoverFromErrors(true);
env.setRecordingComments(true);
env.setStrictMode(true);
env.setWarnTrailingComma(true);
env.setLanguageVersion(170);
env.setReservedKeywordAsIdentifier(true);
env.setIdeMode(true);
env.setErrorReporter(new ErrorCollector());
return env;
}
示例5: parse
import org.mozilla.javascript.ast.ErrorCollector; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public ParseResult parse(RSyntaxDocument doc, String style) {
astRoot = null;
result.clearNotices();
// Always spell check all lines, for now.
Element root = doc.getDefaultRootElement();
int lineCount = root.getElementCount();
result.setParsedLines(0, lineCount - 1);
DocumentReader r = new DocumentReader(doc);
ErrorCollector errorHandler = new ErrorCollector();
CompilerEnvirons env = createCompilerEnvironment(errorHandler, langSupport);
long start = System.currentTimeMillis();
try {
Parser parser = new Parser(env);
astRoot = parser.parse(r, null, 0);
long time = System.currentTimeMillis() - start;
result.setParseTime(time);
} catch (IOException ioe) { // Never happens
result.setError(ioe);
ioe.printStackTrace();
} catch (RhinoException re) {
// Shouldn't happen since we're passing an ErrorCollector in
int line = re.lineNumber();
// if (line>0) {
Element elem = root.getElement(line);
int offs = elem.getStartOffset();
int len = elem.getEndOffset() - offs - 1;
String msg = re.details();
result.addNotice(new DefaultParserNotice(this, msg, line, offs, len));
// }
} catch (Exception e) {
result.setError(e); // catch all
}
r.close();
// Get any parser errors.
switch (langSupport.getErrorParser()) {
default:
case RHINO:
gatherParserErrorsRhino(errorHandler, root);
break;
case JSHINT:
gatherParserErrorsJsHint(doc);
break;
}
// addNotices(doc);
support.firePropertyChange(PROPERTY_AST, null, astRoot);
return result;
}