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

Side by Side Diff: pkg/analyzer/lib/file_system/physical_file_system.dart

Issue 372763003: Move file_system libraries into 'analyzer'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/file_system/memory_file_system.dart ('k') | pkg/analyzer/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 library physical_file_system;
6
7 import 'dart:async';
8 import 'dart:io' as io;
9
10 import 'package:analyzer/src/generated/java_io.dart';
11 import 'package:analyzer/src/generated/source_io.dart';
12 import 'package:path/path.dart';
13 import 'package:watcher/watcher.dart';
14
15 import 'file_system.dart';
16
17
18 /**
19 * A `dart:io` based implementation of [ResourceProvider].
20 */
21 class PhysicalResourceProvider implements ResourceProvider {
22 static final PhysicalResourceProvider INSTANCE =
23 new PhysicalResourceProvider._();
24
25 PhysicalResourceProvider._();
26
27 @override
28 Context get pathContext => io.Platform.isWindows ? windows : posix;
29
30 @override
31 Resource getResource(String path) {
32 if (io.FileSystemEntity.isDirectorySync(path)) {
33 io.Directory directory = new io.Directory(path);
34 return new _PhysicalFolder(directory);
35 } else {
36 io.File file = new io.File(path);
37 return new _PhysicalFile(file);
38 }
39 }
40 }
41
42
43 /**
44 * A `dart:io` based implementation of [File].
45 */
46 class _PhysicalFile extends _PhysicalResource implements File {
47 _PhysicalFile(io.File file) : super(file);
48
49 @override
50 Source createSource(UriKind uriKind) {
51 io.File file = _entry as io.File;
52 JavaFile javaFile = new JavaFile(file.absolute.path);
53 return new FileBasedSource.con2(javaFile, uriKind);
54 }
55 }
56
57
58 /**
59 * A `dart:io` based implementation of [Folder].
60 */
61 class _PhysicalFolder extends _PhysicalResource implements Folder {
62 _PhysicalFolder(io.Directory directory) : super(directory);
63
64 @override
65 Stream<WatchEvent> get changes => new DirectoryWatcher(_entry.path).events;
66
67 @override
68 String canonicalizePath(String relPath) {
69 return normalize(join(_entry.absolute.path, relPath));
70 }
71
72 @override
73 Resource getChild(String relPath) {
74 String canonicalPath = canonicalizePath(relPath);
75 return PhysicalResourceProvider.INSTANCE.getResource(canonicalPath);
76 }
77
78 @override
79 List<Resource> getChildren() {
80 List<Resource> children = <Resource>[];
81 io.Directory directory = _entry as io.Directory;
82 List<io.FileSystemEntity> entries = directory.listSync(recursive: false);
83 int numEntries = entries.length;
84 for (int i = 0; i < numEntries; i++) {
85 io.FileSystemEntity entity = entries[i];
86 if (entity is io.Directory) {
87 children.add(new _PhysicalFolder(entity));
88 } else if (entity is io.File) {
89 children.add(new _PhysicalFile(entity));
90 }
91 }
92 return children;
93 }
94 }
95
96
97 /**
98 * A `dart:io` based implementation of [Resource].
99 */
100 abstract class _PhysicalResource implements Resource {
101 final io.FileSystemEntity _entry;
102
103 _PhysicalResource(this._entry);
104
105 @override
106 bool get exists => _entry.existsSync();
107
108 @override
109 get hashCode => path.hashCode;
110
111 @override
112 Folder get parent {
113 String parentPath = dirname(path);
114 if (parentPath == path) {
115 return null;
116 }
117 return new _PhysicalFolder(new io.Directory(parentPath));
118 }
119
120 @override
121 String get path => _entry.absolute.path;
122
123 @override
124 String get shortName => basename(path);
125
126 @override
127 bool operator ==(other) {
128 if (runtimeType != other.runtimeType) {
129 return false;
130 }
131 return path == other.path;
132 }
133
134 @override
135 String toString() => path;
136 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/file_system/memory_file_system.dart ('k') | pkg/analyzer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698