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

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

Issue 624403002: Write end-of-block comments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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
« no previous file with comments | « no previous file | editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/util/ToFormattedSourceVisitor.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/SyntaxTranslator.java
diff --git a/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/SyntaxTranslator.java b/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/SyntaxTranslator.java
index 5bfc7e69904bfdadd04bd308dc7d4cfc291ba279..88853f052e9a1246f906b5dc77b05511961182b9 100644
--- a/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/SyntaxTranslator.java
+++ b/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/SyntaxTranslator.java
@@ -2026,7 +2026,44 @@ public class SyntaxTranslator extends org.eclipse.jdt.core.dom.ASTVisitor {
commentLine = fixJdtCommentLine(commentLine);
commentLines.add(commentLine);
}
- result.setProperty(ToFormattedSourceVisitor.COMMENTS_KEY, commentLines);
+ result.setProperty(ToFormattedSourceVisitor.COMMENTS_BEFORE_STATEMENT, commentLines);
+ }
+ }
+ // attach comments at the end of Block
+ if (node instanceof org.eclipse.jdt.core.dom.Block) {
+ org.eclipse.jdt.core.dom.Block block = (org.eclipse.jdt.core.dom.Block) node;
+ int blockEnd = block.getStartPosition() + block.getLength();
+ // prepare the offset after last statement of after Block start
+ int afterOffset;
+ {
+ List<?> statements = block.statements();
+ if (statements.isEmpty()) {
+ afterOffset = block.getStartPosition();
+ } else {
+ int lastIndex = statements.size() - 1;
+ org.eclipse.jdt.core.dom.Statement lastStatement = (org.eclipse.jdt.core.dom.Statement) statements.get(lastIndex);
+ afterOffset = lastStatement.getStartPosition() + lastStatement.getLength();
+ }
+ }
+ // find comments at the end of Block
+ List<String> commentLines = Lists.newArrayList();
+ List<org.eclipse.jdt.core.dom.Comment> allComments = javaUnit.getCommentList();
+ int index = 0;
+ while (index < allComments.size()) {
+ org.eclipse.jdt.core.dom.Comment comment = allComments.get(index++);
+ if (comment.getStartPosition() < afterOffset) {
+ continue;
+ }
+ if (comment.getStartPosition() > blockEnd) {
+ break;
+ }
+ String commentLine = getJavaSource(comment);
+ commentLine = fixJdtCommentLine(commentLine);
+ commentLines.add(commentLine);
+ }
+ // remember comments
+ if (!commentLines.isEmpty()) {
+ result.setProperty(ToFormattedSourceVisitor.COMMENTS_AT_BLOCK_END, commentLines);
}
}
// done
« no previous file with comments | « no previous file | editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/util/ToFormattedSourceVisitor.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698