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

Side by Side Diff: pkg/analyzer/lib/src/kernel/resynthesize.dart

Issue 2988113002: Add Class.isEnum to Kernel and use it to resynthesize enums in Analyzer. (Closed)
Patch Set: Created 3 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
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 'package:analyzer/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
7 import 'package:analyzer/dart/ast/token.dart'; 7 import 'package:analyzer/dart/ast/token.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/dart/element/type.dart'; 9 import 'package:analyzer/dart/element/type.dart';
10 import 'package:analyzer/src/dart/element/element.dart'; 10 import 'package:analyzer/src/dart/element/element.dart';
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 CompilationUnitElementImpl unitImpl = unit; 630 CompilationUnitElementImpl unitImpl = unit;
631 ElementImpl child = unitImpl.getChild(name.name); 631 ElementImpl child = unitImpl.getChild(name.name);
632 if (child != null) { 632 if (child != null) {
633 return child; 633 return child;
634 } 634 }
635 } 635 }
636 return null; 636 return null;
637 } 637 }
638 638
639 // Search in the class. 639 // Search in the class.
640 if (parentElement is ClassElementImpl) { 640 if (parentElement is AbstractClassElementImpl) {
641 if (isGetter) { 641 if (isGetter) {
642 return parentElement.getGetter(name.name) as ElementImpl; 642 return parentElement.getGetter(name.name) as ElementImpl;
643 } else if (isSetter) { 643 } else if (isSetter) {
644 return parentElement.getSetter(name.name) as ElementImpl; 644 return parentElement.getSetter(name.name) as ElementImpl;
645 } else if (isField) { 645 } else if (isField) {
646 return parentElement.getField(name.name) as ElementImpl; 646 return parentElement.getField(name.name) as ElementImpl;
647 } else if (isConstructor) { 647 } else if (isConstructor) {
648 if (name.name.isEmpty) { 648 if (name.name.isEmpty) {
649 return parentElement.unnamedConstructor as ConstructorElementImpl; 649 return parentElement.unnamedConstructor as ConstructorElementImpl;
650 } 650 }
651 return parentElement.getNamedConstructor(name.name) as ElementImpl; 651 return parentElement.getNamedConstructor(name.name) as ElementImpl;
652 } else if (isMethod) { 652 } else if (isMethod) {
653 return parentElement.getMethod(name.name) as ElementImpl; 653 return parentElement.getMethod(name.name) as ElementImpl;
654 } 654 }
655 return null; 655 return null;
656 } 656 }
657 657
658 throw new UnimplementedError('Should not be reached.'); 658 throw new UnimplementedError('Should not be reached.');
659 } 659 }
660 660
661 InterfaceType _getInterfaceType(ElementImpl context, 661 InterfaceType _getInterfaceType(ElementImpl context,
662 kernel.CanonicalName className, List<kernel.DartType> kernelArguments) { 662 kernel.CanonicalName className, List<kernel.DartType> kernelArguments) {
663 var libraryName = className.parent; 663 var libraryName = className.parent;
664 var libraryElement = _resynthesizer.getLibrary(libraryName.name); 664 var libraryElement = _resynthesizer.getLibrary(libraryName.name);
665 ClassElementImpl classElement = libraryElement.getType(className.name); 665 ClassElement classElement = libraryElement.getType(className.name);
666 classElement ??= libraryElement.getEnum(className.name);
666 667
667 if (kernelArguments.isEmpty) { 668 if (kernelArguments.isEmpty) {
668 return classElement.type; 669 return classElement.type;
669 } 670 }
670 671
671 return new InterfaceTypeImpl.elementWithNameAndArgs( 672 return new InterfaceTypeImpl.elementWithNameAndArgs(
672 classElement, classElement.name, () { 673 classElement, classElement.name, () {
673 List<DartType> arguments = kernelArguments 674 List<DartType> arguments = kernelArguments
674 .map((kernel.DartType k) => getType(context, k)) 675 .map((kernel.DartType k) => getType(context, k))
675 .toList(growable: false); 676 .toList(growable: false);
(...skipping 10 matching lines...) Expand all
686 for (var typeParameter in ctx.typeParameters) { 687 for (var typeParameter in ctx.typeParameters) {
687 if (typeParameter.name == name) { 688 if (typeParameter.name == name) {
688 return typeParameter; 689 return typeParameter;
689 } 690 }
690 } 691 }
691 } 692 }
692 } 693 }
693 throw new StateError('Not found $kernelTypeParameter in $context'); 694 throw new StateError('Not found $kernelTypeParameter in $context');
694 } 695 }
695 } 696 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/element.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698