Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/util/ToFormattedSourceVisitor.java

Issue 137863002: Issue 8742. Preserve leading line comments during java2dart translation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Test for block-style comment translation. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/util/ToFormattedSourceVisitor.java
diff --git a/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/util/ToFormattedSourceVisitor.java b/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/util/ToFormattedSourceVisitor.java
index 612b321f6f65d712b7b5a75ba5ee65f562e56aae..eb1f9c97cf48ebe83acd6899d0c4dd95ffffb7cf 100644
--- a/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/util/ToFormattedSourceVisitor.java
+++ b/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/util/ToFormattedSourceVisitor.java
@@ -20,12 +20,15 @@ import com.google.dart.engine.utilities.dart.ParameterKind;
import org.apache.commons.lang3.StringUtils;
import java.io.PrintWriter;
+import java.util.List;
/**
* Instances of the class {link ToFormattedSourceVisitor} write a source representation of a visited
* AST node (and all of it's children) to a writer.
*/
public class ToFormattedSourceVisitor implements ASTVisitor<Void> {
+ public static final String COMMENTS_KEY = "List of comments before statement";
+
/**
* The writer to which the source is to be written.
*/
@@ -1039,6 +1042,19 @@ public class ToFormattedSourceVisitor implements ASTVisitor<Void> {
indent();
}
+ @SuppressWarnings("unchecked")
+ private void printLeadingComments(Statement statement) {
+ List<String> comments = (List<String>) statement.getProperty(COMMENTS_KEY);
+ if (comments == null) {
+ return;
+ }
+ for (String comment : comments) {
+ writer.print(comment);
+ writer.print("\n");
+ indent();
+ }
+ }
+
/**
* Safely visit the given node.
*
@@ -1159,7 +1175,11 @@ public class ToFormattedSourceVisitor implements ASTVisitor<Void> {
indent();
}
}
- nodes.get(i).accept(this);
+ ASTNode node = nodes.get(i);
+ if (node instanceof Statement) {
+ printLeadingComments((Statement) node);
+ }
+ node.accept(this);
}
// suffix
writer.print(suffix);

Powered by Google App Engine
This is Rietveld 408576698