Chromium Code Reviews| 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 aff38861d9e0a19e2c6cb742e5585d233ea57f2f..15abf4c6ae4867902c1c21c51e6d0a2d2f6d3ab4 100644 |
| --- a/pkg/analysis_server/tool/spec/codegen_tools.dart |
| +++ b/pkg/analysis_server/tool/spec/codegen_tools.dart |
| @@ -83,14 +83,16 @@ class CodeGenerator { |
| /** |
| * Execute [callback], using [additionalIndent] to indent any code it outputs. |
| */ |
| - void indentBy(String additionalIndent, void callback()) => indentSpecial(additionalIndent, additionalIndent, callback); |
| + void indentBy(String additionalIndent, void callback()) => |
| + indentSpecial(additionalIndent, additionalIndent, callback); |
| /** |
| * Execute [callback], using [additionalIndent] to indent any code it outputs. |
| * The first line of output is indented by [firstAdditionalIndent] instead of |
| * [additionalIndent]. |
| */ |
| - void indentSpecial(String firstAdditionalIndent, String additionalIndent, void callback()) { |
| + void indentSpecial(String firstAdditionalIndent, String additionalIndent, void |
| + callback()) { |
| String oldNextIndent = _state.nextIndent; |
| String oldIndent = _state.indent; |
| try { |
| @@ -114,7 +116,8 @@ class CodeGenerator { |
| * If [javadocStyle] is true, then the output is compatable with Javadoc, |
| * which understands certain HTML constructs. |
| */ |
| - void docComment(List<dom.Node> docs, {int width: 79, bool javadocStyle: false}) { |
| + void docComment(List<dom.Node> docs, {int width: 79, bool javadocStyle: |
| + false}) { |
| writeln('/**'); |
| indentBy(' * ', () { |
| write(nodesToText(docs, width - _state.indent.length, javadocStyle)); |
| @@ -299,10 +302,13 @@ class _HtmlCodeGeneratorState { |
| } |
| /** |
| - * Type of functions used to compute the contents of generated files. |
| + * Type of functions used to compute the contents of a generated file. |
| */ |
| typedef String FileContentsComputer(); |
| +/** |
| + * Type of functions used to compute the contents of a set of generated files. |
| + */ |
| typedef Map<String, FileContentsComputer> DirectoryContentsComputer(); |
| abstract class GeneratedContent { |
| @@ -362,21 +368,36 @@ class GeneratedFile extends GeneratedContent { |
| } |
| } |
| +/** |
| + * Class representing a single output directory (either generated code or |
| + * generated HTML). No other content should exisit in the directory. |
| + */ |
| class GeneratedDirectory extends GeneratedContent { |
| + /** |
| + * The path to the directory that will have the generated content. |
| + */ |
| final String outputDirPath; |
| + |
| + /** |
| + * Callback function which computes the directory contents. |
| + */ |
| final DirectoryContentsComputer directoryContentsComputer; |
| + |
| GeneratedDirectory(this.outputDirPath, this.directoryContentsComputer); |
| /** |
| * Get a Directory object representing the output directory. |
| */ |
| - Directory get outputFile => new Directory(joinAll(posix.split(outputDirPath))); |
| + Directory get outputFile => |
| + new Directory(joinAll(posix.split(outputDirPath))); |
| + /** |
| + * Check whether the directory has the correct contents, and return true if it |
| + * does. |
| + */ |
| @override |
| bool check() { |
| - // TODO (jwren) the lists of files in the directories need to be compared to |
| - // ensure no unexpected files have been added |
| Map<String, FileContentsComputer> map = directoryContentsComputer(); |
| map.forEach((String file, FileContentsComputer fileContentsComputer) { |
| String expectedContents = fileContentsComputer(); |
| @@ -392,12 +413,22 @@ class GeneratedDirectory extends GeneratedContent { |
| return false; |
| } |
| }); |
| - return true; |
| + return outputFile.listSync().length == map.length; |
| } |
| + /** |
| + * Replace the directory with the correct contents. [spec] is the "tool/spec" |
| + * directory. If [spec] is unspecified, it is assumed to be the directory |
| + * containing Platform.executable. |
| + */ |
| @override |
| void generate() { |
| - // TODO (jwren) Delete contents in the directory first. |
| + // delete the contents of the directory (and the directory itself) |
| + outputFile.deleteSync(recursive: true); |
|
Paul Berry
2014/08/14 12:44:05
Put a try/catch around this line as well, so that
jwren
2014/08/14 18:12:29
Done.
|
| + // re-create the empty directory |
| + outputFile.createSync(recursive: true); |
| + |
| + // generate all of the files in the directory |
| Map<String, FileContentsComputer> map = directoryContentsComputer(); |
| map.forEach((String file, FileContentsComputer fileContentsComputer) { |
| File outputFile = new File(joinAll(posix.split(outputDirPath + file))); |