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

Unified Diff: lib/src/in_memory.dart

Issue 1130093007: Create html if needed in server mode (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 7 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
Index: lib/src/in_memory.dart
diff --git a/lib/src/in_memory.dart b/lib/src/in_memory.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c8244c84e389751d76a78115194ddaf8452f35da
--- /dev/null
+++ b/lib/src/in_memory.dart
@@ -0,0 +1,94 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library dev_compiler.src.in_memory;
+
+import 'package:analyzer/src/generated/ast.dart';
+import 'package:analyzer/src/generated/engine.dart' show TimestampedData;
+import 'package:analyzer/src/generated/source.dart';
+import 'package:path/path.dart' as path;
+import 'package:source_span/source_span.dart';
+
+import 'dependency_graph.dart' show runtimeFilesForServerMode;
+
+/// Uri resolver that can load test files from memory.
+class InMemoryUriResolver extends UriResolver {
Jennifer Messerly 2015/05/13 19:31:55 UPDATE: just saw this was from our tests (next fil
vsm 2015/05/14 00:04:08 Yeah, this is just the old stuff with s/Test/InMem
Jennifer Messerly 2015/05/14 14:43:15 yeah, i'm happy to help too. Fun to delete code :)
+ final Map<Uri, InMemorySource> files = <Uri, InMemorySource>{};
+
+ /// Whether to represent a non-existing file with a [TestSource] (default
+ /// behavior from analyzer), or to use null (possible when overriding the
+ /// package-url-resolvers.)
+ final bool representNonExistingFiles;
+
+ InMemoryUriResolver(Map<String, String> allFiles,
+ {this.representNonExistingFiles: true}) {
+ allFiles.forEach((key, value) {
+ var uri = key.startsWith('package:') ? Uri.parse(key) : new Uri.file(key);
Jennifer Messerly 2015/05/13 19:31:55 IMO we need a helper for this ... I've seen this c
+ files[uri] = new InMemorySource(uri, value);
+ });
+
+ // TODO(vsm): Separate flag here?
+ if (representNonExistingFiles) {
+ runtimeFilesForServerMode.forEach((filepath) {
+ var uri = Uri.parse('/dev_compiler_runtime/$filepath');
+ files[uri] =
+ new InMemorySource(uri, '/* test contents of $filepath */');
+ });
+ }
+ }
+
+ Source resolveAbsolute(Uri uri) {
+ if (uri.scheme != 'file' && uri.scheme != 'package') return null;
+ if (!representNonExistingFiles) return files[uri];
+ return files.putIfAbsent(uri, () => new InMemorySource(uri, null));
+ }
+}
+
+class InMemoryContents implements TimestampedData<String> {
Jennifer Messerly 2015/05/13 19:31:55 this looks like TimestampedData<String> ? why anot
+ int modificationTime;
+ String data;
+
+ InMemoryContents(this.modificationTime, this.data);
+}
+
+/// An in memory source file.
+class InMemorySource implements Source {
Jennifer Messerly 2015/05/13 19:31:55 could we replace this with _MemoryFileSource in me
+ final Uri uri;
+ InMemoryContents contents;
+ final SourceFile _file;
+ final UriKind uriKind;
+
+ InMemorySource(uri, contents)
+ : uri = uri,
+ contents = new InMemoryContents(1, contents),
+ _file = contents != null ? new SourceFile(contents, url: uri) : null,
+ uriKind = uri.scheme == 'file' ? UriKind.FILE_URI : UriKind.PACKAGE_URI;
+
+ bool exists() => contents.data != null;
+
+ Source get source => this;
+
+ String _encoding;
+ String get encoding => _encoding != null ? _encoding : (_encoding = '$uri');
+
+ String get fullName => uri.path;
+
+ int get modificationStamp => contents.modificationTime;
+ String get shortName => path.basename(uri.path);
+
+ operator ==(other) => other is InMemorySource && uri == other.uri;
+ int get hashCode => uri.hashCode;
+ bool get isInSystemLibrary => false;
+
+ Uri resolveRelativeUri(Uri relativeUri) => uri.resolveUri(relativeUri);
+
+ SourceSpan spanFor(AstNode node) {
+ final begin = node is AnnotatedNode
+ ? node.firstTokenAfterCommentAndMetadata.offset
+ : node.offset;
+ return _file.span(begin, node.end);
+ }
+
+ String toString() => '[$runtimeType: $uri]';
+}
« lib/devc.dart ('K') | « lib/src/checker/resolver.dart ('k') | lib/src/testing.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698