| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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:async_helper/async_helper.dart'; | 5 import 'package:async_helper/async_helper.dart'; |
| 6 import 'package:compiler/src/constants/values.dart' show PrimitiveConstantValue; | 6 import 'package:compiler/src/constants/values.dart' show PrimitiveConstantValue; |
| 7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 import 'compiler_helper.dart'; | 8 import 'compiler_helper.dart'; |
| 9 import 'package:compiler/src/parser/partial_elements.dart' | 9 import 'package:compiler/src/parser/partial_elements.dart' |
| 10 show PartialMetadataAnnotation; | 10 show PartialMetadataAnnotation; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 // Ensure that a compile-time constant can be resolved from an | 83 // Ensure that a compile-time constant can be resolved from an |
| 84 // annotation. | 84 // annotation. |
| 85 var source3 = """const native = 'xyz'; | 85 var source3 = """const native = 'xyz'; |
| 86 class Foo { | 86 class Foo { |
| 87 @native | 87 @native |
| 88 $declaration | 88 $declaration |
| 89 } | 89 } |
| 90 main() {}"""; | 90 main() {}"""; |
| 91 | 91 |
| 92 analyzeAndCheck(source3, 'Foo', (compiler, element) { | 92 analyzeAndCheck(source3, 'Foo', (compiler, dynamic element) { |
| 93 compiler.enqueuer.resolution.queueIsClosed = false; | 93 compiler.enqueuer.resolution.queueIsClosed = false; |
| 94 Expect.equals(0, element.metadata.length); | 94 Expect.equals(0, element.metadata.length); |
| 95 element.ensureResolved(compiler.resolution); | 95 element.ensureResolved(compiler.resolution); |
| 96 Expect.equals(0, element.metadata.length); | 96 Expect.equals(0, element.metadata.length); |
| 97 element = element.lookupLocalMember(name); | 97 element = element.lookupLocalMember(name); |
| 98 Expect.equals(1, element.metadata.length); | 98 Expect.equals(1, element.metadata.length); |
| 99 PartialMetadataAnnotation annotation = element.metadata.first; | 99 PartialMetadataAnnotation annotation = element.metadata.first; |
| 100 annotation.ensureResolved(compiler.resolution); | 100 annotation.ensureResolved(compiler.resolution); |
| 101 PrimitiveConstantValue value = | 101 PrimitiveConstantValue value = |
| 102 compiler.constants.getConstantValue(annotation.constant); | 102 compiler.constants.getConstantValue(annotation.constant); |
| 103 Expect.stringEquals('xyz', value.primitiveValue); | 103 Expect.stringEquals('xyz', value.primitiveValue); |
| 104 | 104 |
| 105 checkPosition( | 105 checkPosition( |
| 106 annotation, annotation.cachedNode, source3, compiler.reporter); | 106 annotation, annotation.cachedNode, source3, compiler.reporter); |
| 107 }); | 107 }); |
| 108 | 108 |
| 109 // Ensure that each repeated annotation has a unique instance of | 109 // Ensure that each repeated annotation has a unique instance of |
| 110 // [MetadataAnnotation]. | 110 // [MetadataAnnotation]. |
| 111 var source4 = """const native = 'xyz'; | 111 var source4 = """const native = 'xyz'; |
| 112 class Foo { | 112 class Foo { |
| 113 @native @native | 113 @native @native |
| 114 $declaration | 114 $declaration |
| 115 } | 115 } |
| 116 main() {}"""; | 116 main() {}"""; |
| 117 | 117 |
| 118 analyzeAndCheck(source4, 'Foo', (compiler, element) { | 118 analyzeAndCheck(source4, 'Foo', (compiler, dynamic element) { |
| 119 compiler.enqueuer.resolution.queueIsClosed = false; | 119 compiler.enqueuer.resolution.queueIsClosed = false; |
| 120 Expect.equals(0, element.metadata.length); | 120 Expect.equals(0, element.metadata.length); |
| 121 element.ensureResolved(compiler.resolution); | 121 element.ensureResolved(compiler.resolution); |
| 122 Expect.equals(0, element.metadata.length); | 122 Expect.equals(0, element.metadata.length); |
| 123 element = element.lookupLocalMember(name); | 123 element = element.lookupLocalMember(name); |
| 124 Expect.equals(2, element.metadata.length); | 124 Expect.equals(2, element.metadata.length); |
| 125 PartialMetadataAnnotation annotation1 = element.metadata.elementAt(0); | 125 PartialMetadataAnnotation annotation1 = element.metadata.elementAt(0); |
| 126 PartialMetadataAnnotation annotation2 = element.metadata.elementAt(1); | 126 PartialMetadataAnnotation annotation2 = element.metadata.elementAt(1); |
| 127 annotation1.ensureResolved(compiler.resolution); | 127 annotation1.ensureResolved(compiler.resolution); |
| 128 annotation2.ensureResolved(compiler.resolution); | 128 annotation2.ensureResolved(compiler.resolution); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 annotation, annotation.cachedNode, source, compiler.reporter); | 190 annotation, annotation.cachedNode, source, compiler.reporter); |
| 191 })); | 191 })); |
| 192 } | 192 } |
| 193 | 193 |
| 194 var source; | 194 var source; |
| 195 | 195 |
| 196 source = """@native | 196 source = """@native |
| 197 library foo; | 197 library foo; |
| 198 const native = 'xyz'; | 198 const native = 'xyz'; |
| 199 main() {}"""; | 199 main() {}"""; |
| 200 compileAndCheckLibrary(source, (e) => e.libraryTag.metadata); | 200 compileAndCheckLibrary(source, (dynamic e) => e.libraryTag.metadata); |
| 201 | 201 |
| 202 source = """@native | 202 source = """@native |
| 203 import 'lib.dart'; | 203 import 'lib.dart'; |
| 204 const native = 'xyz'; | 204 const native = 'xyz'; |
| 205 main() {}"""; | 205 main() {}"""; |
| 206 compileAndCheckLibrary(source, (e) => e.tags.single.metadata); | 206 compileAndCheckLibrary(source, (dynamic e) => e.tags.single.metadata); |
| 207 | 207 |
| 208 source = """@native | 208 source = """@native |
| 209 export 'lib.dart'; | 209 export 'lib.dart'; |
| 210 const native = 'xyz'; | 210 const native = 'xyz'; |
| 211 main() {}"""; | 211 main() {}"""; |
| 212 compileAndCheckLibrary(source, (e) => e.tags.single.metadata); | 212 compileAndCheckLibrary(source, (dynamic e) => e.tags.single.metadata); |
| 213 | 213 |
| 214 source = """@native | 214 source = """@native |
| 215 part 'part.dart'; | 215 part 'part.dart'; |
| 216 const native = 'xyz'; | 216 const native = 'xyz'; |
| 217 main() {}"""; | 217 main() {}"""; |
| 218 compileAndCheckLibrary(source, (e) => e.tags.single.metadata); | 218 compileAndCheckLibrary(source, (dynamic e) => e.tags.single.metadata); |
| 219 | 219 |
| 220 source = """@native | 220 source = """@native |
| 221 part 'part.dart'; | 221 part 'part.dart'; |
| 222 const native = 'xyz'; | 222 const native = 'xyz'; |
| 223 main() {}"""; | 223 main() {}"""; |
| 224 compileAndCheckLibrary( | 224 compileAndCheckLibrary( |
| 225 source, (e) => e.compilationUnits.first.partTag.metadata); | 225 source, (dynamic e) => e.compilationUnits.first.partTag.metadata); |
| 226 } | 226 } |
| 227 | 227 |
| 228 void main() { | 228 void main() { |
| 229 testClassMetadata(); | 229 testClassMetadata(); |
| 230 testTopLevelMethodMetadata(); | 230 testTopLevelMethodMetadata(); |
| 231 testTopLevelFieldMetadata(); | 231 testTopLevelFieldMetadata(); |
| 232 testLibraryTags(); | 232 testLibraryTags(); |
| 233 } | 233 } |
| OLD | NEW |