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

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

Issue 1698443004: Get rid of unnecessary try/finally in resynthesize.dart (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 summary_resynthesizer; 5 library summary_resynthesizer;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 } 806 }
807 return elementAnnotation; 807 return elementAnnotation;
808 }).toList(); 808 }).toList();
809 } 809 }
810 } 810 }
811 811
812 /** 812 /**
813 * Resynthesize a [ClassElement] and place it in [unitHolder]. 813 * Resynthesize a [ClassElement] and place it in [unitHolder].
814 */ 814 */
815 void buildClass(UnlinkedClass serializedClass) { 815 void buildClass(UnlinkedClass serializedClass) {
816 try { 816 ClassElementImpl classElement =
817 ClassElementImpl classElement = new ClassElementImpl( 817 new ClassElementImpl(serializedClass.name, serializedClass.nameOffset);
818 serializedClass.name, serializedClass.nameOffset); 818 classElement.typeParameters =
819 classElement.typeParameters = 819 buildTypeParameters(serializedClass.typeParameters);
820 buildTypeParameters(serializedClass.typeParameters); 820 classElement.abstract = serializedClass.isAbstract;
821 classElement.abstract = serializedClass.isAbstract; 821 classElement.mixinApplication = serializedClass.isMixinApplication;
822 classElement.mixinApplication = serializedClass.isMixinApplication; 822 InterfaceTypeImpl correspondingType = new InterfaceTypeImpl(classElement);
823 InterfaceTypeImpl correspondingType = new InterfaceTypeImpl(classElement); 823 if (serializedClass.supertype != null) {
824 if (serializedClass.supertype != null) { 824 classElement.supertype = buildType(serializedClass.supertype);
825 classElement.supertype = buildType(serializedClass.supertype); 825 } else if (!serializedClass.hasNoSupertype) {
826 } else if (!serializedClass.hasNoSupertype) { 826 if (isCoreLibrary) {
827 if (isCoreLibrary) { 827 delayedObjectSubclasses.add(classElement);
828 delayedObjectSubclasses.add(classElement); 828 } else {
829 } else { 829 classElement.supertype = summaryResynthesizer.typeProvider.objectType;
830 classElement.supertype = summaryResynthesizer.typeProvider.objectType;
831 }
832 } 830 }
833 classElement.interfaces = 831 }
834 serializedClass.interfaces.map(buildType).toList(); 832 classElement.interfaces =
835 classElement.mixins = serializedClass.mixins.map(buildType).toList(); 833 serializedClass.interfaces.map(buildType).toList();
836 ElementHolder memberHolder = new ElementHolder(); 834 classElement.mixins = serializedClass.mixins.map(buildType).toList();
837 fields = <String, FieldElementImpl>{}; 835 ElementHolder memberHolder = new ElementHolder();
838 for (UnlinkedVariable serializedVariable in serializedClass.fields) { 836 fields = <String, FieldElementImpl>{};
839 buildVariable(serializedVariable, memberHolder); 837 for (UnlinkedVariable serializedVariable in serializedClass.fields) {
838 buildVariable(serializedVariable, memberHolder);
839 }
840 bool constructorFound = false;
841 constructors = <String, ConstructorElementImpl>{};
842 for (UnlinkedExecutable serializedExecutable
843 in serializedClass.executables) {
844 switch (serializedExecutable.kind) {
845 case UnlinkedExecutableKind.constructor:
846 constructorFound = true;
847 buildConstructor(
848 serializedExecutable, memberHolder, correspondingType);
849 break;
850 case UnlinkedExecutableKind.functionOrMethod:
851 case UnlinkedExecutableKind.getter:
852 case UnlinkedExecutableKind.setter:
853 buildExecutable(serializedExecutable, memberHolder);
854 break;
840 } 855 }
841 bool constructorFound = false; 856 }
842 constructors = <String, ConstructorElementImpl>{}; 857 if (!serializedClass.isMixinApplication) {
843 for (UnlinkedExecutable serializedExecutable 858 if (!constructorFound) {
844 in serializedClass.executables) { 859 // Synthesize implicit constructors.
845 switch (serializedExecutable.kind) { 860 ConstructorElementImpl constructor = new ConstructorElementImpl('', -1);
846 case UnlinkedExecutableKind.constructor: 861 constructor.synthetic = true;
847 constructorFound = true; 862 constructor.returnType = correspondingType;
848 buildConstructor( 863 constructor.type = new FunctionTypeImpl.elementWithNameAndArgs(
849 serializedExecutable, memberHolder, correspondingType); 864 constructor, null, getCurrentTypeArguments(), false);
850 break; 865 memberHolder.addConstructor(constructor);
851 case UnlinkedExecutableKind.functionOrMethod:
852 case UnlinkedExecutableKind.getter:
853 case UnlinkedExecutableKind.setter:
854 buildExecutable(serializedExecutable, memberHolder);
855 break;
856 }
857 } 866 }
858 if (!serializedClass.isMixinApplication) { 867 classElement.constructors = memberHolder.constructors;
859 if (!constructorFound) {
860 // Synthesize implicit constructors.
861 ConstructorElementImpl constructor =
862 new ConstructorElementImpl('', -1);
863 constructor.synthetic = true;
864 constructor.returnType = correspondingType;
865 constructor.type = new FunctionTypeImpl.elementWithNameAndArgs(
866 constructor, null, getCurrentTypeArguments(), false);
867 memberHolder.addConstructor(constructor);
868 }
869 classElement.constructors = memberHolder.constructors;
870 }
871 classElement.accessors = memberHolder.accessors;
872 classElement.fields = memberHolder.fields;
873 classElement.methods = memberHolder.methods;
874 correspondingType.typeArguments = getCurrentTypeArguments();
875 classElement.type = correspondingType;
876 buildDocumentation(classElement, serializedClass.documentationComment);
877 buildAnnotations(classElement, serializedClass.annotations);
878 resolveConstructorInitializers(classElement);
879 unitHolder.addType(classElement);
880 } finally {
881 currentTypeParameters.removeLast();
882 assert(currentTypeParameters.isEmpty);
883 fields = null;
884 constructors = null;
885 } 868 }
869 classElement.accessors = memberHolder.accessors;
870 classElement.fields = memberHolder.fields;
871 classElement.methods = memberHolder.methods;
872 correspondingType.typeArguments = getCurrentTypeArguments();
873 classElement.type = correspondingType;
874 buildDocumentation(classElement, serializedClass.documentationComment);
875 buildAnnotations(classElement, serializedClass.annotations);
876 resolveConstructorInitializers(classElement);
877 unitHolder.addType(classElement);
878 currentTypeParameters.removeLast();
879 assert(currentTypeParameters.isEmpty);
880 fields = null;
881 constructors = null;
886 } 882 }
887 883
888 /** 884 /**
889 * Resynthesize a [NamespaceCombinator]. 885 * Resynthesize a [NamespaceCombinator].
890 */ 886 */
891 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) { 887 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) {
892 if (serializedCombinator.shows.isNotEmpty) { 888 if (serializedCombinator.shows.isNotEmpty) {
893 ShowElementCombinatorImpl combinator = new ShowElementCombinatorImpl(); 889 ShowElementCombinatorImpl combinator = new ShowElementCombinatorImpl();
894 // Note: we call toList() so that we don't retain a reference to the 890 // Note: we call toList() so that we don't retain a reference to the
895 // deserialized data structure. 891 // deserialized data structure.
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 return referenceInfo.buildType( 1600 return referenceInfo.buildType(
1605 getTypeArgument, type.implicitFunctionTypeIndices); 1601 getTypeArgument, type.implicitFunctionTypeIndices);
1606 } 1602 }
1607 } 1603 }
1608 1604
1609 /** 1605 /**
1610 * Resynthesize a [FunctionTypeAliasElement] and place it in the 1606 * Resynthesize a [FunctionTypeAliasElement] and place it in the
1611 * [unitHolder]. 1607 * [unitHolder].
1612 */ 1608 */
1613 void buildTypedef(UnlinkedTypedef serializedTypedef) { 1609 void buildTypedef(UnlinkedTypedef serializedTypedef) {
1614 try { 1610 FunctionTypeAliasElementImpl functionTypeAliasElement =
1615 FunctionTypeAliasElementImpl functionTypeAliasElement = 1611 new FunctionTypeAliasElementImpl(
1616 new FunctionTypeAliasElementImpl( 1612 serializedTypedef.name, serializedTypedef.nameOffset);
1617 serializedTypedef.name, serializedTypedef.nameOffset); 1613 functionTypeAliasElement.typeParameters =
1618 functionTypeAliasElement.typeParameters = 1614 buildTypeParameters(serializedTypedef.typeParameters);
1619 buildTypeParameters(serializedTypedef.typeParameters); 1615 functionTypeAliasElement.parameters =
1620 functionTypeAliasElement.parameters = 1616 serializedTypedef.parameters.map(buildParameter).toList();
1621 serializedTypedef.parameters.map(buildParameter).toList(); 1617 functionTypeAliasElement.returnType =
1622 functionTypeAliasElement.returnType = 1618 buildType(serializedTypedef.returnType);
1623 buildType(serializedTypedef.returnType); 1619 functionTypeAliasElement.type =
1624 functionTypeAliasElement.type = 1620 new FunctionTypeImpl.forTypedef(functionTypeAliasElement);
1625 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); 1621 buildDocumentation(
1626 buildDocumentation( 1622 functionTypeAliasElement, serializedTypedef.documentationComment);
1627 functionTypeAliasElement, serializedTypedef.documentationComment); 1623 buildAnnotations(functionTypeAliasElement, serializedTypedef.annotations);
1628 buildAnnotations(functionTypeAliasElement, serializedTypedef.annotations); 1624 unitHolder.addTypeAlias(functionTypeAliasElement);
1629 unitHolder.addTypeAlias(functionTypeAliasElement); 1625 currentTypeParameters.removeLast();
1630 } finally { 1626 assert(currentTypeParameters.isEmpty);
1631 currentTypeParameters.removeLast();
1632 assert(currentTypeParameters.isEmpty);
1633 }
1634 } 1627 }
1635 1628
1636 /** 1629 /**
1637 * Resynthesize a [TypeParameterElement], handling all parts of its except 1630 * Resynthesize a [TypeParameterElement], handling all parts of its except
1638 * its bound. 1631 * its bound.
1639 * 1632 *
1640 * The bound is deferred until later since it may refer to other type 1633 * The bound is deferred until later since it may refer to other type
1641 * parameters that have not been resynthesized yet. To handle the bound, 1634 * parameters that have not been resynthesized yet. To handle the bound,
1642 * call [finishTypeParameter]. 1635 * call [finishTypeParameter].
1643 */ 1636 */
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
2181 } 2174 }
2182 : () => this.element; 2175 : () => this.element;
2183 // TODO(paulberry): Is it a bug that we have to pass `false` for 2176 // TODO(paulberry): Is it a bug that we have to pass `false` for
2184 // isInstantiated? 2177 // isInstantiated?
2185 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); 2178 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false);
2186 } else { 2179 } else {
2187 return null; 2180 return null;
2188 } 2181 }
2189 } 2182 }
2190 } 2183 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698