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

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

Issue 2986983002: Resynthesize metadata from Kernel, when already supported. (Closed)
Patch Set: Created 3 years, 5 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/kernel/resynthesize.dart
diff --git a/pkg/analyzer/lib/src/kernel/resynthesize.dart b/pkg/analyzer/lib/src/kernel/resynthesize.dart
index 0e62cb9b3c64272935b121799b5e6c5ca28db4a7..d018091f77bad8ae246ecfbe77b349acd2738f43 100644
--- a/pkg/analyzer/lib/src/kernel/resynthesize.dart
+++ b/pkg/analyzer/lib/src/kernel/resynthesize.dart
@@ -384,6 +384,21 @@ class _KernelLibraryResynthesizerContextImpl
_KernelLibraryResynthesizerContextImpl(this._resynthesizer, this.library);
@override
+ List<ElementAnnotation> buildAnnotations(
+ CompilationUnitElementImpl unit, List<kernel.Expression> expressions) {
+ int length = expressions.length;
+ if (length != 0) {
+ var annotations = new List<ElementAnnotation>(length);
+ for (int i = 0; i < length; i++) {
+ annotations[i] = _buildAnnotation(unit, expressions[i]);
+ }
+ return annotations;
+ } else {
+ return const <ElementAnnotation>[];
+ }
+ }
+
+ @override
UnitExplicitTopLevelAccessors buildTopLevelAccessors(
CompilationUnitElementImpl unit) {
var accessorsData = new UnitExplicitTopLevelAccessors();
@@ -544,6 +559,27 @@ class _KernelLibraryResynthesizerContextImpl
throw new UnimplementedError('For ${kernelType.runtimeType}');
}
+ ElementAnnotationImpl _buildAnnotation(
+ CompilationUnitElementImpl unit, kernel.Expression expression) {
+ ElementAnnotationImpl elementAnnotation = new ElementAnnotationImpl(unit);
+ Expression constExpr = getExpression(expression);
+ if (constExpr is Identifier) {
+ elementAnnotation.element = constExpr.staticElement;
+ elementAnnotation.annotationAst = AstTestFactory.annotation(constExpr);
+ } else if (constExpr is InstanceCreationExpression) {
+ elementAnnotation.element = constExpr.staticElement;
+ Identifier typeName = constExpr.constructorName.type.name;
+ SimpleIdentifier constructorName = constExpr.constructorName.name;
+ elementAnnotation.annotationAst = AstTestFactory.annotation2(
+ typeName, constructorName, constExpr.argumentList)
+ ..element = constExpr.staticElement;
+ } else {
+ throw new StateError(
+ 'Unexpected annotation type: ${constExpr.runtimeType}');
+ }
+ return elementAnnotation;
+ }
+
/**
* Return the [ElementImpl] that corresponds to the given [name], or `null`
* if the corresponding element cannot be found.
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/element.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698