| 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 library reflectable.src.analyzer_setup; | 5 library reflectable.src.analyzer_setup; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'package:analyzer/file_system/file_system.dart' show Folder; | 8 import 'package:analyzer/file_system/file_system.dart' show Folder; |
| 9 import 'package:analyzer/file_system/physical_file_system.dart'; | 9 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 10 import 'package:analyzer/source/package_map_provider.dart'; | 10 import 'package:analyzer/source/package_map_provider.dart'; |
| 11 import 'package:analyzer/source/package_map_resolver.dart'; | 11 import 'package:analyzer/source/package_map_resolver.dart'; |
| 12 import 'package:analyzer/source/pub_package_map_provider.dart'; | 12 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 13 import 'package:analyzer/src/generated/constant.dart'; | 13 import 'package:analyzer/src/generated/constant.dart'; |
| 14 import 'package:analyzer/src/generated/element.dart'; | 14 import 'package:analyzer/src/generated/element.dart'; |
| 15 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
| 16 import 'package:analyzer/src/generated/java_io.dart'; | 16 import 'package:analyzer/src/generated/java_io.dart'; |
| 17 import 'package:analyzer/src/generated/sdk_io.dart'; | 17 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 18 import 'package:analyzer/src/generated/source_io.dart'; | 18 import 'package:analyzer/src/generated/source_io.dart'; |
| 19 | 19 |
| 20 class AnalyzerSetup { | 20 class AnalyzerSetup { |
| 21 final AnalysisContext context; | 21 final AnalysisContext context; |
| 22 final Set<Source> sources; | 22 final Set<Source> sources; |
| 23 AnalyzerSetup(this.context, this.sources); | 23 AnalyzerSetup(this.context, this.sources); |
| 24 } | 24 } |
| 25 | 25 |
| 26 /// Convert [sourcePath] into an absolute path. | 26 /// Converts [sourcePath] into an absolute path. |
| 27 String _normalizeSourcePath(String sourcePath) { | 27 String _normalizeSourcePath(String sourcePath) { |
| 28 if (sourcePath == null) throw new ArgumentError("sourcePath cannot be null"); | 28 if (sourcePath == null) throw new ArgumentError("sourcePath cannot be null"); |
| 29 return new File(sourcePath).absolute.path; | 29 return new File(sourcePath).absolute.path; |
| 30 } | 30 } |
| 31 | 31 |
| 32 /// Returns the [Uri] for the given input file. | 32 /// Returns the [Uri] for the given input file. |
| 33 /// Usually it is a `file:` [Uri], but if [file] is located in the `lib` | 33 /// Usually it is a `file:` [Uri], but if [file] is located in the `lib` |
| 34 /// directory of the [sdk], then returns a `dart:` [Uri]. | 34 /// directory of the [sdk], then returns a `dart:` [Uri]. |
| 35 Uri _getUri(DirectoryBasedDartSdk sdk, JavaFile file) { | 35 Uri _getUri(DirectoryBasedDartSdk sdk, JavaFile file) { |
| 36 Source source = sdk.fromFileUri(file.toURI()); | 36 Source source = sdk.fromFileUri(file.toURI()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 changeSet.addedSource(librarySource); | 97 changeSet.addedSource(librarySource); |
| 98 context.applyChanges(changeSet); | 98 context.applyChanges(changeSet); |
| 99 | 99 |
| 100 // Avoid using a part as an entry point. | 100 // Avoid using a part as an entry point. |
| 101 if (context.computeKindOf(librarySource) == SourceKind.PART) { | 101 if (context.computeKindOf(librarySource) == SourceKind.PART) { |
| 102 print("Only libraries can be analyzed."); | 102 print("Only libraries can be analyzed."); |
| 103 print("$sourcePath is a part and can not be analyzed."); | 103 print("$sourcePath is a part and can not be analyzed."); |
| 104 throw new ArgumentError("Analyzing a part"); | 104 throw new ArgumentError("Analyzing a part"); |
| 105 } | 105 } |
| 106 | 106 |
| 107 /// Gather libraries for analysis. | 107 /// Gathers libraries for analysis. |
| 108 Set<Source> gatherLibrarySources(LibraryElement library) { | 108 Set<Source> gatherLibrarySources(LibraryElement library) { |
| 109 Set<Source> sources = new Set<Source>(); | 109 Set<Source> sources = new Set<Source>(); |
| 110 Set<CompilationUnitElement> units = new Set<CompilationUnitElement>(); | 110 Set<CompilationUnitElement> units = new Set<CompilationUnitElement>(); |
| 111 Set<LibraryElement> libraries = new Set<LibraryElement>(); | 111 Set<LibraryElement> libraries = new Set<LibraryElement>(); |
| 112 | 112 |
| 113 void addCompilationUnitSource(CompilationUnitElement unit) { | 113 void addCompilationUnitSource(CompilationUnitElement unit) { |
| 114 if (unit == null || units.contains(unit)) return; | 114 if (unit == null || units.contains(unit)) return; |
| 115 units.add(unit); | 115 units.add(unit); |
| 116 sources.add(unit.source); | 116 sources.add(unit.source); |
| 117 } | 117 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 128 } | 128 } |
| 129 | 129 |
| 130 addLibrarySources(library); | 130 addLibrarySources(library); |
| 131 return sources; | 131 return sources; |
| 132 } | 132 } |
| 133 | 133 |
| 134 return new AnalyzerSetup( | 134 return new AnalyzerSetup( |
| 135 context, | 135 context, |
| 136 gatherLibrarySources(context.computeLibraryElement(librarySource))); | 136 gatherLibrarySources(context.computeLibraryElement(librarySource))); |
| 137 } | 137 } |
| OLD | NEW |