mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 15:01:29 +00:00
Analyzer code cleanup.
Removed some unused imports and fixed member sorting. R=scheglov@google.com Review URL: https://codereview.chromium.org//1230273002 .
This commit is contained in:
parent
04fa456a88
commit
a81c308283
|
@ -4,15 +4,12 @@
|
||||||
|
|
||||||
library source.sdk_ext;
|
library source.sdk_ext;
|
||||||
|
|
||||||
import 'dart:async';
|
|
||||||
import 'dart:collection';
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:core' hide Resource;
|
import 'dart:core' hide Resource;
|
||||||
|
|
||||||
import 'package:analyzer/file_system/file_system.dart';
|
import 'package:analyzer/file_system/file_system.dart';
|
||||||
import 'package:analyzer/source/package_map_resolver.dart';
|
|
||||||
import 'package:analyzer/src/generated/source.dart';
|
|
||||||
import 'package:analyzer/src/generated/java_io.dart' show JavaFile;
|
import 'package:analyzer/src/generated/java_io.dart' show JavaFile;
|
||||||
|
import 'package:analyzer/src/generated/source.dart';
|
||||||
import 'package:analyzer/src/generated/source_io.dart' show FileBasedSource;
|
import 'package:analyzer/src/generated/source_io.dart' show FileBasedSource;
|
||||||
import 'package:path/path.dart' as pathos;
|
import 'package:path/path.dart' as pathos;
|
||||||
|
|
||||||
|
@ -41,58 +38,16 @@ class SdkExtUriResolver extends UriResolver {
|
||||||
packageMap.forEach(_processPackage);
|
packageMap.forEach(_processPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Programmatically add a new SDK extension given a JSON description
|
/// Number of sdk extensions.
|
||||||
/// ([sdkExtJSON]) and a lib directory ([libDir]).
|
int get length => _urlMappings.length;
|
||||||
void addSdkExt(String sdkExtJSON, Folder libDir) {
|
|
||||||
_processSdkExt(sdkExtJSON, libDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the path mapping for [libName] or null if there is none.
|
/// Return the path mapping for [libName] or null if there is none.
|
||||||
String operator[](String libName) => _urlMappings[libName];
|
String operator[](String libName) => _urlMappings[libName];
|
||||||
|
|
||||||
/// Number of sdk extensions.
|
/// Programmatically add a new SDK extension given a JSON description
|
||||||
int get length => _urlMappings.length;
|
/// ([sdkExtJSON]) and a lib directory ([libDir]).
|
||||||
|
void addSdkExt(String sdkExtJSON, Folder libDir) {
|
||||||
/// Resolve a 'part' statement inside an sdk extension.
|
_processSdkExt(sdkExtJSON, libDir);
|
||||||
Source _resolvePart(Uri libraryEntry, String partPath, Uri importUri) {
|
|
||||||
// Library part.
|
|
||||||
var directory = pathos.dirname(libraryEntry.path);
|
|
||||||
var partUri = new Uri.file(pathos.join(directory, partPath));
|
|
||||||
assert(partUri.isAbsolute);
|
|
||||||
JavaFile javaFile = new JavaFile.fromUri(partUri);
|
|
||||||
return new FileBasedSource(javaFile, importUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Resolve an import of an sdk extension.
|
|
||||||
Source _resolveEntry(Uri libraryEntry, Uri importUri) {
|
|
||||||
// Library entry.
|
|
||||||
JavaFile javaFile = new JavaFile.fromUri(libraryEntry);
|
|
||||||
return new FileBasedSource(javaFile, importUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the library name of [importUri].
|
|
||||||
String _libraryName(Uri importUri) {
|
|
||||||
var uri = importUri.toString();
|
|
||||||
int index = uri.indexOf('/');
|
|
||||||
if (index >= 0) {
|
|
||||||
return uri.substring(0, index);
|
|
||||||
}
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the part path of [importUri].
|
|
||||||
String _partPath(Uri importUri) {
|
|
||||||
var uri = importUri.toString();
|
|
||||||
int index = uri.indexOf('/');
|
|
||||||
if (index >= 0) {
|
|
||||||
return uri.substring(index + 1);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if [libraryName] is a registered sdk extension.
|
|
||||||
bool _registeredSdkExtension(String libraryName) {
|
|
||||||
return _urlMappings[libraryName] != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -128,6 +83,26 @@ class SdkExtUriResolver extends UriResolver {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the library name of [importUri].
|
||||||
|
String _libraryName(Uri importUri) {
|
||||||
|
var uri = importUri.toString();
|
||||||
|
int index = uri.indexOf('/');
|
||||||
|
if (index >= 0) {
|
||||||
|
return uri.substring(0, index);
|
||||||
|
}
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the part path of [importUri].
|
||||||
|
String _partPath(Uri importUri) {
|
||||||
|
var uri = importUri.toString();
|
||||||
|
int index = uri.indexOf('/');
|
||||||
|
if (index >= 0) {
|
||||||
|
return uri.substring(index + 1);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/// Given a package [name] and a list of folders ([libDirs]),
|
/// Given a package [name] and a list of folders ([libDirs]),
|
||||||
/// add any found sdk extensions.
|
/// add any found sdk extensions.
|
||||||
void _processPackage(String name, List<Folder> libDirs) {
|
void _processPackage(String name, List<Folder> libDirs) {
|
||||||
|
@ -139,18 +114,6 @@ class SdkExtUriResolver extends UriResolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read the contents of [libDir]/[SDK_EXT_NAME] as a string.
|
|
||||||
/// Returns null if the file doesn't exist.
|
|
||||||
String _readDotSdkExt(Folder libDir) {
|
|
||||||
var file = libDir.getChild(SDK_EXT_NAME);
|
|
||||||
try {
|
|
||||||
return file.readAsStringSync();
|
|
||||||
} on FileSystemException catch (e) {
|
|
||||||
// File can't be read.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Given the JSON for an SDK extension ([sdkExtJSON]) and a folder
|
/// Given the JSON for an SDK extension ([sdkExtJSON]) and a folder
|
||||||
/// ([libDir]), setup the uri mapping.
|
/// ([libDir]), setup the uri mapping.
|
||||||
void _processSdkExt(String sdkExtJSON, Folder libDir) {
|
void _processSdkExt(String sdkExtJSON, Folder libDir) {
|
||||||
|
@ -176,4 +139,38 @@ class SdkExtUriResolver extends UriResolver {
|
||||||
var value = libDir.canonicalizePath(file);
|
var value = libDir.canonicalizePath(file);
|
||||||
_urlMappings[key] = value;
|
_urlMappings[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Read the contents of [libDir]/[SDK_EXT_NAME] as a string.
|
||||||
|
/// Returns null if the file doesn't exist.
|
||||||
|
String _readDotSdkExt(Folder libDir) {
|
||||||
|
var file = libDir.getChild(SDK_EXT_NAME);
|
||||||
|
try {
|
||||||
|
return file.readAsStringSync();
|
||||||
|
} on FileSystemException {
|
||||||
|
// File can't be read.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if [libraryName] is a registered sdk extension.
|
||||||
|
bool _registeredSdkExtension(String libraryName) {
|
||||||
|
return _urlMappings[libraryName] != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Resolve an import of an sdk extension.
|
||||||
|
Source _resolveEntry(Uri libraryEntry, Uri importUri) {
|
||||||
|
// Library entry.
|
||||||
|
JavaFile javaFile = new JavaFile.fromUri(libraryEntry);
|
||||||
|
return new FileBasedSource(javaFile, importUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Resolve a 'part' statement inside an sdk extension.
|
||||||
|
Source _resolvePart(Uri libraryEntry, String partPath, Uri importUri) {
|
||||||
|
// Library part.
|
||||||
|
var directory = pathos.dirname(libraryEntry.path);
|
||||||
|
var partUri = new Uri.file(pathos.join(directory, partPath));
|
||||||
|
assert(partUri.isAbsolute);
|
||||||
|
JavaFile javaFile = new JavaFile.fromUri(partUri);
|
||||||
|
return new FileBasedSource(javaFile, importUri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import 'dart:math' as math;
|
||||||
import 'package:analyzer/src/context/cache.dart'
|
import 'package:analyzer/src/context/cache.dart'
|
||||||
show CacheEntry, TargetedResult;
|
show CacheEntry, TargetedResult;
|
||||||
import 'package:analyzer/src/generated/constant.dart';
|
import 'package:analyzer/src/generated/constant.dart';
|
||||||
import 'package:analyzer/src/services/lint.dart';
|
|
||||||
import 'package:analyzer/src/task/dart.dart'
|
import 'package:analyzer/src/task/dart.dart'
|
||||||
show
|
show
|
||||||
HINTS,
|
HINTS,
|
||||||
|
|
|
@ -4,31 +4,10 @@
|
||||||
|
|
||||||
library test.source.sdk_ext;
|
library test.source.sdk_ext;
|
||||||
|
|
||||||
import 'package:analyzer/file_system/file_system.dart';
|
|
||||||
import 'package:analyzer/file_system/memory_file_system.dart';
|
import 'package:analyzer/file_system/memory_file_system.dart';
|
||||||
import 'package:analyzer/source/sdk_ext.dart';
|
import 'package:analyzer/source/sdk_ext.dart';
|
||||||
import 'package:unittest/unittest.dart';
|
import 'package:unittest/unittest.dart';
|
||||||
|
|
||||||
MemoryResourceProvider resourceProvider;
|
|
||||||
|
|
||||||
buildResourceProvider() {
|
|
||||||
resourceProvider = new MemoryResourceProvider();
|
|
||||||
resourceProvider.newFolder('/empty');
|
|
||||||
resourceProvider.newFolder('/tmp');
|
|
||||||
resourceProvider.newFile('/tmp/_sdkext', r'''
|
|
||||||
{
|
|
||||||
"dart:fox": "slippy.dart",
|
|
||||||
"dart:bear": "grizzly.dart",
|
|
||||||
"dart:relative": "../relative.dart",
|
|
||||||
"dart:deep": "deep/directory/file.dart",
|
|
||||||
"fart:loudly": "nomatter.dart"
|
|
||||||
}''');
|
|
||||||
}
|
|
||||||
|
|
||||||
clearResourceProvider() {
|
|
||||||
resourceProvider = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
groupSep = ' | ';
|
groupSep = ' | ';
|
||||||
group('SdkExtUriResolverTest', () {
|
group('SdkExtUriResolverTest', () {
|
||||||
|
@ -95,3 +74,23 @@ main() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MemoryResourceProvider resourceProvider;
|
||||||
|
|
||||||
|
buildResourceProvider() {
|
||||||
|
resourceProvider = new MemoryResourceProvider();
|
||||||
|
resourceProvider.newFolder('/empty');
|
||||||
|
resourceProvider.newFolder('/tmp');
|
||||||
|
resourceProvider.newFile('/tmp/_sdkext', r'''
|
||||||
|
{
|
||||||
|
"dart:fox": "slippy.dart",
|
||||||
|
"dart:bear": "grizzly.dart",
|
||||||
|
"dart:relative": "../relative.dart",
|
||||||
|
"dart:deep": "deep/directory/file.dart",
|
||||||
|
"fart:loudly": "nomatter.dart"
|
||||||
|
}''');
|
||||||
|
}
|
||||||
|
|
||||||
|
clearResourceProvider() {
|
||||||
|
resourceProvider = null;
|
||||||
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ import 'package:analyzer/src/generated/engine.dart'
|
||||||
import 'package:analyzer/src/generated/error.dart'
|
import 'package:analyzer/src/generated/error.dart'
|
||||||
show AnalysisError, HtmlErrorCode;
|
show AnalysisError, HtmlErrorCode;
|
||||||
import 'package:analyzer/src/generated/java_engine.dart' show CaughtException;
|
import 'package:analyzer/src/generated/java_engine.dart' show CaughtException;
|
||||||
import 'package:analyzer/src/generated/scanner.dart' show ScannerErrorCode;
|
|
||||||
import 'package:analyzer/src/generated/source.dart';
|
import 'package:analyzer/src/generated/source.dart';
|
||||||
import 'package:analyzer/src/task/driver.dart';
|
import 'package:analyzer/src/task/driver.dart';
|
||||||
import 'package:analyzer/src/task/html.dart';
|
import 'package:analyzer/src/task/html.dart';
|
||||||
|
|
Loading…
Reference in a new issue