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

Unified Diff: pkg/analysis_server/tool/spec/codegen_tools.dart

Issue 469543002: Add a test to verify that analysis server code generation is up to date. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove unused imports Created 6 years, 4 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: pkg/analysis_server/tool/spec/codegen_tools.dart
diff --git a/pkg/analysis_server/tool/spec/codegen_tools.dart b/pkg/analysis_server/tool/spec/codegen_tools.dart
index 53db1dbeedd8a0c3dc758a0f40708768634920a2..3b4d64d6f07f9fd9257246c4296f55ae02db32e7 100644
--- a/pkg/analysis_server/tool/spec/codegen_tools.dart
+++ b/pkg/analysis_server/tool/spec/codegen_tools.dart
@@ -7,7 +7,10 @@
*/
library codegen.tools;
+import 'dart:io';
+
import 'package:html5lib/dom.dart' as dom;
+import 'package:path/path.dart';
import 'text_formatter.dart';
import 'html_tools.dart';
@@ -290,3 +293,58 @@ class _HtmlCodeGeneratorState {
}
}
}
+
+/**
+ * Type of functions used to compute the contents of generated files.
+ */
+typedef String ContentsComputer();
+
+/**
+ * Class representing a single output file (either generated code or generated
+ * HTML).
+ */
+class GeneratedFile {
+ /**
+ * The output file to which generated output should be written, relative to
+ * the "tool/spec" directory. This filename uses the posix path separator
+ * ('/') regardless of the OS.
+ */
+ final String outputPath;
+
+ /**
+ * Callback function which computes the file.
+ */
+ final ContentsComputer computeContents;
+
+ GeneratedFile(this.outputPath, this.computeContents);
+
+ /**
+ * Get a File object representing the output file.
+ */
+ File get outputFile => new File(joinAll(posix.split(outputPath)));
+
+ /**
+ * Check whether the file has the correct contents, and return true if it
+ * does.
+ */
+ bool check() {
+ String expectedContents = computeContents();
+ try {
+ return expectedContents == outputFile.readAsStringSync();
+ } catch(e) {
+ // There was a problem reading the file (most likely because it didn't
+ // exist). Treat that the same as if the file doesn't have the expected
+ // contents.
+ return false;
+ }
+ }
+
+ /**
+ * Replace the file with the correct contents. [spec] is the "tool/spec"
+ * directory. If [spec] is unspecified, it is assumed to be the directory
+ * containing Platform.executable.
+ */
+ void generate() {
+ outputFile.writeAsStringSync(computeContents());
+ }
+}
« no previous file with comments | « pkg/analysis_server/tool/spec/codegen_matchers.dart ('k') | pkg/analysis_server/tool/spec/generate_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698