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

Side by Side Diff: pkg/analyzer/lib/src/summary/summarize_ast.dart

Issue 1672413002: Add summary support for annotations. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 library serialization.summarize_ast; 5 library serialization.summarize_ast;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/visitor.dart'; 8 import 'package:analyzer/dart/ast/visitor.dart';
9 import 'package:analyzer/src/generated/scanner.dart'; 9 import 'package:analyzer/src/generated/scanner.dart';
10 import 'package:analyzer/src/generated/utilities_dart.dart'; 10 import 'package:analyzer/src/generated/utilities_dart.dart';
(...skipping 12 matching lines...) Expand all
23 /** 23 /**
24 * Instances of this class keep track of intermediate state during 24 * Instances of this class keep track of intermediate state during
25 * serialization of a single constant [Expression]. 25 * serialization of a single constant [Expression].
26 */ 26 */
27 class _ConstExprSerializer extends AbstractConstExprSerializer { 27 class _ConstExprSerializer extends AbstractConstExprSerializer {
28 final _SummarizeAstVisitor visitor; 28 final _SummarizeAstVisitor visitor;
29 29
30 _ConstExprSerializer(this.visitor); 30 _ConstExprSerializer(this.visitor);
31 31
32 @override 32 @override
33 EntityRefBuilder serializeConstructorName(ConstructorName constructor) { 33 void serializeAnnotation(Annotation annotation) {
34 EntityRefBuilder typeBuilder = serializeType(constructor.type); 34 if (annotation.arguments == null) {
35 if (constructor.name == null) { 35 assert(annotation.constructorName == null);
36 serialize(annotation.name);
37 } else {
38 Identifier name = annotation.name;
39 EntityRefBuilder constructor;
40 if (name is PrefixedIdentifier && annotation.constructorName == null) {
41 constructor = serializeConstructorName(
42 new TypeName(name.prefix, null), name.identifier);
43 } else {
44 constructor = serializeConstructorName(
45 new TypeName(annotation.name, null), annotation.constructorName);
46 }
47 serializeInstanceCreation(constructor, annotation.arguments);
48 }
49 }
50
51 @override
52 EntityRefBuilder serializeConstructorName(
53 TypeName type, SimpleIdentifier name) {
54 EntityRefBuilder typeBuilder = serializeType(type);
55 if (name == null) {
36 return typeBuilder; 56 return typeBuilder;
37 } else { 57 } else {
38 String name = constructor.name.name; 58 int nameRef =
39 int nameRef = visitor.serializeReference(typeBuilder.reference, name); 59 visitor.serializeReference(typeBuilder.reference, name.name);
40 return new EntityRefBuilder( 60 return new EntityRefBuilder(
41 reference: nameRef, typeArguments: typeBuilder.typeArguments); 61 reference: nameRef, typeArguments: typeBuilder.typeArguments);
42 } 62 }
43 } 63 }
44 64
45 EntityRefBuilder serializeIdentifier(Identifier identifier) { 65 EntityRefBuilder serializeIdentifier(Identifier identifier) {
46 EntityRefBuilder b = new EntityRefBuilder(); 66 EntityRefBuilder b = new EntityRefBuilder();
47 if (identifier is SimpleIdentifier) { 67 if (identifier is SimpleIdentifier) {
48 b.reference = visitor.serializeReference(null, identifier.name); 68 b.reference = visitor.serializeReference(null, identifier.name);
49 } else if (identifier is PrefixedIdentifier) { 69 } else if (identifier is PrefixedIdentifier) {
50 int prefix = visitor.serializeReference(null, identifier.prefix.name); 70 int prefix = visitor.serializeReference(null, identifier.prefix.name);
51 b.reference = 71 b.reference =
52 visitor.serializeReference(prefix, identifier.identifier.name); 72 visitor.serializeReference(prefix, identifier.identifier.name);
53 } else { 73 } else {
54 throw new StateError( 74 throw new StateError(
55 'Unexpected identifier type: ${identifier.runtimeType}'); 75 'Unexpected identifier type: ${identifier.runtimeType}');
56 } 76 }
57 return b; 77 return b;
58 } 78 }
59 79
60 @override 80 @override
61 EntityRefBuilder serializePropertyAccess(PropertyAccess access) { 81 EntityRefBuilder serializePropertyAccess(PropertyAccess access) {
62 Expression target = access.target; 82 Expression target = access.target;
63 if (target is Identifier) { 83 if (target is Identifier) {
64 EntityRefBuilder targetRef = serializeIdentifier(target); 84 EntityRefBuilder targetRef = serializeIdentifier(target);
65 return new EntityRefBuilder(reference: visitor.serializeReference( 85 return new EntityRefBuilder(
66 targetRef.reference, access.propertyName.name)); 86 reference: visitor.serializeReference(
87 targetRef.reference, access.propertyName.name));
67 } else { 88 } else {
68 // TODO(scheglov) should we handle other targets in malformed constants? 89 // TODO(scheglov) should we handle other targets in malformed constants?
69 throw new StateError('Unexpected target type: ${target.runtimeType}'); 90 throw new StateError('Unexpected target type: ${target.runtimeType}');
70 } 91 }
71 } 92 }
72 93
73 @override 94 @override
74 EntityRefBuilder serializeType(TypeName node) { 95 EntityRefBuilder serializeType(TypeName node) {
75 return visitor.serializeTypeName(node); 96 return visitor.serializeTypeName(node);
76 } 97 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 */ 256 */
236 int libraryNameLength; 257 int libraryNameLength;
237 258
238 /** 259 /**
239 * If the library has a library directive, the documentation comment for it 260 * If the library has a library directive, the documentation comment for it
240 * (if any). Otherwise `null`. 261 * (if any). Otherwise `null`.
241 */ 262 */
242 UnlinkedDocumentationCommentBuilder libraryDocumentationComment; 263 UnlinkedDocumentationCommentBuilder libraryDocumentationComment;
243 264
244 /** 265 /**
266 * If the library has a library directive, the annotations for it (if any).
267 * Otherwise `null`.
268 */
269 List<UnlinkedConst> libraryAnnotations = const <UnlinkedConstBuilder>[];
270
271 /**
245 * The number of slot ids which have been assigned to this compilation unit. 272 * The number of slot ids which have been assigned to this compilation unit.
246 */ 273 */
247 int numSlots = 0; 274 int numSlots = 0;
248 275
249 /** 276 /**
250 * A flag indicating whether a variable declaration is in the context of a 277 * A flag indicating whether a variable declaration is in the context of a
251 * field declaration. 278 * field declaration.
252 */ 279 */
253 bool inFieldContext = false; 280 bool inFieldContext = false;
254 281
(...skipping 24 matching lines...) Expand all
279 // We don't have to worry about the one with a trailing `=` because 306 // We don't have to worry about the one with a trailing `=` because
280 // the only thing we look up is type names. 307 // the only thing we look up is type names.
281 scope[field.name.name] = new _OtherScopedEntity(); 308 scope[field.name.name] = new _OtherScopedEntity();
282 } 309 }
283 } 310 }
284 } 311 }
285 return scope; 312 return scope;
286 } 313 }
287 314
288 /** 315 /**
316 * Serialize the given list of [annotations]. If there are no annotations,
317 * the empty list is returned.
318 */
319 List<UnlinkedConstBuilder> serializeAnnotations(
320 NodeList<Annotation> annotations) {
321 if (annotations.isEmpty) {
322 return const <UnlinkedConstBuilder>[];
323 }
324 return annotations.map((Annotation a) {
325 _ConstExprSerializer serializer = new _ConstExprSerializer(this);
326 serializer.serializeAnnotation(a);
327 return serializer.toBuilder();
328 }).toList();
329 }
330
331 /**
289 * Serialize a [ClassDeclaration] or [ClassTypeAlias] into an [UnlinkedClass] 332 * Serialize a [ClassDeclaration] or [ClassTypeAlias] into an [UnlinkedClass]
290 * and store the result in [classes]. 333 * and store the result in [classes].
291 */ 334 */
292 void serializeClass( 335 void serializeClass(
293 Token abstractKeyword, 336 Token abstractKeyword,
294 String name, 337 String name,
295 int nameOffset, 338 int nameOffset,
296 TypeParameterList typeParameters, 339 TypeParameterList typeParameters,
297 TypeName superclass, 340 TypeName superclass,
298 WithClause withClause, 341 WithClause withClause,
299 ImplementsClause implementsClause, 342 ImplementsClause implementsClause,
300 NodeList<ClassMember> members, 343 NodeList<ClassMember> members,
301 bool isMixinApplication, 344 bool isMixinApplication,
302 Comment documentationComment) { 345 Comment documentationComment,
346 NodeList<Annotation> annotations) {
303 int oldScopesLength = scopes.length; 347 int oldScopesLength = scopes.length;
304 List<UnlinkedExecutableBuilder> oldExecutables = executables; 348 List<UnlinkedExecutableBuilder> oldExecutables = executables;
305 executables = <UnlinkedExecutableBuilder>[]; 349 executables = <UnlinkedExecutableBuilder>[];
306 List<UnlinkedVariableBuilder> oldVariables = variables; 350 List<UnlinkedVariableBuilder> oldVariables = variables;
307 variables = <UnlinkedVariableBuilder>[]; 351 variables = <UnlinkedVariableBuilder>[];
308 _TypeParameterScope typeParameterScope = new _TypeParameterScope(); 352 _TypeParameterScope typeParameterScope = new _TypeParameterScope();
309 scopes.add(typeParameterScope); 353 scopes.add(typeParameterScope);
310 UnlinkedClassBuilder b = new UnlinkedClassBuilder(); 354 UnlinkedClassBuilder b = new UnlinkedClassBuilder();
311 b.name = name; 355 b.name = name;
312 b.nameOffset = nameOffset; 356 b.nameOffset = nameOffset;
(...skipping 14 matching lines...) Expand all
327 scopes.add(buildClassMemberScope(members)); 371 scopes.add(buildClassMemberScope(members));
328 for (ClassMember member in members) { 372 for (ClassMember member in members) {
329 member.accept(this); 373 member.accept(this);
330 } 374 }
331 scopes.removeLast(); 375 scopes.removeLast();
332 } 376 }
333 b.executables = executables; 377 b.executables = executables;
334 b.fields = variables; 378 b.fields = variables;
335 b.isAbstract = abstractKeyword != null; 379 b.isAbstract = abstractKeyword != null;
336 b.documentationComment = serializeDocumentation(documentationComment); 380 b.documentationComment = serializeDocumentation(documentationComment);
381 b.annotations = serializeAnnotations(annotations);
337 classes.add(b); 382 classes.add(b);
338 scopes.removeLast(); 383 scopes.removeLast();
339 assert(scopes.length == oldScopesLength); 384 assert(scopes.length == oldScopesLength);
340 executables = oldExecutables; 385 executables = oldExecutables;
341 variables = oldVariables; 386 variables = oldVariables;
342 } 387 }
343 388
344 /** 389 /**
345 * Serialize a [Combinator] into an [UnlinkedCombinator]. 390 * Serialize a [Combinator] into an [UnlinkedCombinator].
346 */ 391 */
(...skipping 20 matching lines...) Expand all
367 compilationUnit.directives.accept(this); 412 compilationUnit.directives.accept(this);
368 if (!hasCoreBeenImported) { 413 if (!hasCoreBeenImported) {
369 unlinkedImports.add(new UnlinkedImportBuilder(isImplicit: true)); 414 unlinkedImports.add(new UnlinkedImportBuilder(isImplicit: true));
370 } 415 }
371 compilationUnit.declarations.accept(this); 416 compilationUnit.declarations.accept(this);
372 UnlinkedUnitBuilder b = new UnlinkedUnitBuilder(); 417 UnlinkedUnitBuilder b = new UnlinkedUnitBuilder();
373 b.libraryName = libraryName; 418 b.libraryName = libraryName;
374 b.libraryNameOffset = libraryNameOffset; 419 b.libraryNameOffset = libraryNameOffset;
375 b.libraryNameLength = libraryNameLength; 420 b.libraryNameLength = libraryNameLength;
376 b.libraryDocumentationComment = libraryDocumentationComment; 421 b.libraryDocumentationComment = libraryDocumentationComment;
422 b.libraryAnnotations = libraryAnnotations;
377 b.classes = classes; 423 b.classes = classes;
378 b.enums = enums; 424 b.enums = enums;
379 b.executables = executables; 425 b.executables = executables;
380 b.exports = exports; 426 b.exports = exports;
381 b.imports = unlinkedImports; 427 b.imports = unlinkedImports;
382 b.parts = parts; 428 b.parts = parts;
383 b.references = unlinkedReferences; 429 b.references = unlinkedReferences;
384 b.typedefs = typedefs; 430 b.typedefs = typedefs;
385 b.variables = variables; 431 b.variables = variables;
386 b.publicNamespace = computePublicNamespace(compilationUnit); 432 b.publicNamespace = computePublicNamespace(compilationUnit);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 UnlinkedExecutableBuilder serializeExecutable( 467 UnlinkedExecutableBuilder serializeExecutable(
422 SimpleIdentifier name, 468 SimpleIdentifier name,
423 bool isGetter, 469 bool isGetter,
424 bool isSetter, 470 bool isSetter,
425 TypeName returnType, 471 TypeName returnType,
426 FormalParameterList formalParameters, 472 FormalParameterList formalParameters,
427 FunctionBody body, 473 FunctionBody body,
428 bool isTopLevel, 474 bool isTopLevel,
429 bool isDeclaredStatic, 475 bool isDeclaredStatic,
430 Comment documentationComment, 476 Comment documentationComment,
477 NodeList<Annotation> annotations,
431 TypeParameterList typeParameters, 478 TypeParameterList typeParameters,
432 bool isExternal) { 479 bool isExternal) {
433 int oldScopesLength = scopes.length; 480 int oldScopesLength = scopes.length;
434 _TypeParameterScope typeParameterScope = new _TypeParameterScope(); 481 _TypeParameterScope typeParameterScope = new _TypeParameterScope();
435 scopes.add(typeParameterScope); 482 scopes.add(typeParameterScope);
436 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder(); 483 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder();
437 String nameString = name.name; 484 String nameString = name.name;
438 if (isGetter) { 485 if (isGetter) {
439 b.kind = UnlinkedExecutableKind.getter; 486 b.kind = UnlinkedExecutableKind.getter;
440 } else if (isSetter) { 487 } else if (isSetter) {
(...skipping 20 matching lines...) Expand all
461 if (!isSemanticallyStatic) { 508 if (!isSemanticallyStatic) {
462 for (int i = 0; i < formalParameters.parameters.length; i++) { 509 for (int i = 0; i < formalParameters.parameters.length; i++) {
463 if (!b.parameters[i].isFunctionTyped && 510 if (!b.parameters[i].isFunctionTyped &&
464 b.parameters[i].type == null) { 511 b.parameters[i].type == null) {
465 b.parameters[i].inferredTypeSlot = assignTypeSlot(); 512 b.parameters[i].inferredTypeSlot = assignTypeSlot();
466 } 513 }
467 } 514 }
468 } 515 }
469 } 516 }
470 b.documentationComment = serializeDocumentation(documentationComment); 517 b.documentationComment = serializeDocumentation(documentationComment);
518 b.annotations = serializeAnnotations(annotations);
471 if (returnType == null && !isSemanticallyStatic) { 519 if (returnType == null && !isSemanticallyStatic) {
472 b.inferredReturnTypeSlot = assignTypeSlot(); 520 b.inferredReturnTypeSlot = assignTypeSlot();
473 } 521 }
474 scopes.removeLast(); 522 scopes.removeLast();
475 assert(scopes.length == oldScopesLength); 523 assert(scopes.length == oldScopesLength);
476 return b; 524 return b;
477 } 525 }
478 526
479 /** 527 /**
480 * Serialize the return type and parameters of a function-typed formal 528 * Serialize the return type and parameters of a function-typed formal
(...skipping 11 matching lines...) Expand all
492 } 540 }
493 541
494 /** 542 /**
495 * Serialize a [FieldFormalParameter], [FunctionTypedFormalParameter], or 543 * Serialize a [FieldFormalParameter], [FunctionTypedFormalParameter], or
496 * [SimpleFormalParameter] into an [UnlinkedParam]. 544 * [SimpleFormalParameter] into an [UnlinkedParam].
497 */ 545 */
498 UnlinkedParamBuilder serializeParameter(NormalFormalParameter node) { 546 UnlinkedParamBuilder serializeParameter(NormalFormalParameter node) {
499 UnlinkedParamBuilder b = new UnlinkedParamBuilder(); 547 UnlinkedParamBuilder b = new UnlinkedParamBuilder();
500 b.name = node.identifier.name; 548 b.name = node.identifier.name;
501 b.nameOffset = node.identifier.offset; 549 b.nameOffset = node.identifier.offset;
550 b.annotations = serializeAnnotations(node.metadata);
502 switch (node.kind) { 551 switch (node.kind) {
503 case ParameterKind.REQUIRED: 552 case ParameterKind.REQUIRED:
504 b.kind = UnlinkedParamKind.required; 553 b.kind = UnlinkedParamKind.required;
505 break; 554 break;
506 case ParameterKind.POSITIONAL: 555 case ParameterKind.POSITIONAL:
507 b.kind = UnlinkedParamKind.positional; 556 b.kind = UnlinkedParamKind.positional;
508 break; 557 break;
509 case ParameterKind.NAMED: 558 case ParameterKind.NAMED:
510 b.kind = UnlinkedParamKind.named; 559 b.kind = UnlinkedParamKind.named;
511 break; 560 break;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 } 658 }
610 return typeParameters.typeParameters.map(visitTypeParameter).toList(); 659 return typeParameters.typeParameters.map(visitTypeParameter).toList();
611 } 660 }
612 return const <UnlinkedTypeParamBuilder>[]; 661 return const <UnlinkedTypeParamBuilder>[];
613 } 662 }
614 663
615 /** 664 /**
616 * Serialize the given [variables] into [UnlinkedVariable]s, and store them 665 * Serialize the given [variables] into [UnlinkedVariable]s, and store them
617 * in [this.variables]. 666 * in [this.variables].
618 */ 667 */
619 void serializeVariables(VariableDeclarationList variables, 668 void serializeVariables(
620 bool isDeclaredStatic, Comment documentationComment, bool isField) { 669 VariableDeclarationList variables,
670 bool isDeclaredStatic,
671 Comment documentationComment,
672 NodeList<Annotation> annotations,
673 bool isField) {
621 for (VariableDeclaration variable in variables.variables) { 674 for (VariableDeclaration variable in variables.variables) {
622 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); 675 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder();
623 b.isFinal = variables.isFinal; 676 b.isFinal = variables.isFinal;
624 b.isConst = variables.isConst; 677 b.isConst = variables.isConst;
625 b.isStatic = isDeclaredStatic; 678 b.isStatic = isDeclaredStatic;
626 b.name = variable.name.name; 679 b.name = variable.name.name;
627 b.nameOffset = variable.name.offset; 680 b.nameOffset = variable.name.offset;
628 b.type = serializeTypeName(variables.type); 681 b.type = serializeTypeName(variables.type);
629 b.documentationComment = serializeDocumentation(documentationComment); 682 b.documentationComment = serializeDocumentation(documentationComment);
683 b.annotations = serializeAnnotations(annotations);
630 if (variable.isConst || variable.isFinal && inFieldContext) { 684 if (variable.isConst || variable.isFinal && inFieldContext) {
631 Expression initializer = variable.initializer; 685 Expression initializer = variable.initializer;
632 if (initializer != null) { 686 if (initializer != null) {
633 b.constExpr = serializeConstExpr(initializer); 687 b.constExpr = serializeConstExpr(initializer);
634 } 688 }
635 } 689 }
636 if (variable.initializer != null && 690 if (variable.initializer != null &&
637 (variables.isFinal || variables.isConst)) { 691 (variables.isFinal || variables.isConst)) {
638 b.propagatedTypeSlot = assignTypeSlot(); 692 b.propagatedTypeSlot = assignTypeSlot();
639 } 693 }
(...skipping 13 matching lines...) Expand all
653 serializeClass( 707 serializeClass(
654 node.abstractKeyword, 708 node.abstractKeyword,
655 node.name.name, 709 node.name.name,
656 node.name.offset, 710 node.name.offset,
657 node.typeParameters, 711 node.typeParameters,
658 superclass, 712 superclass,
659 node.withClause, 713 node.withClause,
660 node.implementsClause, 714 node.implementsClause,
661 node.members, 715 node.members,
662 false, 716 false,
663 node.documentationComment); 717 node.documentationComment,
718 node.metadata);
664 } 719 }
665 720
666 @override 721 @override
667 void visitClassTypeAlias(ClassTypeAlias node) { 722 void visitClassTypeAlias(ClassTypeAlias node) {
668 serializeClass( 723 serializeClass(
669 node.abstractKeyword, 724 node.abstractKeyword,
670 node.name.name, 725 node.name.name,
671 node.name.offset, 726 node.name.offset,
672 node.typeParameters, 727 node.typeParameters,
673 node.superclass, 728 node.superclass,
674 node.withClause, 729 node.withClause,
675 node.implementsClause, 730 node.implementsClause,
676 null, 731 null,
677 true, 732 true,
678 node.documentationComment); 733 node.documentationComment,
734 node.metadata);
679 } 735 }
680 736
681 @override 737 @override
682 void visitConstructorDeclaration(ConstructorDeclaration node) { 738 void visitConstructorDeclaration(ConstructorDeclaration node) {
683 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder(); 739 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder();
684 if (node.name != null) { 740 if (node.name != null) {
685 b.name = node.name.name; 741 b.name = node.name.name;
686 b.nameOffset = node.name.offset; 742 b.nameOffset = node.name.offset;
687 } else { 743 } else {
688 b.nameOffset = node.returnType.offset; 744 b.nameOffset = node.returnType.offset;
689 } 745 }
690 b.parameters = node.parameters.parameters 746 b.parameters = node.parameters.parameters
691 .map((FormalParameter p) => p.accept(this)) 747 .map((FormalParameter p) => p.accept(this))
692 .toList(); 748 .toList();
693 b.kind = UnlinkedExecutableKind.constructor; 749 b.kind = UnlinkedExecutableKind.constructor;
694 b.isFactory = node.factoryKeyword != null; 750 b.isFactory = node.factoryKeyword != null;
695 b.isConst = node.constKeyword != null; 751 b.isConst = node.constKeyword != null;
696 b.isExternal = node.externalKeyword != null; 752 b.isExternal = node.externalKeyword != null;
697 b.documentationComment = serializeDocumentation(node.documentationComment); 753 b.documentationComment = serializeDocumentation(node.documentationComment);
754 b.annotations = serializeAnnotations(node.metadata);
698 executables.add(b); 755 executables.add(b);
699 } 756 }
700 757
701 @override 758 @override
702 UnlinkedParamBuilder visitDefaultFormalParameter( 759 UnlinkedParamBuilder visitDefaultFormalParameter(
703 DefaultFormalParameter node) { 760 DefaultFormalParameter node) {
704 UnlinkedParamBuilder b = node.parameter.accept(this); 761 UnlinkedParamBuilder b = node.parameter.accept(this);
705 if (node.defaultValue != null) { 762 if (node.defaultValue != null) {
706 b.defaultValue = serializeConstExpr(node.defaultValue); 763 b.defaultValue = serializeConstExpr(node.defaultValue);
707 } 764 }
708 return b; 765 return b;
709 } 766 }
710 767
711 @override 768 @override
712 void visitEnumDeclaration(EnumDeclaration node) { 769 void visitEnumDeclaration(EnumDeclaration node) {
713 UnlinkedEnumBuilder b = new UnlinkedEnumBuilder(); 770 UnlinkedEnumBuilder b = new UnlinkedEnumBuilder();
714 b.name = node.name.name; 771 b.name = node.name.name;
715 b.nameOffset = node.name.offset; 772 b.nameOffset = node.name.offset;
716 b.values = node.constants 773 b.values = node.constants
717 .map((EnumConstantDeclaration value) => new UnlinkedEnumValueBuilder( 774 .map((EnumConstantDeclaration value) => new UnlinkedEnumValueBuilder(
718 name: value.name.name, nameOffset: value.name.offset)) 775 name: value.name.name, nameOffset: value.name.offset))
719 .toList(); 776 .toList();
720 b.documentationComment = serializeDocumentation(node.documentationComment); 777 b.documentationComment = serializeDocumentation(node.documentationComment);
778 b.annotations = serializeAnnotations(node.metadata);
721 enums.add(b); 779 enums.add(b);
722 } 780 }
723 781
724 @override 782 @override
725 void visitExportDirective(ExportDirective node) { 783 void visitExportDirective(ExportDirective node) {
726 UnlinkedExportNonPublicBuilder b = new UnlinkedExportNonPublicBuilder( 784 UnlinkedExportNonPublicBuilder b = new UnlinkedExportNonPublicBuilder(
727 uriOffset: node.uri.offset, uriEnd: node.uri.end, offset: node.offset); 785 uriOffset: node.uri.offset, uriEnd: node.uri.end, offset: node.offset);
786 b.annotations = serializeAnnotations(node.metadata);
728 exports.add(b); 787 exports.add(b);
729 } 788 }
730 789
731 @override 790 @override
732 void visitFieldDeclaration(FieldDeclaration node) { 791 void visitFieldDeclaration(FieldDeclaration node) {
733 try { 792 try {
734 inFieldContext = true; 793 inFieldContext = true;
735 serializeVariables(node.fields, node.staticKeyword != null, 794 serializeVariables(node.fields, node.staticKeyword != null,
736 node.documentationComment, true); 795 node.documentationComment, node.metadata, true);
737 } finally { 796 } finally {
738 inFieldContext = false; 797 inFieldContext = false;
739 } 798 }
740 } 799 }
741 800
742 @override 801 @override
743 UnlinkedParamBuilder visitFieldFormalParameter(FieldFormalParameter node) { 802 UnlinkedParamBuilder visitFieldFormalParameter(FieldFormalParameter node) {
744 UnlinkedParamBuilder b = serializeParameter(node); 803 UnlinkedParamBuilder b = serializeParameter(node);
745 b.isInitializingFormal = true; 804 b.isInitializingFormal = true;
746 if (node.type != null || node.parameters != null) { 805 if (node.type != null || node.parameters != null) {
(...skipping 12 matching lines...) Expand all
759 executables.add(serializeExecutable( 818 executables.add(serializeExecutable(
760 node.name, 819 node.name,
761 node.isGetter, 820 node.isGetter,
762 node.isSetter, 821 node.isSetter,
763 node.returnType, 822 node.returnType,
764 node.functionExpression.parameters, 823 node.functionExpression.parameters,
765 node.functionExpression.body, 824 node.functionExpression.body,
766 true, 825 true,
767 false, 826 false,
768 node.documentationComment, 827 node.documentationComment,
828 node.metadata,
769 node.functionExpression.typeParameters, 829 node.functionExpression.typeParameters,
770 node.externalKeyword != null)); 830 node.externalKeyword != null));
771 } 831 }
772 832
773 @override 833 @override
774 void visitFunctionTypeAlias(FunctionTypeAlias node) { 834 void visitFunctionTypeAlias(FunctionTypeAlias node) {
775 int oldScopesLength = scopes.length; 835 int oldScopesLength = scopes.length;
776 _TypeParameterScope typeParameterScope = new _TypeParameterScope(); 836 _TypeParameterScope typeParameterScope = new _TypeParameterScope();
777 scopes.add(typeParameterScope); 837 scopes.add(typeParameterScope);
778 UnlinkedTypedefBuilder b = new UnlinkedTypedefBuilder(); 838 UnlinkedTypedefBuilder b = new UnlinkedTypedefBuilder();
779 b.name = node.name.name; 839 b.name = node.name.name;
780 b.nameOffset = node.name.offset; 840 b.nameOffset = node.name.offset;
781 b.typeParameters = 841 b.typeParameters =
782 serializeTypeParameters(node.typeParameters, typeParameterScope); 842 serializeTypeParameters(node.typeParameters, typeParameterScope);
783 EntityRefBuilder serializedReturnType = serializeTypeName(node.returnType); 843 EntityRefBuilder serializedReturnType = serializeTypeName(node.returnType);
784 if (serializedReturnType != null) { 844 if (serializedReturnType != null) {
785 b.returnType = serializedReturnType; 845 b.returnType = serializedReturnType;
786 } 846 }
787 b.parameters = node.parameters.parameters 847 b.parameters = node.parameters.parameters
788 .map((FormalParameter p) => p.accept(this)) 848 .map((FormalParameter p) => p.accept(this))
789 .toList(); 849 .toList();
790 b.documentationComment = serializeDocumentation(node.documentationComment); 850 b.documentationComment = serializeDocumentation(node.documentationComment);
851 b.annotations = serializeAnnotations(node.metadata);
791 typedefs.add(b); 852 typedefs.add(b);
792 scopes.removeLast(); 853 scopes.removeLast();
793 assert(scopes.length == oldScopesLength); 854 assert(scopes.length == oldScopesLength);
794 } 855 }
795 856
796 @override 857 @override
797 UnlinkedParamBuilder visitFunctionTypedFormalParameter( 858 UnlinkedParamBuilder visitFunctionTypedFormalParameter(
798 FunctionTypedFormalParameter node) { 859 FunctionTypedFormalParameter node) {
799 UnlinkedParamBuilder b = serializeParameter(node); 860 UnlinkedParamBuilder b = serializeParameter(node);
800 b.isFunctionTyped = true; 861 b.isFunctionTyped = true;
801 serializeFunctionTypedParameterDetails(b, node.returnType, node.parameters); 862 serializeFunctionTypedParameterDetails(b, node.returnType, node.parameters);
802 return b; 863 return b;
803 } 864 }
804 865
805 @override 866 @override
806 void visitImportDirective(ImportDirective node) { 867 void visitImportDirective(ImportDirective node) {
807 UnlinkedImportBuilder b = new UnlinkedImportBuilder(); 868 UnlinkedImportBuilder b = new UnlinkedImportBuilder();
869 b.annotations = serializeAnnotations(node.metadata);
808 if (node.uri.stringValue == 'dart:core') { 870 if (node.uri.stringValue == 'dart:core') {
809 hasCoreBeenImported = true; 871 hasCoreBeenImported = true;
810 } 872 }
811 b.offset = node.offset; 873 b.offset = node.offset;
812 b.combinators = node.combinators.map(serializeCombinator).toList(); 874 b.combinators = node.combinators.map(serializeCombinator).toList();
813 if (node.prefix != null) { 875 if (node.prefix != null) {
814 b.prefixReference = serializeReference(null, node.prefix.name); 876 b.prefixReference = serializeReference(null, node.prefix.name);
815 b.prefixOffset = node.prefix.offset; 877 b.prefixOffset = node.prefix.offset;
816 } 878 }
817 b.isDeferred = node.deferredKeyword != null; 879 b.isDeferred = node.deferredKeyword != null;
818 b.uri = node.uri.stringValue; 880 b.uri = node.uri.stringValue;
819 b.uriOffset = node.uri.offset; 881 b.uriOffset = node.uri.offset;
820 b.uriEnd = node.uri.end; 882 b.uriEnd = node.uri.end;
821 unlinkedImports.add(b); 883 unlinkedImports.add(b);
822 } 884 }
823 885
824 @override 886 @override
825 void visitLibraryDirective(LibraryDirective node) { 887 void visitLibraryDirective(LibraryDirective node) {
826 libraryName = 888 libraryName =
827 node.name.components.map((SimpleIdentifier id) => id.name).join('.'); 889 node.name.components.map((SimpleIdentifier id) => id.name).join('.');
828 libraryNameOffset = node.name.offset; 890 libraryNameOffset = node.name.offset;
829 libraryNameLength = node.name.length; 891 libraryNameLength = node.name.length;
830 libraryDocumentationComment = 892 libraryDocumentationComment =
831 serializeDocumentation(node.documentationComment); 893 serializeDocumentation(node.documentationComment);
894 libraryAnnotations = serializeAnnotations(node.metadata);
832 } 895 }
833 896
834 @override 897 @override
835 void visitMethodDeclaration(MethodDeclaration node) { 898 void visitMethodDeclaration(MethodDeclaration node) {
836 executables.add(serializeExecutable( 899 executables.add(serializeExecutable(
837 node.name, 900 node.name,
838 node.isGetter, 901 node.isGetter,
839 node.isSetter, 902 node.isSetter,
840 node.returnType, 903 node.returnType,
841 node.parameters, 904 node.parameters,
842 node.body, 905 node.body,
843 false, 906 false,
844 node.isStatic, 907 node.isStatic,
845 node.documentationComment, 908 node.documentationComment,
909 node.metadata,
846 node.typeParameters, 910 node.typeParameters,
847 node.externalKeyword != null)); 911 node.externalKeyword != null));
848 } 912 }
849 913
850 @override 914 @override
851 void visitPartDirective(PartDirective node) { 915 void visitPartDirective(PartDirective node) {
852 parts.add(new UnlinkedPartBuilder( 916 parts.add(new UnlinkedPartBuilder(
853 uriOffset: node.uri.offset, uriEnd: node.uri.end)); 917 uriOffset: node.uri.offset,
918 uriEnd: node.uri.end,
919 annotations: serializeAnnotations(node.metadata)));
854 } 920 }
855 921
856 @override 922 @override
857 void visitPartOfDirective(PartOfDirective node) {} 923 void visitPartOfDirective(PartOfDirective node) {}
858 924
859 @override 925 @override
860 UnlinkedParamBuilder visitSimpleFormalParameter(SimpleFormalParameter node) { 926 UnlinkedParamBuilder visitSimpleFormalParameter(SimpleFormalParameter node) {
861 UnlinkedParamBuilder b = serializeParameter(node); 927 UnlinkedParamBuilder b = serializeParameter(node);
862 b.type = serializeTypeName(node.type); 928 b.type = serializeTypeName(node.type);
863 return b; 929 return b;
864 } 930 }
865 931
866 @override 932 @override
867 void visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 933 void visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
868 serializeVariables(node.variables, false, node.documentationComment, false); 934 serializeVariables(
935 node.variables, false, node.documentationComment, node.metadata, false);
869 } 936 }
870 937
871 @override 938 @override
872 UnlinkedTypeParamBuilder visitTypeParameter(TypeParameter node) { 939 UnlinkedTypeParamBuilder visitTypeParameter(TypeParameter node) {
873 UnlinkedTypeParamBuilder b = new UnlinkedTypeParamBuilder(); 940 UnlinkedTypeParamBuilder b = new UnlinkedTypeParamBuilder();
874 b.name = node.name.name; 941 b.name = node.name.name;
875 b.nameOffset = node.name.offset; 942 b.nameOffset = node.name.offset;
876 if (node.bound != null) { 943 if (node.bound != null) {
877 b.bound = serializeTypeName(node.bound); 944 b.bound = serializeTypeName(node.bound);
878 } 945 }
946 b.annotations = serializeAnnotations(node.metadata);
879 return b; 947 return b;
880 } 948 }
881 949
882 /** 950 /**
883 * Helper method to determine if a given [typeName] refers to `dynamic`. 951 * Helper method to determine if a given [typeName] refers to `dynamic`.
884 */ 952 */
885 static bool isDynamic(TypeName typeName) { 953 static bool isDynamic(TypeName typeName) {
886 Identifier name = typeName.name; 954 Identifier name = typeName.name;
887 return name is SimpleIdentifier && name.name == 'dynamic'; 955 return name is SimpleIdentifier && name.name == 'dynamic';
888 } 956 }
889 } 957 }
890 958
891 /** 959 /**
892 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. 960 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s.
893 */ 961 */
894 class _TypeParameterScope extends _Scope { 962 class _TypeParameterScope extends _Scope {
895 /** 963 /**
896 * Get the number of [_ScopedTypeParameter]s defined in this 964 * Get the number of [_ScopedTypeParameter]s defined in this
897 * [_TypeParameterScope]. 965 * [_TypeParameterScope].
898 */ 966 */
899 int get length => _definedNames.length; 967 int get length => _definedNames.length;
900 } 968 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | pkg/analyzer/lib/src/summary/summarize_const_expr.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698