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

Unified Diff: pkg/compiler/lib/src/native/resolver.dart

Issue 2824423002: Compute NativeBasicData for KernelWorldBuilder (Closed)
Patch Set: Created 3 years, 8 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/compiler/lib/src/native/resolver.dart
diff --git a/pkg/compiler/lib/src/native/resolver.dart b/pkg/compiler/lib/src/native/resolver.dart
index b7163e9a559a7c88cc5b0816bc9d2ef3b9ba2a82..9f0fc9c26430e3c635cedfdbecb8fabb115139dd 100644
--- a/pkg/compiler/lib/src/native/resolver.dart
+++ b/pkg/compiler/lib/src/native/resolver.dart
@@ -226,33 +226,21 @@ class NativeDataResolverImpl implements NativeDataResolver {
/// Returns the JSName annotation string or `null` if no JSName annotation is
/// present.
String _findJsNameFromAnnotation(Element element) {
- String name = null;
- ClassElement annotationClass =
- _compiler.commonElements.annotationJSNameClass;
+ String jsName = null;
for (MetadataAnnotation annotation in element.implementation.metadata) {
annotation.ensureResolved(_compiler.resolution);
ConstantValue value =
_compiler.constants.getConstantValue(annotation.constant);
- if (!value.isConstructedObject) continue;
- ConstructedConstantValue constructedObject = value;
- if (constructedObject.type.element != annotationClass) continue;
-
- Iterable<ConstantValue> fields = constructedObject.fields.values;
- // TODO(sra): Better validation of the constant.
- if (fields.length != 1 || fields.single is! StringConstantValue) {
- _reporter.internalError(
- annotation, 'Annotations needs one string: ${annotation}');
- }
- StringConstantValue specStringConstant = fields.single;
- String specString = specStringConstant.toDartString().slowToString();
- if (name == null) {
- name = specString;
- } else {
- _reporter.internalError(
+ String name = readAnnotationName(
+ annotation, value, _compiler.commonElements.annotationJSNameClass);
+ if (jsName == null) {
+ jsName = name;
+ } else if (name != null) {
+ throw new SpannableAssertionFailure(
annotation, 'Too many JSName annotations: ${annotation}');
}
}
- return name;
+ return jsName;
}
@override
@@ -308,7 +296,8 @@ class NativeAnnotationHandler extends EagerAnnotationHandler<String> {
ClassElement cls = element;
String native = getNativeAnnotation(annotation);
if (native != null) {
- _nativeBasicDataBuilder.setNativeClassTagInfo(cls, native);
+ String tagText = native.substring(1, native.length - 1);
+ _nativeBasicDataBuilder.setNativeClassTagInfo(cls, tagText);
return native;
}
}
@@ -568,3 +557,21 @@ class NativeClassResolverImpl implements NativeClassResolver {
});
}
}
+
+/// Extracts the name if [value] is a named annotation based on
+/// [annotationClass], otherwise returns `null`.
+String readAnnotationName(
+ Spannable spannable, ConstantValue value, ClassEntity annotationClass) {
+ if (!value.isConstructedObject) return null;
+ ConstructedConstantValue constructedObject = value;
+ if (constructedObject.type.element != annotationClass) return null;
+
+ Iterable<ConstantValue> fields = constructedObject.fields.values;
+ // TODO(sra): Better validation of the constant.
+ if (fields.length != 1 || fields.single is! StringConstantValue) {
+ throw new SpannableAssertionFailure(
+ spannable, 'Annotations needs one string: ${value.toStructuredText()}');
+ }
+ StringConstantValue specStringConstant = fields.single;
+ return specStringConstant.toDartString().slowToString();
+}

Powered by Google App Engine
This is Rietveld 408576698