Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(524)

Unified Diff: pkg/code_transformers/lib/src/resolver_impl.dart

Issue 335943003: merge to trunk all changes from 36817 until 37378 under the packages: polymer, (Closed) Base URL: http://dart.googlecode.com/svn/trunk/dart/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/code_transformers/lib/src/dart_sdk.dart ('k') | pkg/code_transformers/lib/src/resolvers.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/code_transformers/lib/src/resolver_impl.dart
===================================================================
--- pkg/code_transformers/lib/src/resolver_impl.dart (revision 37373)
+++ pkg/code_transformers/lib/src/resolver_impl.dart (working copy)
@@ -5,15 +5,13 @@
library code_transformer.src.resolver_impl;
import 'dart:async';
-import 'package:analyzer/analyzer.dart' show parseCompilationUnit;
+import 'package:analyzer/analyzer.dart' show parseDirectives;
import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator;
import 'package:analyzer/src/generated/constant.dart' show ConstantEvaluator,
EvaluationResult;
import 'package:analyzer/src/generated/element.dart';
import 'package:analyzer/src/generated/engine.dart';
-import 'package:analyzer/src/generated/java_io.dart';
import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
-import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk;
import 'package:analyzer/src/generated/source.dart';
import 'package:barback/barback.dart';
import 'package:code_transformers/assets.dart';
@@ -22,6 +20,7 @@
import 'package:source_maps/span.dart' show SourceFile, Span;
import 'resolver.dart';
+import 'dart_sdk.dart' show UriAnnotatedSource;
// We should always be using url paths here since it's always Dart/pub code.
final path = native_path.url;
@@ -51,12 +50,10 @@
/// Completer for wrapping up the current phase.
Completer _currentPhaseComplete;
- /// Handler for all Dart SDK (dart:) sources.
- DirectoryBasedDartSdk _dartSdk;
-
- /// Creates a resolver, where [sdkDir] is the root directory of the Dart SDK,
- /// for resolving `dart:*` imports.
- ResolverImpl(String sdkDir, {AnalysisOptions options}) {
+ /// Creates a resolver with a given [sdk] implementation for resolving
+ /// `dart:*` imports.
+ ResolverImpl(DartSdk sdk, DartUriResolver dartUriResolver,
+ {AnalysisOptions options}) {
if (options == null) {
options = new AnalysisOptionsImpl()
..cacheSize = 256 // # of sources to cache ASTs for.
@@ -64,12 +61,8 @@
..analyzeFunctionBodies = true;
}
_context.analysisOptions = options;
-
- _dartSdk = new _DirectoryBasedDartSdkProxy(new JavaFile(sdkDir));
- _dartSdk.context.analysisOptions = options;
-
- _context.sourceFactory = new SourceFactory([
- new DartUriResolverProxy(_dartSdk),
+ sdk.context.analysisOptions = options;
+ _context.sourceFactory = new SourceFactory([dartUriResolver,
new _AssetUriResolver(this)]);
}
@@ -248,7 +241,7 @@
var source = element.source;
if (source is _AssetBasedSource) {
return source.getSourceUri(from);
- } else if (source is _DartSourceProxy) {
+ } else if (source is UriAnnotatedSource) {
return source.uri;
}
// Should not be able to encounter any other source types.
@@ -320,7 +313,7 @@
/// any analyzer resolution.
void updateDependencies(String contents) {
if (contents == _contents) return;
- var unit = parseCompilationUnit(contents, suppressErrors: true);
+ var unit = parseDirectives(contents, suppressErrors: true);
_dependentAssets = unit.directives
.where((d) => (d is ImportDirective || d is PartDirective ||
d is ExportDirective))
@@ -453,86 +446,6 @@
TransformLogger get logger => _resolver._currentTransform.logger;
}
-
-/// Dart SDK which wraps all Dart sources to ensure they are tracked with Uris.
-///
-/// Just a simple wrapper to make it easy to make sure that all sources we
-/// encounter are either _AssetBasedSource or _DartSourceProxy.
-class _DirectoryBasedDartSdkProxy extends DirectoryBasedDartSdk {
- _DirectoryBasedDartSdkProxy(JavaFile sdkDirectory) : super(sdkDirectory);
-
- Source mapDartUri(String dartUri) =>
- _DartSourceProxy.wrap(super.mapDartUri(dartUri), Uri.parse(dartUri));
-}
-
-
-/// Dart SDK resolver which wraps all Dart sources to ensure they are tracked
-/// with URIs.
-class DartUriResolverProxy implements DartUriResolver {
- final DartUriResolver _proxy;
- DartUriResolverProxy(DirectoryBasedDartSdk sdk) :
- _proxy = new DartUriResolver(sdk);
-
- Source resolveAbsolute(Uri uri) =>
- _DartSourceProxy.wrap(_proxy.resolveAbsolute(uri), uri);
-
- DartSdk get dartSdk => _proxy.dartSdk;
-
- Source fromEncoding(UriKind kind, Uri uri) =>
- throw new UnsupportedError('fromEncoding is not supported');
-
- Uri restoreAbsolute(Source source) =>
- throw new UnsupportedError('restoreAbsolute is not supported');
-}
-
-/// Source file for dart: sources which track the sources with dart: URIs.
-///
-/// This is primarily to support [Resolver.getImportUri] for Dart SDK (dart:)
-/// based libraries.
-class _DartSourceProxy implements Source {
-
- /// Absolute URI which this source can be imported from
- final Uri uri;
-
- /// Underlying source object.
- final Source _proxy;
-
- _DartSourceProxy(this._proxy, this.uri);
-
- /// Ensures that [source] is a _DartSourceProxy.
- static _DartSourceProxy wrap(Source source, Uri uri) {
- if (source == null || source is _DartSourceProxy) return source;
- return new _DartSourceProxy(source, uri);
- }
-
- Source resolveRelative(Uri relativeUri) {
- // Assume that the type can be accessed via this URI, since these
- // should only be parts for dart core files.
- return wrap(_proxy.resolveRelative(relativeUri), uri);
- }
-
- bool exists() => _proxy.exists();
-
- bool operator ==(Object other) =>
- (other is _DartSourceProxy && _proxy == other._proxy);
-
- int get hashCode => _proxy.hashCode;
-
- TimestampedData<String> get contents => _proxy.contents;
-
- String get encoding => _proxy.encoding;
-
- String get fullName => _proxy.fullName;
-
- int get modificationStamp => _proxy.modificationStamp;
-
- String get shortName => _proxy.shortName;
-
- UriKind get uriKind => _proxy.uriKind;
-
- bool get isInSystemLibrary => _proxy.isInSystemLibrary;
-}
-
/// Get an asset ID for a URL relative to another source asset.
AssetId _resolve(AssetId source, String url, TransformLogger logger,
Span span) {
« no previous file with comments | « pkg/code_transformers/lib/src/dart_sdk.dart ('k') | pkg/code_transformers/lib/src/resolvers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698