OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import 'package:front_end/src/fasta/scanner.dart' show StringToken, Token; | 5 import 'package:front_end/src/fasta/scanner.dart' show StringToken, Token; |
6 import 'package:front_end/src/fasta/scanner.dart' as Tokens show EOF_TOKEN; | 6 import 'package:front_end/src/fasta/scanner.dart' as Tokens show EOF_TOKEN; |
7 import 'package:front_end/src/scanner/token.dart' show BeginToken; | 7 import 'package:front_end/src/scanner/token.dart' show BeginToken; |
8 | 8 |
9 import '../common.dart'; | 9 import '../common.dart'; |
10 import '../common_elements.dart' show CommonElements, ElementEnvironment; | 10 import '../common_elements.dart' show CommonElements, ElementEnvironment; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 /// use the declared @JSName as the expression | 171 /// use the declared @JSName as the expression |
172 /// 3. If [element] does not have a @JSName annotation, qualify the name of | 172 /// 3. If [element] does not have a @JSName annotation, qualify the name of |
173 /// the method with the @Native name of the enclosing class. | 173 /// the method with the @Native name of the enclosing class. |
174 void _setNativeNameForStaticMethod(FunctionEntity element) { | 174 void _setNativeNameForStaticMethod(FunctionEntity element) { |
175 String name = _findJsNameFromAnnotation(element); | 175 String name = _findJsNameFromAnnotation(element); |
176 if (name == null) name = element.name; | 176 if (name == null) name = element.name; |
177 if (_isIdentifier(name)) { | 177 if (_isIdentifier(name)) { |
178 List<String> nativeNames = | 178 List<String> nativeNames = |
179 nativeBasicData.getNativeTagsOfClass(element.enclosingClass); | 179 nativeBasicData.getNativeTagsOfClass(element.enclosingClass); |
180 if (nativeNames.length != 1) { | 180 if (nativeNames.length != 1) { |
181 throw new SpannableAssertionFailure( | 181 failedAt( |
182 element, | 182 element, |
183 'Unable to determine a native name for the enclosing class, ' | 183 'Unable to determine a native name for the enclosing class, ' |
184 'options: $nativeNames'); | 184 'options: $nativeNames'); |
185 } | 185 } |
186 nativeDataBuilder.setNativeMemberName(element, '${nativeNames[0]}.$name'); | 186 nativeDataBuilder.setNativeMemberName(element, '${nativeNames[0]}.$name'); |
187 } else { | 187 } else { |
188 nativeDataBuilder.setNativeMemberName(element, name); | 188 nativeDataBuilder.setNativeMemberName(element, name); |
189 } | 189 } |
190 } | 190 } |
191 | 191 |
192 bool _isIdentifier(String s) => _identifier.hasMatch(s); | 192 bool _isIdentifier(String s) => _identifier.hasMatch(s); |
193 | 193 |
194 /// Returns the JSName annotation string or `null` if no JSName annotation is | 194 /// Returns the JSName annotation string or `null` if no JSName annotation is |
195 /// present. | 195 /// present. |
196 String _findJsNameFromAnnotation(MemberEntity element) { | 196 String _findJsNameFromAnnotation(MemberEntity element) { |
197 String jsName = null; | 197 String jsName = null; |
198 for (ConstantValue value in elementEnvironment.getMemberMetadata(element)) { | 198 for (ConstantValue value in elementEnvironment.getMemberMetadata(element)) { |
199 String name = readAnnotationName( | 199 String name = readAnnotationName( |
200 element, value, commonElements.annotationJSNameClass); | 200 element, value, commonElements.annotationJSNameClass); |
201 if (jsName == null) { | 201 if (jsName == null) { |
202 jsName = name; | 202 jsName = name; |
203 } else if (name != null) { | 203 } else if (name != null) { |
204 throw new SpannableAssertionFailure( | 204 failedAt(element, 'Too many JSName annotations: ${value.toDartText()}'); |
205 element, 'Too many JSName annotations: ${value.toDartText()}'); | |
206 } | 205 } |
207 } | 206 } |
208 return jsName; | 207 return jsName; |
209 } | 208 } |
210 } | 209 } |
211 | 210 |
212 class NativeDataResolverImpl extends NativeMemberResolverBase | 211 class NativeDataResolverImpl extends NativeMemberResolverBase |
213 implements NativeDataResolver { | 212 implements NativeDataResolver { |
214 final Compiler _compiler; | 213 final Compiler _compiler; |
215 | 214 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 covariant ClassEntity cls, Set<ClassEntity> nativeClasses) { | 439 covariant ClassEntity cls, Set<ClassEntity> nativeClasses) { |
441 nativeClasses.add(cls); | 440 nativeClasses.add(cls); |
442 // Js Interop interfaces do not have tags. | 441 // Js Interop interfaces do not have tags. |
443 if (_nativeBasicData.isJsInteropClass(cls)) return; | 442 if (_nativeBasicData.isJsInteropClass(cls)) return; |
444 // Since we map from dispatch tags to classes, a dispatch tag must be used | 443 // Since we map from dispatch tags to classes, a dispatch tag must be used |
445 // on only one native class. | 444 // on only one native class. |
446 for (String tag in _nativeBasicData.getNativeTagsOfClass(cls)) { | 445 for (String tag in _nativeBasicData.getNativeTagsOfClass(cls)) { |
447 ClassEntity owner = _tagOwner[tag]; | 446 ClassEntity owner = _tagOwner[tag]; |
448 if (owner != null) { | 447 if (owner != null) { |
449 if (owner != cls) { | 448 if (owner != cls) { |
450 throw new SpannableAssertionFailure( | 449 failedAt(cls, "Tag '$tag' already in use by '${owner.name}'"); |
451 cls, "Tag '$tag' already in use by '${owner.name}'"); | |
452 } | 450 } |
453 } else { | 451 } else { |
454 _tagOwner[tag] = cls; | 452 _tagOwner[tag] = cls; |
455 } | 453 } |
456 } | 454 } |
457 } | 455 } |
458 | 456 |
459 /// Returns the name of the super class of [cls] or `null` of [cls] has | 457 /// Returns the name of the super class of [cls] or `null` of [cls] has |
460 /// no explicit superclass. | 458 /// no explicit superclass. |
461 String _findExtendsNameOfClass(covariant ClassEntity cls) { | 459 String _findExtendsNameOfClass(covariant ClassEntity cls) { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 /// [annotationClass], otherwise returns `null`. | 611 /// [annotationClass], otherwise returns `null`. |
614 String readAnnotationName( | 612 String readAnnotationName( |
615 Spannable spannable, ConstantValue value, ClassEntity annotationClass) { | 613 Spannable spannable, ConstantValue value, ClassEntity annotationClass) { |
616 if (!value.isConstructedObject) return null; | 614 if (!value.isConstructedObject) return null; |
617 ConstructedConstantValue constructedObject = value; | 615 ConstructedConstantValue constructedObject = value; |
618 if (constructedObject.type.element != annotationClass) return null; | 616 if (constructedObject.type.element != annotationClass) return null; |
619 | 617 |
620 Iterable<ConstantValue> fields = constructedObject.fields.values; | 618 Iterable<ConstantValue> fields = constructedObject.fields.values; |
621 // TODO(sra): Better validation of the constant. | 619 // TODO(sra): Better validation of the constant. |
622 if (fields.length != 1 || fields.single is! StringConstantValue) { | 620 if (fields.length != 1 || fields.single is! StringConstantValue) { |
623 throw new SpannableAssertionFailure( | 621 failedAt( |
624 spannable, 'Annotations needs one string: ${value.toStructuredText()}'); | 622 spannable, 'Annotations needs one string: ${value.toStructuredText()}'); |
625 } | 623 } |
626 StringConstantValue specStringConstant = fields.single; | 624 StringConstantValue specStringConstant = fields.single; |
627 return specStringConstant.primitiveValue; | 625 return specStringConstant.primitiveValue; |
628 } | 626 } |
OLD | NEW |