use of com.google.javascript.jscomp.JSError in project closure-compiler by google.
the class FixingErrorManager method getAllFixes.
/**
* Returns fixes for errors first, then fixes for warnings.
*/
public Collection<SuggestedFix> getAllFixes() {
boolean containsFixableShorthandModuleWarning = containsFixableShorthandModuleWarning();
Collection<SuggestedFix> fixes = new ArrayList<>();
for (JSError error : getErrors()) {
// don't apply the extra/missing require fix.
if (containsFixableShorthandModuleWarning && (error.getType().equals(EXTRA_REQUIRE_WARNING) || error.getType().equals(MISSING_REQUIRE_STRICT_WARNING) || error.getType().equals(MISSING_REQUIRE_WARNING))) {
// Don't apply this fix.
} else {
fixes.addAll(getFixesForJsError(error));
}
}
for (JSError warning : getWarnings()) {
if (warning.getType().equals(EXTRA_REQUIRE_WARNING) && containsFixableShorthandModuleWarning) {
// As above, don't apply the extra-require fix.
} else {
fixes.addAll(getFixesForJsError(warning));
}
}
return fixes;
}
use of com.google.javascript.jscomp.JSError in project closure-compiler by google.
the class ErrorToFixMapperTest method testImplicitNullability2.
@Test
public void testImplicitNullability2() {
String originalCode = "/** @param {Object} o */ function f(o) {}";
compiler.compile(// Externs
ImmutableList.<SourceFile>of(), ImmutableList.of(SourceFile.fromCode("test", originalCode)), options);
assertThat(compiler.getErrors()).isEmpty();
JSError[] warnings = compiler.getWarnings();
assertThat(warnings).hasLength(1);
JSError warning = warnings[0];
List<SuggestedFix> fixes = ErrorToFixMapper.getFixesForJsError(warning, compiler);
assertThat(fixes).hasSize(2);
// First fix is to add "!"
String newCode = ApplySuggestedFixes.applySuggestedFixesToCode(ImmutableList.of(fixes.get(0)), ImmutableMap.of("test", originalCode)).get("test");
assertThat(newCode).isEqualTo("/** @param {?Object} o */ function f(o) {}");
// Second fix is to add "?"
newCode = ApplySuggestedFixes.applySuggestedFixesToCode(ImmutableList.of(fixes.get(1)), ImmutableMap.of("test", originalCode)).get("test");
assertThat(newCode).isEqualTo("/** @param {!Object} o */ function f(o) {}");
}
use of com.google.javascript.jscomp.JSError in project closure-compiler by google.
the class GwtRunner method toNativeErrorArray.
/**
* Convert a list of {@link JSError} instances to a JS array containing plain objects.
*/
private static JavaScriptObject[] toNativeErrorArray(List<JSError> errors) {
JavaScriptObject[] out = new JavaScriptObject[errors.size()];
for (int i = 0; i < errors.size(); ++i) {
JSError error = errors.get(i);
DiagnosticType type = error.getType();
out[i] = createError(error.sourceName, error.description, type != null ? type.key : null, error.lineNumber, error.getCharno());
}
return out;
}
use of com.google.javascript.jscomp.JSError in project closure-compiler by google.
the class TranspilationException method format.
private static String format(SourceExcerptProvider source, JSError[] errors, JSError[] warnings) {
StringBuilder sb = new StringBuilder().append("Transpilation failed:\n");
MessageFormatter formatter = source != null ? ErrorFormat.SINGLELINE.toFormatter(source, false) : ErrorFormat.SOURCELESS.toFormatter(source, false);
for (JSError error : errors) {
sb.append("\n").append(formatter.formatError(error));
}
for (JSError warning : warnings) {
sb.append("\n").append(formatter.formatError(warning));
}
return sb.toString();
}
use of com.google.javascript.jscomp.JSError in project closure-compiler by google.
the class DebuggerGwtMain method updateUi.
private void updateUi(Compiler compiler, Result result) {
rightPane.clear();
rightPane.add(new HTML("<h4>Output</h4>"));
String outputCode = compiler.toSource();
rightPane.add(new Label(outputCode));
rightPane.add(new HTML("<h4>Warnings</h4>"));
List<JSError> errors = Arrays.asList(result.errors);
List<JSError> warnings = Arrays.asList(result.warnings);
rightPane.add(new Label(Joiner.on("\n\n").join(Iterables.concat(errors, warnings))));
rightPane.add(new HTML("<h4>AST</h4>"));
String outputAst = compiler.getRoot().toStringTree();
rightPane.add(new Label(outputAst));
}
Aggregations