| 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();
|
| +}
|
|
|