| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 // TODO(johnniwinther): Make this a separate library. | 5 // TODO(johnniwinther): Make this a separate library. |
| 6 part of dart2js.kernel.element_map; | 6 part of dart2js.kernel.element_map; |
| 7 | 7 |
| 8 class KernelAnnotationProcessor implements AnnotationProcessor { | 8 class KernelAnnotationProcessor implements AnnotationProcessor { |
| 9 final KernelToElementMap elementMap; | 9 final KernelToElementMap elementMap; |
| 10 | 10 |
| 11 KernelAnnotationProcessor(this.elementMap); | 11 KernelAnnotationProcessor(this.elementMap); |
| 12 | 12 |
| 13 void extractNativeAnnotations( | 13 void extractNativeAnnotations( |
| 14 LibraryEntity library, NativeBasicDataBuilder nativeBasicDataBuilder) { | 14 LibraryEntity library, NativeBasicDataBuilder nativeBasicDataBuilder) { |
| 15 ElementEnvironment elementEnvironment = elementMap.elementEnvironment; | 15 ElementEnvironment elementEnvironment = elementMap.elementEnvironment; |
| 16 CommonElements commonElements = elementMap.commonElements; | 16 CommonElements commonElements = elementMap.commonElements; |
| 17 | 17 |
| 18 elementEnvironment.forEachClass(library, (ClassEntity cls) { | 18 elementEnvironment.forEachClass(library, (ClassEntity cls) { |
| 19 String annotationName; | 19 String annotationName; |
| 20 // TODO(johnniwinther): Make [_getClassMetadata] public and at test to | 20 // TODO(johnniwinther): Make [_getClassMetadata] public and at test to |
| 21 // guard against misuse. | 21 // guard against misuse. |
| 22 for (ConstantExpression annotation in elementMap._getClassMetadata(cls)) { | 22 for (ConstantValue value in elementMap._getClassMetadata(cls)) { |
| 23 ConstantValue value = | |
| 24 elementMap.constantEnvironment.getConstantValue(annotation); | |
| 25 String name = readAnnotationName( | 23 String name = readAnnotationName( |
| 26 cls, value, commonElements.nativeAnnotationClass); | 24 cls, value, commonElements.nativeAnnotationClass); |
| 27 if (annotationName == null) { | 25 if (annotationName == null) { |
| 28 annotationName = name; | 26 annotationName = name; |
| 29 } else if (name != null) { | 27 } else if (name != null) { |
| 30 throw new SpannableAssertionFailure( | 28 throw new SpannableAssertionFailure( |
| 31 cls, 'Too many name annotations.'); | 29 cls, 'Too many name annotations.'); |
| 32 } | 30 } |
| 33 } | 31 } |
| 34 if (annotationName != null) { | 32 if (annotationName != null) { |
| 35 nativeBasicDataBuilder.setNativeClassTagInfo(cls, annotationName); | 33 nativeBasicDataBuilder.setNativeClassTagInfo(cls, annotationName); |
| 36 } | 34 } |
| 37 }); | 35 }); |
| 38 } | 36 } |
| 39 | 37 |
| 40 void extractJsInteropAnnotations( | 38 void extractJsInteropAnnotations( |
| 41 LibraryEntity library, NativeBasicDataBuilder nativeBasicDataBuilder) { | 39 LibraryEntity library, NativeBasicDataBuilder nativeBasicDataBuilder) { |
| 42 // TODO(johnniwinther): Implement this. | 40 // TODO(johnniwinther): Implement this. |
| 43 } | 41 } |
| 44 | 42 |
| 45 @override | 43 @override |
| 46 void processJsInteropAnnotations( | 44 void processJsInteropAnnotations( |
| 47 NativeBasicData nativeData, NativeDataBuilder nativeDataBuilder) { | 45 NativeBasicData nativeData, NativeDataBuilder nativeDataBuilder) { |
| 48 // TODO(johnniwinther): Implement this. | 46 // TODO(johnniwinther): Implement this. |
| 49 } | 47 } |
| 50 } | 48 } |
| OLD | NEW |