Search in sources :

Example 1 with JSError

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;
}
Also used : ArrayList(java.util.ArrayList) JSError(com.google.javascript.jscomp.JSError)

Example 2 with JSError

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) {}");
}
Also used : JSError(com.google.javascript.jscomp.JSError) Test(org.junit.Test)

Example 3 with JSError

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;
}
Also used : JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) DiagnosticType(com.google.javascript.jscomp.DiagnosticType) EntryPoint(com.google.gwt.core.client.EntryPoint) JSError(com.google.javascript.jscomp.JSError)

Example 4 with JSError

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();
}
Also used : MessageFormatter(com.google.javascript.jscomp.MessageFormatter) JSError(com.google.javascript.jscomp.JSError)

Example 5 with JSError

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));
}
Also used : Label(com.google.gwt.user.client.ui.Label) HTML(com.google.gwt.user.client.ui.HTML) JSError(com.google.javascript.jscomp.JSError)

Aggregations

JSError (com.google.javascript.jscomp.JSError)9 Test (org.junit.Test)3 MessageFormatter (com.google.javascript.jscomp.MessageFormatter)2 EntryPoint (com.google.gwt.core.client.EntryPoint)1 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 HTML (com.google.gwt.user.client.ui.HTML)1 Label (com.google.gwt.user.client.ui.Label)1 BasicErrorManager (com.google.javascript.jscomp.BasicErrorManager)1 CheckLevel (com.google.javascript.jscomp.CheckLevel)1 CompilationLevel (com.google.javascript.jscomp.CompilationLevel)1 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)1 DiagnosticType (com.google.javascript.jscomp.DiagnosticType)1 ArrayList (java.util.ArrayList)1 SecurityContext (org.structr.common.SecurityContext)1 PropertyMap (org.structr.core.property.PropertyMap)1