| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 'dart:collection' show HashSet; | 5 import 'dart:collection' show HashSet; |
| 6 import 'package:args/args.dart' show ArgParser, ArgResults; | 6 import 'package:args/args.dart' show ArgParser, ArgResults; |
| 7 import 'package:args/src/usage_exception.dart' show UsageException; |
| 7 import 'package:analyzer/analyzer.dart' | 8 import 'package:analyzer/analyzer.dart' |
| 8 show | 9 show |
| 9 AnalysisError, | 10 AnalysisError, |
| 10 CompilationUnit, | 11 CompilationUnit, |
| 11 CompileTimeErrorCode, | 12 CompileTimeErrorCode, |
| 12 ErrorSeverity, | 13 ErrorSeverity, |
| 13 StaticWarningCode; | 14 StaticWarningCode; |
| 14 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; | 15 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; |
| 15 import 'package:analyzer/src/generated/java_engine.dart' show AnalysisException; | |
| 16 import 'package:analyzer/src/generated/source_io.dart' show Source, SourceKind; | 16 import 'package:analyzer/src/generated/source_io.dart' show Source, SourceKind; |
| 17 import 'package:func/func.dart' show Func1; | 17 import 'package:func/func.dart' show Func1; |
| 18 import 'package:path/path.dart' as path; | 18 import 'package:path/path.dart' as path; |
| 19 | 19 |
| 20 import '../analyzer/context.dart' | 20 import '../analyzer/context.dart' |
| 21 show AnalyzerOptions, createAnalysisContextWithSources; | 21 show AnalyzerOptions, createAnalysisContextWithSources; |
| 22 import 'extension_types.dart' show ExtensionTypeSet; | 22 import 'extension_types.dart' show ExtensionTypeSet; |
| 23 import 'code_generator.dart' show CodeGenerator; | 23 import 'code_generator.dart' show CodeGenerator; |
| 24 import 'error_helpers.dart' show errorSeverity, formatError, sortErrors; | 24 import 'error_helpers.dart' show errorSeverity, formatError, sortErrors; |
| 25 | 25 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // Validate that all parts were explicitly passed in. | 70 // Validate that all parts were explicitly passed in. |
| 71 // If not, it's an error. | 71 // If not, it's an error. |
| 72 var explicitParts = new HashSet<Source>(); | 72 var explicitParts = new HashSet<Source>(); |
| 73 var usedParts = new HashSet<Source>(); | 73 var usedParts = new HashSet<Source>(); |
| 74 for (var sourcePath in unit.sources) { | 74 for (var sourcePath in unit.sources) { |
| 75 var sourceUri = Uri.parse(sourcePath); | 75 var sourceUri = Uri.parse(sourcePath); |
| 76 if (sourceUri.scheme == '') { | 76 if (sourceUri.scheme == '') { |
| 77 sourceUri = path.toUri(path.absolute(sourcePath)); | 77 sourceUri = path.toUri(path.absolute(sourcePath)); |
| 78 } | 78 } |
| 79 Source source = context.sourceFactory.forUri2(sourceUri); | 79 Source source = context.sourceFactory.forUri2(sourceUri); |
| 80 |
| 81 var fileUsage = 'You need to pass at least one existing .dart file as an' |
| 82 ' argument.'; |
| 80 if (source == null) { | 83 if (source == null) { |
| 81 throw new AnalysisException('could not create a source for $sourcePath.' | 84 throw new UsageException( |
| 82 ' The file name is in the wrong format or was not found.'); | 85 'Could not create a source for "$sourcePath". The file name is in' |
| 86 ' the wrong format or was not found.', |
| 87 fileUsage); |
| 88 } else if (!source.exists()) { |
| 89 throw new UsageException( |
| 90 'Given file "$sourcePath" does not exist.', fileUsage); |
| 83 } | 91 } |
| 84 | 92 |
| 85 // Ignore parts. They need to be handled in the context of their library. | 93 // Ignore parts. They need to be handled in the context of their library. |
| 86 if (context.computeKindOf(source) == SourceKind.PART) { | 94 if (context.computeKindOf(source) == SourceKind.PART) { |
| 87 explicitParts.add(source); | 95 explicitParts.add(source); |
| 88 continue; | 96 continue; |
| 89 } | 97 } |
| 90 | 98 |
| 91 var resolvedTree = context.resolveCompilationUnit2(source, source); | 99 var resolvedTree = context.resolveCompilationUnit2(source, source); |
| 92 trees.add(resolvedTree); | 100 trees.add(resolvedTree); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 } | 350 } |
| 343 } | 351 } |
| 344 | 352 |
| 345 /// (Public for tests) the error code used when a part is missing. | 353 /// (Public for tests) the error code used when a part is missing. |
| 346 final missingPartErrorCode = const CompileTimeErrorCode( | 354 final missingPartErrorCode = const CompileTimeErrorCode( |
| 347 'MISSING_PART', 'The part was not supplied as an input to the compiler.'); | 355 'MISSING_PART', 'The part was not supplied as an input to the compiler.'); |
| 348 | 356 |
| 349 /// (Public for tests) the error code used when a part is unused. | 357 /// (Public for tests) the error code used when a part is unused. |
| 350 final unusedPartWarningCode = const StaticWarningCode( | 358 final unusedPartWarningCode = const StaticWarningCode( |
| 351 'UNUSED_PART', 'The part was not used by any libraries being compiled.'); | 359 'UNUSED_PART', 'The part was not used by any libraries being compiled.'); |
| OLD | NEW |