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

Unified Diff: pkg/analyzer/lib/src/summary/resynthesize.dart

Issue 1983293002: Delay resynthesizing metadata to Impl classes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fixes for review comments. Created 4 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/summary/resynthesize.dart
diff --git a/pkg/analyzer/lib/src/summary/resynthesize.dart b/pkg/analyzer/lib/src/summary/resynthesize.dart
index d285d8cfbbfb6dabe3426d2e3962e4bcd3054352..58ac5d0d1975609edf125e0451f078500d555446 100644
--- a/pkg/analyzer/lib/src/summary/resynthesize.dart
+++ b/pkg/analyzer/lib/src/summary/resynthesize.dart
@@ -1557,6 +1557,11 @@ class _ResynthesizerContext implements ResynthesizerContext {
_ResynthesizerContext(this._unitResynthesizer);
@override
+ ElementAnnotationImpl buildAnnotation(UnlinkedConst uc) {
+ return _unitResynthesizer.buildAnnotation(uc);
+ }
+
+ @override
DartType resolveTypeRef(
EntityRef type, TypeParameterizedElementMixin typeParameterContext,
{bool defaultVoid: false, bool instantiateToBoundsAllowed: true}) {
@@ -1690,36 +1695,40 @@ class _UnitResynthesizer {
TypeProvider get typeProvider => summaryResynthesizer.typeProvider;
/**
+ * Build [ElementAnnotationImpl] for the given [UnlinkedConst].
+ */
+ ElementAnnotationImpl buildAnnotation(UnlinkedConst uc) {
+ ElementAnnotationImpl elementAnnotation = new ElementAnnotationImpl(unit);
+ Expression constExpr = _buildConstExpression(uc);
+ if (constExpr is Identifier) {
+ elementAnnotation.element = constExpr.staticElement;
+ elementAnnotation.annotationAst = AstFactory.annotation(constExpr);
+ } else if (constExpr is InstanceCreationExpression) {
+ elementAnnotation.element = constExpr.staticElement;
+ Identifier typeName = constExpr.constructorName.type.name;
+ SimpleIdentifier constructorName = constExpr.constructorName.name;
+ if (typeName is SimpleIdentifier && constructorName != null) {
+ // E.g. `@cls.ctor()`. Since `cls.ctor` would have been parsed as
+ // a PrefixedIdentifier, we need to resynthesize it as one.
+ typeName = AstFactory.identifier(typeName, constructorName);
+ constructorName = null;
+ }
+ elementAnnotation.annotationAst = AstFactory.annotation2(
+ typeName, constructorName, constExpr.argumentList);
+ } else {
+ throw new StateError(
+ 'Unexpected annotation type: ${constExpr.runtimeType}');
+ }
+ return elementAnnotation;
+ }
+
+ /**
* Build the annotations for the given [element].
*/
void buildAnnotations(
ElementImpl element, List<UnlinkedConst> serializedAnnotations) {
if (serializedAnnotations.isNotEmpty) {
- element.metadata = serializedAnnotations.map((UnlinkedConst a) {
- ElementAnnotationImpl elementAnnotation =
- new ElementAnnotationImpl(this.unit);
- Expression constExpr = _buildConstExpression(a);
- if (constExpr is Identifier) {
- elementAnnotation.element = constExpr.staticElement;
- elementAnnotation.annotationAst = AstFactory.annotation(constExpr);
- } else if (constExpr is InstanceCreationExpression) {
- elementAnnotation.element = constExpr.staticElement;
- Identifier typeName = constExpr.constructorName.type.name;
- SimpleIdentifier constructorName = constExpr.constructorName.name;
- if (typeName is SimpleIdentifier && constructorName != null) {
- // E.g. `@cls.ctor()`. Since `cls.ctor` would have been parsed as
- // a PrefixedIdentifier, we need to resynthesize it as one.
- typeName = AstFactory.identifier(typeName, constructorName);
- constructorName = null;
- }
- elementAnnotation.annotationAst = AstFactory.annotation2(
- typeName, constructorName, constExpr.argumentList);
- } else {
- throw new StateError(
- 'Unexpected annotation type: ${constExpr.runtimeType}');
- }
- return elementAnnotation;
- }).toList();
+ element.metadata = serializedAnnotations.map(buildAnnotation).toList();
}
}
@@ -1822,7 +1831,6 @@ class _UnitResynthesizer {
// TODO(scheglov) move to ClassElementImpl
correspondingType.typeArguments = classElement.typeParameterTypes;
classElement.type = correspondingType;
- buildAnnotations(classElement, serializedClass.annotations);
assert(currentTypeParameters.isEmpty);
// TODO(scheglov) Somehow Observatory shows too much time spent here
// during DDC run on the large codebase. I would expect only Object here.
@@ -2116,7 +2124,6 @@ class _UnitResynthesizer {
}
executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs(
executableElement, null, getCurrentTypeArguments(skipLevels: 1), false);
- buildAnnotations(executableElement, serializedExecutable.annotations);
executableElement.functions =
serializedExecutable.localFunctions.map(buildLocalFunction).toList();
executableElement.labels =
@@ -2449,7 +2456,6 @@ class _UnitResynthesizer {
serializedTypedef.returnType, _currentTypeParameterizedElement);
functionTypeAliasElement.type =
new FunctionTypeImpl.forTypedef(functionTypeAliasElement);
- buildAnnotations(functionTypeAliasElement, serializedTypedef.annotations);
unitHolder.addTypeAlias(functionTypeAliasElement);
currentTypeParameters.removeLast();
assert(currentTypeParameters.isEmpty);
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/element.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698