@Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) throws Exception { final CompilerOptions copts = new CompilerOptions(); copts.setCodingConvention(new ClosureCodingConvention()); copts.setOutputCharset(StandardCharsets.UTF_8); copts.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); CompilationLevel level = level(get("level")); level.setOptionsForCompilationLevel(copts); Compiler.setLoggingLevel(Level.SEVERE); Compiler compiler = new Compiler(); compiler.disableThreads(); compiler.initOptions(copts); List<SourceFile> externs = externs(copts); Result result = compiler.compile(externs, ImmutableList.of(SourceFile.fromCode(filename, source)), copts); if (result.success) { return compiler.toSource(); } List<AssetProblem> errors = Arrays.stream(result.errors) .map(error -> new AssetProblem(error.sourceName, error.lineNumber, error.getCharno(), error.description, null)) .collect(Collectors.toList()); throw new AssetException(name(), errors); }
@Override public int hashCode() { return Objects.hash( level, error.description, error.sourceName, error.lineNumber, error.getCharno()); }
@Override public boolean equals(Object obj) { if (!(obj instanceof ErrorWithLevel)) { return false; } ErrorWithLevel e = (ErrorWithLevel) obj; return Objects.equals(level, e.level) && Objects.equals(error.description, e.error.description) && Objects.equals(error.sourceName, e.error.sourceName) && error.lineNumber == e.error.lineNumber && error.getCharno() == e.error.getCharno(); } }
String getExcerptWithPosition(JSError error) { return getExcerptWithPosition(error, error.sourceName, error.lineNumber, error.getCharno()); }