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

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

Issue 128443003: Analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes for review comments. 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/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 267a7f246db5627062a78c21ae3e385c70b3fc29..aa298419ef9b5186905cc5fbfed8c2da223698f8 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
@@ -20,8 +20,10 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import com.google.dart.engine.ast.ASTNode;
+import com.google.dart.engine.ast.ClassDeclaration;
import com.google.dart.engine.ast.CompilationUnit;
import com.google.dart.engine.ast.CompilationUnitMember;
+import com.google.dart.engine.ast.NodeList;
import com.google.dart.engine.ast.Statement;
import com.google.dart.engine.utilities.io.PrintStringWriter;
import com.google.dart.java2dart.Context;
@@ -253,10 +255,35 @@ public class MainEngine {
}
{
CompilationUnit library = buildUtilitiesGeneralLibrary();
- Files.write(
- getFormattedSource(library),
- new File(targetFolder + "/utilities_general.dart"),
- Charsets.UTF_8);
+ removeClass(library, "TimeCounter");
+ removeClass(library, "TimeCounter_TimeCounterHandle");
+ String source = getFormattedSource(library);
+ source += Joiner.on("\n").join(
+ new String[] {
+ "/**",
+ " * Helper for measuring how much time is spent doing some operation.",
+ " */",
+ "class TimeCounter {",
+ " Stopwatch _sw = new Stopwatch();",
+ "",
+ " /**",
+ " * @return the number of milliseconds spent between [start] and [stop].",
+ " */",
+ " int get result => _sw.elapsedMilliseconds;",
+ "",
+ " /**",
+ " * Starts counting time.",
+ " *",
+ " * @return the [TimeCounterHandle] that should be used to stop counting.",
+ " */",
+ " TimeCounter_TimeCounterHandle start() => new TimeCounter_TimeCounterHandle(this);",
+ "}", "", "/**",
+ " * The handle object that should be used to stop and update counter.", " */",
+ "class TimeCounter_TimeCounterHandle {", " final TimeCounter _counter;", "",
+ " TimeCounter_TimeCounterHandle(this._counter) {", " _counter._sw.start();",
+ " }", "", " /**", " * Stops counting time and updates counter.", " */",
+ " void stop() {", " _counter._sw.stop();", " }", "}"});
+ Files.write(source, new File(targetFolder + "/utilities_general.dart"), Charsets.UTF_8);
}
{
CompilationUnit library = buildSourceLibrary();
@@ -1112,7 +1139,6 @@ public class MainEngine {
private static CompilationUnit buildUtilitiesGeneralLibrary() throws Exception {
CompilationUnit unit = new CompilationUnit(null, null, null, null, null);
unit.getDirectives().add(libraryDirective("engine", "utilities", "general"));
- unit.getDirectives().add(importDirective("java_core.dart", null));
for (Entry<File, List<CompilationUnitMember>> entry : context.getFileToMembers().entrySet()) {
File file = entry.getKey();
if (isEnginePath(file, "utilities/general/")) {
@@ -1157,6 +1183,22 @@ public class MainEngine {
}
/**
+ * Removes {@link ClassDeclaration} with the given name.
+ */
+ private static void removeClass(CompilationUnit unit, String name) {
+ NodeList<CompilationUnitMember> declarations = unit.getDeclarations();
+ for (Iterator<CompilationUnitMember> iter = declarations.iterator(); iter.hasNext();) {
+ CompilationUnitMember member = iter.next();
+ if (member instanceof ClassDeclaration) {
+ ClassDeclaration classDeclaration = (ClassDeclaration) member;
+ if (classDeclaration.getName().getName().equals(name)) {
+ iter.remove();
+ }
+ }
+ }
+ }
+
+ /**
* Removes trailing spaces from the given Dart source.
*/
private static String removeTrailingWhitespaces(String source) {

Powered by Google App Engine
This is Rietveld 408576698