| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Code generation for the file "integration_test_methods.dart". | 6 * Code generation for the file "integration_test_methods.dart". |
| 7 */ | 7 */ |
| 8 library codegenInttestMethods; | |
| 9 | |
| 10 import 'dart:convert'; | 8 import 'dart:convert'; |
| 11 | 9 |
| 12 import 'package:analyzer/src/codegen/tools.dart'; | 10 import 'package:analyzer/src/codegen/tools.dart'; |
| 13 import 'package:front_end/src/codegen/tools.dart'; | 11 import 'package:front_end/src/codegen/tools.dart'; |
| 12 import 'package:path/path.dart' as path; |
| 14 | 13 |
| 15 import 'api.dart'; | 14 import 'api.dart'; |
| 16 import 'codegen_dart.dart'; | 15 import 'codegen_dart.dart'; |
| 17 import 'from_html.dart'; | 16 import 'from_html.dart'; |
| 18 import 'to_html.dart'; | 17 import 'to_html.dart'; |
| 19 | 18 |
| 20 final GeneratedFile target = new GeneratedFile( | 19 final GeneratedFile target = new GeneratedFile( |
| 21 'test/integration/integration_test_methods.dart', (String pkgPath) { | 20 'test/integration/support/integration_test_methods.dart', (String pkgPath) { |
| 22 CodegenInttestMethodsVisitor visitor = | 21 CodegenInttestMethodsVisitor visitor = new CodegenInttestMethodsVisitor( |
| 23 new CodegenInttestMethodsVisitor(readApi(pkgPath)); | 22 path.basename(pkgPath), readApi(pkgPath)); |
| 24 return visitor.collectCode(visitor.visitApi); | 23 return visitor.collectCode(visitor.visitApi); |
| 25 }); | 24 }); |
| 26 | 25 |
| 27 /** | 26 /** |
| 28 * Visitor that generates the code for integration_test_methods.dart | 27 * Visitor that generates the code for integration_test_methods.dart |
| 29 */ | 28 */ |
| 30 class CodegenInttestMethodsVisitor extends DartCodegenVisitor | 29 class CodegenInttestMethodsVisitor extends DartCodegenVisitor |
| 31 with CodeGenerator { | 30 with CodeGenerator { |
| 32 /** | 31 /** |
| 32 * The name of the package into which code is being generated. |
| 33 */ |
| 34 final String packageName; |
| 35 |
| 36 /** |
| 33 * Visitor used to produce doc comments. | 37 * Visitor used to produce doc comments. |
| 34 */ | 38 */ |
| 35 final ToHtmlVisitor toHtmlVisitor; | 39 final ToHtmlVisitor toHtmlVisitor; |
| 36 | 40 |
| 37 /** | 41 /** |
| 38 * Code snippets concatenated to initialize all of the class fields. | 42 * Code snippets concatenated to initialize all of the class fields. |
| 39 */ | 43 */ |
| 40 List<String> fieldInitializationCode = <String>[]; | 44 List<String> fieldInitializationCode = <String>[]; |
| 41 | 45 |
| 42 /** | 46 /** |
| 43 * Code snippets concatenated to produce the contents of the switch statement | 47 * Code snippets concatenated to produce the contents of the switch statement |
| 44 * for dispatching notifications. | 48 * for dispatching notifications. |
| 45 */ | 49 */ |
| 46 List<String> notificationSwitchContents = <String>[]; | 50 List<String> notificationSwitchContents = <String>[]; |
| 47 | 51 |
| 48 CodegenInttestMethodsVisitor(Api api) | 52 CodegenInttestMethodsVisitor(this.packageName, Api api) |
| 49 : toHtmlVisitor = new ToHtmlVisitor(api), | 53 : toHtmlVisitor = new ToHtmlVisitor(api), |
| 50 super(api) { | 54 super(api) { |
| 51 codeGeneratorSettings.commentLineLength = 79; | 55 codeGeneratorSettings.commentLineLength = 79; |
| 52 codeGeneratorSettings.languageName = 'dart'; | 56 codeGeneratorSettings.languageName = 'dart'; |
| 53 } | 57 } |
| 54 | 58 |
| 55 /** | 59 /** |
| 56 * Generate a function argument for the given parameter field. | 60 * Generate a function argument for the given parameter field. |
| 57 */ | 61 */ |
| 58 String formatArgument(TypeObjectField field) => | 62 String formatArgument(TypeObjectField field) => |
| (...skipping 27 matching lines...) Expand all Loading... |
| 86 } | 90 } |
| 87 } else if (type is TypeUnion) { | 91 } else if (type is TypeUnion) { |
| 88 return 'Object'; | 92 return 'Object'; |
| 89 } else { | 93 } else { |
| 90 throw new Exception('Unexpected kind of TypeDecl'); | 94 throw new Exception('Unexpected kind of TypeDecl'); |
| 91 } | 95 } |
| 92 } | 96 } |
| 93 | 97 |
| 94 @override | 98 @override |
| 95 visitApi() { | 99 visitApi() { |
| 96 outputHeader(); | 100 outputHeader(year: '2017'); |
| 97 writeln(); | 101 writeln(); |
| 98 writeln('/**'); | 102 writeln('/**'); |
| 99 writeln(' * Convenience methods for running integration tests'); | 103 writeln(' * Convenience methods for running integration tests'); |
| 100 writeln(' */'); | 104 writeln(' */'); |
| 101 writeln('library test.integration.methods;'); | |
| 102 writeln(); | |
| 103 writeln("import 'dart:async';"); | 105 writeln("import 'dart:async';"); |
| 104 writeln(); | 106 writeln(); |
| 105 writeln("import 'package:analysis_server/plugin/protocol/protocol.dart';"); | 107 writeln("import 'package:$packageName/protocol/protocol_generated.dart';"); |
| 106 writeln( | 108 writeln( |
| 107 "import 'package:analysis_server/src/protocol/protocol_internal.dart';")
; | 109 "import 'package:$packageName/src/protocol/protocol_internal.dart';"); |
| 108 writeln("import 'package:test/test.dart';"); | 110 writeln("import 'package:test/test.dart';"); |
| 109 writeln(); | 111 writeln(); |
| 110 writeln("import 'integration_tests.dart';"); | 112 writeln("import 'integration_tests.dart';"); |
| 111 writeln("import 'protocol_matchers.dart';"); | 113 writeln("import 'protocol_matchers.dart';"); |
| 112 writeln(); | 114 writeln(); |
| 113 writeln(); | |
| 114 writeln('/**'); | 115 writeln('/**'); |
| 115 writeln(' * Convenience methods for running integration tests'); | 116 writeln(' * Convenience methods for running integration tests'); |
| 116 writeln(' */'); | 117 writeln(' */'); |
| 117 writeln('abstract class IntegrationTestMixin {'); | 118 writeln('abstract class IntegrationTestMixin {'); |
| 118 indent(() { | 119 indent(() { |
| 119 writeln('Server get server;'); | 120 writeln('Server get server;'); |
| 120 super.visitApi(); | 121 super.visitApi(); |
| 121 writeln(); | 122 writeln(); |
| 122 docComment(toHtmlVisitor.collectHtml(() { | 123 docComment(toHtmlVisitor.collectHtml(() { |
| 123 toHtmlVisitor.writeln('Initialize the fields in InttestMixin, and'); | 124 toHtmlVisitor.writeln('Initialize the fields in InttestMixin, and'); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 writeln('ResponseDecoder decoder = new ResponseDecoder($kind);'); | 260 writeln('ResponseDecoder decoder = new ResponseDecoder($kind);'); |
| 260 writeln("return new $resultClass.fromJson(decoder, 'result', result);"); | 261 writeln("return new $resultClass.fromJson(decoder, 'result', result);"); |
| 261 } else { | 262 } else { |
| 262 writeln('outOfTestExpect(result, isNull);'); | 263 writeln('outOfTestExpect(result, isNull);'); |
| 263 writeln('return null;'); | 264 writeln('return null;'); |
| 264 } | 265 } |
| 265 }); | 266 }); |
| 266 writeln('}'); | 267 writeln('}'); |
| 267 } | 268 } |
| 268 } | 269 } |
| OLD | NEW |