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

Side by Side Diff: pkg/analyzer_plugin/tool/spec/codegen_dart_protocol.dart

Issue 2844273003: Unify the server and plugin versions of the generators (Closed)
Patch Set: add missed files Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2017, 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 import 'dart:convert'; 5 import 'dart:convert';
6 6
7 import 'package:analyzer/src/codegen/tools.dart'; 7 import 'package:analyzer/src/codegen/tools.dart';
8 import 'package:front_end/src/codegen/tools.dart'; 8 import 'package:front_end/src/codegen/tools.dart';
9 import 'package:html/dom.dart' as dom; 9 import 'package:html/dom.dart' as dom;
10 import 'package:path/path.dart' as path;
10 11
11 import 'api.dart'; 12 import 'api.dart';
12 import 'codegen_dart.dart'; 13 import 'codegen_dart.dart';
13 import 'from_html.dart'; 14 import 'from_html.dart';
14 import 'implied_types.dart'; 15 import 'implied_types.dart';
15 import 'to_html.dart'; 16 import 'to_html.dart';
16 17
17 /** 18 /**
18 * Special flags that need to be inserted into the declaration of the Element 19 * Special flags that need to be inserted into the declaration of the Element
19 * class. 20 * class.
20 */ 21 */
21 const Map<String, String> specialElementFlags = const { 22 const Map<String, String> specialElementFlags = const {
22 'abstract': '0x01', 23 'abstract': '0x01',
23 'const': '0x02', 24 'const': '0x02',
24 'final': '0x04', 25 'final': '0x04',
25 'static': '0x08', 26 'static': '0x08',
26 'private': '0x10', 27 'private': '0x10',
27 'deprecated': '0x20' 28 'deprecated': '0x20'
28 }; 29 };
29 30
30 final GeneratedFile target = 31 final GeneratedFile target =
31 new GeneratedFile('lib/protocol/protocol_generated.dart', (String pkgPath) { 32 new GeneratedFile('lib/protocol/protocol_generated.dart', (String pkgPath) {
32 CodegenProtocolVisitor visitor = new CodegenProtocolVisitor(readApi(pkgPath)); 33 CodegenProtocolVisitor visitor =
34 new CodegenProtocolVisitor(path.basename(pkgPath), readApi(pkgPath));
33 return visitor.collectCode(visitor.visitApi); 35 return visitor.collectCode(visitor.visitApi);
34 }); 36 });
35 37
36 /** 38 /**
37 * Callback type used to represent arbitrary code generation. 39 * Callback type used to represent arbitrary code generation.
38 */ 40 */
39 typedef void CodegenCallback(); 41 typedef void CodegenCallback();
40 42
41 typedef String FromJsonSnippetCallback(String jsonPath, String json); 43 typedef String FromJsonSnippetCallback(String jsonPath, String json);
42 44
(...skipping 16 matching lines...) Expand all
59 }; 61 };
60 62
61 /** 63 /**
62 * The disclaimer added to the documentation comment for each of the classes 64 * The disclaimer added to the documentation comment for each of the classes
63 * that are generated. 65 * that are generated.
64 */ 66 */
65 static const String disclaimer = 67 static const String disclaimer =
66 'Clients may not extend, implement or mix-in this class.'; 68 'Clients may not extend, implement or mix-in this class.';
67 69
68 /** 70 /**
71 * The name of the package into which code is being generated.
72 */
73 final String packageName;
74
75 /**
69 * Visitor used to produce doc comments. 76 * Visitor used to produce doc comments.
70 */ 77 */
71 final ToHtmlVisitor toHtmlVisitor; 78 final ToHtmlVisitor toHtmlVisitor;
72 79
73 /** 80 /**
74 * Types implied by the API. This includes types explicitly named in the 81 * Types implied by the API. This includes types explicitly named in the
75 * API as well as those implied by the definitions of requests, responses, 82 * API as well as those implied by the definitions of requests, responses,
76 * notifications, etc. 83 * notifications, etc.
77 */ 84 */
78 final Map<String, ImpliedType> impliedTypes; 85 final Map<String, ImpliedType> impliedTypes;
79 86
80 CodegenProtocolVisitor(Api api) 87 CodegenProtocolVisitor(this.packageName, Api api)
81 : toHtmlVisitor = new ToHtmlVisitor(api), 88 : toHtmlVisitor = new ToHtmlVisitor(api),
82 impliedTypes = computeImpliedTypes(api), 89 impliedTypes = computeImpliedTypes(api),
83 super(api) { 90 super(api) {
84 codeGeneratorSettings.commentLineLength = 79; 91 codeGeneratorSettings.commentLineLength = 79;
85 codeGeneratorSettings.languageName = 'dart'; 92 codeGeneratorSettings.languageName = 'dart';
86 } 93 }
87 94
88 /** 95 /**
89 * Compute the code necessary to compare two objects for equality. 96 * Compute the code necessary to compare two objects for equality.
90 */ 97 */
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 } 1127 }
1121 } 1128 }
1122 1129
1123 @override 1130 @override
1124 visitApi() { 1131 visitApi() {
1125 outputHeader(year: '2017'); 1132 outputHeader(year: '2017');
1126 writeln(); 1133 writeln();
1127 writeln("import 'dart:convert' hide JsonDecoder;"); 1134 writeln("import 'dart:convert' hide JsonDecoder;");
1128 writeln(); 1135 writeln();
1129 writeln("import 'package:analyzer/src/generated/utilities_general.dart';"); 1136 writeln("import 'package:analyzer/src/generated/utilities_general.dart';");
1130 writeln("import 'package:analyzer_plugin/protocol/protocol.dart';"); 1137 writeln("import 'package:$packageName/protocol/protocol.dart';");
1131 writeln( 1138 writeln(
1132 "import 'package:analyzer_plugin/src/protocol/protocol_internal.dart';") ; 1139 "import 'package:$packageName/src/protocol/protocol_internal.dart';");
1133 emitClasses(); 1140 emitClasses();
1134 } 1141 }
1135 } 1142 }
1136 1143
1137 /** 1144 /**
1138 * Container for code that can be used to translate a data type from JSON. 1145 * Container for code that can be used to translate a data type from JSON.
1139 */ 1146 */
1140 abstract class FromJsonCode { 1147 abstract class FromJsonCode {
1141 /** 1148 /**
1142 * Get the translation code in the form of a closure. 1149 * Get the translation code in the form of a closure.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 1281
1275 @override 1282 @override
1276 String get asClosure => '($type value) => ${callback('value')}'; 1283 String get asClosure => '($type value) => ${callback('value')}';
1277 1284
1278 @override 1285 @override
1279 bool get isIdentity => false; 1286 bool get isIdentity => false;
1280 1287
1281 @override 1288 @override
1282 String asSnippet(String value) => callback(value); 1289 String asSnippet(String value) => callback(value);
1283 } 1290 }
OLDNEW
« no previous file with comments | « pkg/analyzer_plugin/tool/spec/codegen_dart.dart ('k') | pkg/analyzer_plugin/tool/spec/codegen_inttest_methods.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698