Tweak pretty-printed Java source output for proper indentation on JSNI methods. Review by: spoon git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5204 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/SourceGenerationVisitor.java b/dev/core/src/com/google/gwt/dev/jjs/impl/SourceGenerationVisitor.java index 46282f5..1f52bfd 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/SourceGenerationVisitor.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/SourceGenerationVisitor.java
@@ -20,6 +20,7 @@ import com.google.gwt.dev.jjs.ast.JField; import com.google.gwt.dev.jjs.ast.JInterfaceType; import com.google.gwt.dev.jjs.ast.JMethod; +import com.google.gwt.dev.jjs.ast.JMethodBody; import com.google.gwt.dev.jjs.ast.JProgram; import com.google.gwt.dev.jjs.ast.JReferenceType; import com.google.gwt.dev.util.TextOutput; @@ -48,10 +49,6 @@ @Override public boolean visit(JClassType x, Context ctx) { - // All classes are deemed "static" so the monolithic compile results can be - // copy/pasted into a single enclosing class. - print(CHARS_STATIC); - super.visit(x, ctx); openBlock(); @@ -64,6 +61,13 @@ } for (int i = 0; i < x.methods.size(); ++i) { JMethod it = x.methods.get(i); + // Suppress empty clinit. + if (i == 0) { + JMethodBody body = (JMethodBody) it.getBody(); + if (body.getBlock().getStatements().isEmpty()) { + continue; + } + } accept(it); newline(); newline();
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ToStringGenerationVisitor.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ToStringGenerationVisitor.java index 2848db1..9ad064c 100644 --- a/dev/core/src/com/google/gwt/dev/jjs/impl/ToStringGenerationVisitor.java +++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ToStringGenerationVisitor.java
@@ -88,6 +88,7 @@ import com.google.gwt.dev.jjs.ast.js.JsonArray; import com.google.gwt.dev.jjs.ast.js.JsonObject; import com.google.gwt.dev.jjs.ast.js.JsonObject.JsonPropInit; +import com.google.gwt.dev.js.JsSourceGenerationVisitor; import com.google.gwt.dev.util.TextOutput; import java.util.Iterator; @@ -739,10 +740,13 @@ } @Override - public boolean visit(JsniMethodBody x, Context ctx) { + public boolean visit(final JsniMethodBody x, Context ctx) { print(" /*-"); - String source = x.getFunc().getBody().toSource(); - print(source.trim()); + new JsSourceGenerationVisitor(this) { + { + printJsBlock(x.getFunc().getBody(), false, false); + } + }; print("-*/"); semi(); return false;
diff --git a/dev/core/src/com/google/gwt/dev/js/JsSourceGenerationVisitor.java b/dev/core/src/com/google/gwt/dev/js/JsSourceGenerationVisitor.java index 4a15d4a..1a0ff06 100644 --- a/dev/core/src/com/google/gwt/dev/js/JsSourceGenerationVisitor.java +++ b/dev/core/src/com/google/gwt/dev/js/JsSourceGenerationVisitor.java
@@ -45,7 +45,7 @@ @Override public boolean visit(JsBlock x, JsContext<JsStatement> ctx) { - printJsBlockOptionalTruncate(x, false); + printJsBlock(x, false, true); return false; }
diff --git a/dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java b/dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java index f2ce3e9..0660d3e 100644 --- a/dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java +++ b/dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
@@ -179,7 +179,7 @@ @Override public boolean visit(JsBlock x, JsContext<JsStatement> ctx) { - printJsBlockOptionalTruncate(x, true); + printJsBlock(x, true, true); return false; } @@ -798,7 +798,7 @@ p.newlineOpt(); } - protected void printJsBlockOptionalTruncate(JsBlock x, boolean truncate) { + protected void printJsBlock(JsBlock x, boolean truncate, boolean finalNewline) { boolean needBraces = !x.isGlobalBlock(); if (needBraces) { @@ -849,9 +849,12 @@ } if (needBraces) { - // Close braces. - // - _blockClose(); + // _blockClose() modified + p.indentOut(); + p.print('}'); + if (finalNewline) { + _newlineOpt(); + } } needSemi = false; }