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

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

Issue 259773005: New analyzer snapshot. Sorted unit members. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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/engine/MainEngine.java
diff --git a/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/engine/MainEngine.java b/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/engine/MainEngine.java
index d71a08bbe300fbf62e0e5fee466fcfe390c80489..8bb1473afe8d61796858d2c137184e9a7e1f0055 100644
--- a/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/engine/MainEngine.java
+++ b/editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/engine/MainEngine.java
@@ -29,6 +29,7 @@ import com.google.dart.engine.ast.CompilationUnit;
import com.google.dart.engine.ast.CompilationUnitMember;
import com.google.dart.engine.ast.Expression;
import com.google.dart.engine.ast.FieldDeclaration;
+import com.google.dart.engine.ast.FunctionDeclaration;
import com.google.dart.engine.ast.NodeList;
import com.google.dart.engine.ast.ParenthesizedExpression;
import com.google.dart.engine.ast.Statement;
@@ -1418,10 +1419,11 @@ public class MainEngine {
/**
* @return the formatted Dart source dump of the given {@link AstNode}.
*/
- private static String getFormattedSource(AstNode node) {
+ private static String getFormattedSource(CompilationUnit unit) {
PrintStringWriter writer = new PrintStringWriter();
writer.append(HEADER);
- node.accept(new ToFormattedSourceVisitor(writer));
+ sortUnitMembersByName(unit);
+ unit.accept(new ToFormattedSourceVisitor(writer));
String source = writer.toString();
source = removeTrailingWhitespaces(source);
return source;
@@ -1507,4 +1509,25 @@ public class MainEngine {
}
return matcher.replaceFirst(replacement);
}
+
+ private static void sortUnitMembersByName(CompilationUnit unit) {
+ Collections.sort(unit.getDeclarations(), new Comparator<CompilationUnitMember>() {
+ @Override
+ public int compare(CompilationUnitMember o1, CompilationUnitMember o2) {
+ String name1 = getName(o1);
+ String name2 = getName(o2);
+ return name1.compareTo(name2);
+ }
+
+ private String getName(CompilationUnitMember member) {
+ if (member instanceof ClassDeclaration) {
+ return ((ClassDeclaration) member).getName().getName();
+ }
+ if (member instanceof FunctionDeclaration) {
+ return ((FunctionDeclaration) member).getName().getName();
+ }
+ throw new UnsupportedOperationException(member.toSource());
+ }
+ });
+ }
}

Powered by Google App Engine
This is Rietveld 408576698