| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // Test that elements are not needlessly required by dart2js. | 5 // Test that elements are not needlessly required by dart2js. |
| 6 | 6 |
| 7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
| 8 import 'package:compiler/src/compiler.dart'; | 8 import 'package:compiler/src/compiler.dart'; |
| 9 import 'package:compiler/src/elements/elements.dart'; | 9 import 'package:compiler/src/elements/elements.dart'; |
| 10 import 'package:compiler/src/enqueue.dart'; | 10 import 'package:compiler/src/enqueue.dart'; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 }); | 22 }); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void checkInstantiated(Compiler compiler, ClassElement cls, bool expected) { | 25 void checkInstantiated(Compiler compiler, ClassElement cls, bool expected) { |
| 26 ResolutionEnqueuer enqueuer = compiler.enqueuer.resolution; | 26 ResolutionEnqueuer enqueuer = compiler.enqueuer.resolution; |
| 27 bool isInstantiated = | 27 bool isInstantiated = |
| 28 enqueuer.universe.directlyInstantiatedClasses.contains(cls); | 28 enqueuer.universe.directlyInstantiatedClasses.contains(cls); |
| 29 bool isProcessed = enqueuer.isClassProcessed(cls); | 29 bool isProcessed = enqueuer.isClassProcessed(cls); |
| 30 Expect.equals(expected, isInstantiated, | 30 Expect.equals(expected, isInstantiated, |
| 31 'Unexpected instantiation state of class $cls.'); | 31 'Unexpected instantiation state of class $cls.'); |
| 32 Expect.equals(expected, isProcessed, | 32 Expect.equals( |
| 33 'Unexpected processing state of class $cls.'); | 33 expected, isProcessed, 'Unexpected processing state of class $cls.'); |
| 34 } | 34 } |
| 35 | 35 |
| 36 analyze(String code, | 36 analyze(String code, |
| 37 {bool proxyConstant: false, | 37 {bool proxyConstant: false, bool deprecatedClass: false}) async { |
| 38 bool deprecatedClass: false}) async { | |
| 39 CompilationResult result = await runCompiler( | 38 CompilationResult result = await runCompiler( |
| 40 memorySourceFiles: {'main.dart': code}, | 39 memorySourceFiles: {'main.dart': code}, options: ['--analyze-only']); |
| 41 options: ['--analyze-only']); | |
| 42 Expect.isTrue(result.isSuccess); | 40 Expect.isTrue(result.isSuccess); |
| 43 Compiler compiler = result.compiler; | 41 Compiler compiler = result.compiler; |
| 44 Expect.equals(proxyConstant, compiler.proxyConstant != null, | 42 Expect.equals(proxyConstant, compiler.resolution.proxyConstant != null, |
| 45 "Unexpected computation of proxy constant."); | 43 "Unexpected computation of proxy constant."); |
| 46 | 44 |
| 47 checkInstantiated( | 45 checkInstantiated( |
| 48 compiler, compiler.coreLibrary.find('_Proxy'), proxyConstant); | 46 compiler, compiler.coreLibrary.find('_Proxy'), proxyConstant); |
| 49 checkInstantiated( | 47 checkInstantiated( |
| 50 compiler, compiler.coreLibrary.find('Deprecated'), deprecatedClass); | 48 compiler, compiler.coreLibrary.find('Deprecated'), deprecatedClass); |
| 51 | 49 |
| 52 LibraryElement jsHelperLibrary = | 50 LibraryElement jsHelperLibrary = |
| 53 compiler.libraryLoader.lookupLibrary(BackendHelpers.DART_JS_HELPER); | 51 compiler.libraryLoader.lookupLibrary(BackendHelpers.DART_JS_HELPER); |
| 54 jsHelperLibrary.forEachLocalMember((Element element) { | 52 jsHelperLibrary.forEachLocalMember((Element element) { |
| 55 Uri uri = element.compilationUnit.script.resourceUri; | 53 Uri uri = element.compilationUnit.script.resourceUri; |
| 56 if (element.isClass && uri.path.endsWith('annotations.dart')) { | 54 if (element.isClass && uri.path.endsWith('annotations.dart')) { |
| 57 checkInstantiated(compiler, element, false); | 55 checkInstantiated(compiler, element, false); |
| 58 } | 56 } |
| 59 }); | 57 }); |
| 60 } | 58 } |
| OLD | NEW |