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

Side by Side Diff: pkg/analysis_server/tool/spec/api.dart

Issue 469673002: Add union types to the analysis server API spec. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 * Data structures representing an API definition, and visitor base classes 6 * Data structures representing an API definition, and visitor base classes
7 * for visiting those data structures. 7 * for visiting those data structures.
8 */ 8 */
9 library api; 9 library api;
10 10
11 import 'dart:collection'; 11 import 'dart:collection';
12 12
13 import 'package:html5lib/dom.dart' as dom; 13 import 'package:html5lib/dom.dart' as dom;
14 14
15 /** 15 /**
16 * Base class for visiting the API definition. 16 * Base class for visiting the API definition.
17 */ 17 */
18 abstract class ApiVisitor<T> { 18 abstract class ApiVisitor<T> {
19 T visitTypeReference(TypeReference typeReference); 19 T visitTypeReference(TypeReference typeReference);
20 T visitTypeUnion(TypeUnion typeUnion);
20 T visitTypeObject(TypeObject typeObject); 21 T visitTypeObject(TypeObject typeObject);
21 T visitTypeList(TypeList typeList); 22 T visitTypeList(TypeList typeList);
22 T visitTypeMap(TypeMap typeMap); 23 T visitTypeMap(TypeMap typeMap);
23 T visitTypeEnum(TypeEnum typeEnum); 24 T visitTypeEnum(TypeEnum typeEnum);
24 25
25 /** 26 /**
26 * Dispatch the given [type] to the visitor. 27 * Dispatch the given [type] to the visitor.
27 */ 28 */
28 T visitTypeDecl(TypeDecl type) => type.accept(this); 29 T visitTypeDecl(TypeDecl type) => type.accept(this);
29 } 30 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 112 }
112 113
113 void visitTypeObjectField(TypeObjectField typeObjectField) { 114 void visitTypeObjectField(TypeObjectField typeObjectField) {
114 visitTypeDecl(typeObjectField.type); 115 visitTypeDecl(typeObjectField.type);
115 } 116 }
116 117
117 @override 118 @override
118 void visitTypeReference(TypeReference typeReference) { 119 void visitTypeReference(TypeReference typeReference) {
119 } 120 }
120 121
122 @override
123 void visitTypeUnion(TypeUnion typeUnion) {
124 typeUnion.choices.forEach(visitTypeDecl);
125 }
126
121 /** 127 /**
122 * If [type] is a [TypeReference] that is defined in the API, follow the 128 * If [type] is a [TypeReference] that is defined in the API, follow the
123 * chain until a non-[TypeReference] is found, if possible. 129 * chain until a non-[TypeReference] is found, if possible.
124 * 130 *
125 * If it is not possible (because the chain ends with a [TypeReference] that 131 * If it is not possible (because the chain ends with a [TypeReference] that
126 * is not defined in the API), then that final [TypeReference] is returned. 132 * is not defined in the API), then that final [TypeReference] is returned.
127 */ 133 */
128 TypeDecl resolveTypeReferenceChain(TypeDecl type) { 134 TypeDecl resolveTypeReferenceChain(TypeDecl type) {
129 while (type is TypeReference && api.types.containsKey(type.typeName)) { 135 while (type is TypeReference && api.types.containsKey(type.typeName)) {
130 type = api.types[(type as TypeReference).typeName].type; 136 type = api.types[(type as TypeReference).typeName].type;
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 TypeReference(this.typeName, dom.Element html) : super(html) { 365 TypeReference(this.typeName, dom.Element html) : super(html) {
360 if (typeName.isEmpty) { 366 if (typeName.isEmpty) {
361 throw new Exception('Empty type name'); 367 throw new Exception('Empty type name');
362 } 368 }
363 } 369 }
364 370
365 accept(ApiVisitor visitor) => visitor.visitTypeReference(this); 371 accept(ApiVisitor visitor) => visitor.visitTypeReference(this);
366 } 372 }
367 373
368 /** 374 /**
375 * Type which represents a union among multiple choices.
376 */
377 class TypeUnion extends TypeDecl {
378 final List<TypeDecl> choices;
379
380 TypeUnion(this.choices, dom.Element html) : super(html);
381
382 accept(ApiVisitor visitor) => visitor.visitTypeUnion(this);
383 }
384
385 /**
369 * Type of a JSON object with specified fields, some of which may be optional. 386 * Type of a JSON object with specified fields, some of which may be optional.
370 */ 387 */
371 class TypeObject extends TypeDecl { 388 class TypeObject extends TypeDecl {
372 final List<TypeObjectField> fields; 389 final List<TypeObjectField> fields;
373 390
374 TypeObject(this.fields, dom.Element html) : super(html); 391 TypeObject(this.fields, dom.Element html) : super(html);
375 392
376 accept(ApiVisitor visitor) => visitor.visitTypeObject(this); 393 accept(ApiVisitor visitor) => visitor.visitTypeObject(this);
377 } 394 }
378 395
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 } 455 }
439 456
440 /** 457 /**
441 * Description of a single allowed value for an enum. 458 * Description of a single allowed value for an enum.
442 */ 459 */
443 class TypeEnumValue extends ApiNode { 460 class TypeEnumValue extends ApiNode {
444 final String value; 461 final String value;
445 462
446 TypeEnumValue(this.value, dom.Element html) : super(html); 463 TypeEnumValue(this.value, dom.Element html) : super(html);
447 } 464 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698