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

Side by Side Diff: pkg/analyzer/lib/src/generated/source_io.dart

Issue 1933763002: Use null-aware operators to clean up the code (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Additional clean-up Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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 library analyzer.src.generated.source_io; 5 library analyzer.src.generated.source_io;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/java_core.dart'; 10 import 'package:analyzer/src/generated/java_core.dart';
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 * The cached encoding for this source. 169 * The cached encoding for this source.
170 */ 170 */
171 String _encoding; 171 String _encoding;
172 172
173 /** 173 /**
174 * Initialize a newly created source object to represent the given [file]. If 174 * Initialize a newly created source object to represent the given [file]. If
175 * a [uri] is given, then it will be used as the URI from which the source was 175 * a [uri] is given, then it will be used as the URI from which the source was
176 * derived, otherwise a `file:` URI will be created based on the [file]. 176 * derived, otherwise a `file:` URI will be created based on the [file].
177 */ 177 */
178 FileBasedSource(JavaFile file, [Uri uri]) 178 FileBasedSource(JavaFile file, [Uri uri])
179 : this.uri = (uri == null ? file.toURI() : uri), 179 : this.uri = uri ?? file.toURI(),
180 this.file = file, 180 this.file = file,
181 id = _idTable.putIfAbsent( 181 id = _idTable.putIfAbsent(
182 '${uri == null ? file.toURI() : uri}@${file.getPath()}', 182 '${uri ?? file.toURI()}@${file.getPath()}', () => _idTable.length);
183 () => _idTable.length);
184 183
185 @override 184 @override
186 TimestampedData<String> get contents { 185 TimestampedData<String> get contents {
187 return PerformanceStatistics.io.makeCurrentWhile(() { 186 return PerformanceStatistics.io.makeCurrentWhile(() {
188 return contentsFromFile; 187 return contentsFromFile;
189 }); 188 });
190 } 189 }
191 190
192 /** 191 /**
193 * Get the contents and timestamp of the underlying file. 192 * Get the contents and timestamp of the underlying file.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 /** 261 /**
263 * The name of the `file` scheme. 262 * The name of the `file` scheme.
264 */ 263 */
265 static String FILE_SCHEME = "file"; 264 static String FILE_SCHEME = "file";
266 265
267 @override 266 @override
268 Source resolveAbsolute(Uri uri, [Uri actualUri]) { 267 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
269 if (!isFileUri(uri)) { 268 if (!isFileUri(uri)) {
270 return null; 269 return null;
271 } 270 }
272 return new FileBasedSource( 271 return new FileBasedSource(new JavaFile.fromUri(uri), actualUri ?? uri);
273 new JavaFile.fromUri(uri), actualUri != null ? actualUri : uri);
274 } 272 }
275 273
276 @override 274 @override
277 Uri restoreAbsolute(Source source) { 275 Uri restoreAbsolute(Source source) {
278 return new Uri.file(source.fullName); 276 return new Uri.file(source.fullName);
279 } 277 }
280 278
281 /** 279 /**
282 * Return `true` if the given URI is a `file` URI. 280 * Return `true` if the given URI is a `file` URI.
283 * 281 *
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 return new FileBasedSource(canonicalFile, actualUri); 447 return new FileBasedSource(canonicalFile, actualUri);
450 } 448 }
451 if (_isSelfReference(packagesDirectory, canonicalFile)) { 449 if (_isSelfReference(packagesDirectory, canonicalFile)) {
452 uri = canonicalFile.toURI(); 450 uri = canonicalFile.toURI();
453 } 451 }
454 return new FileBasedSource(canonicalFile, uri); 452 return new FileBasedSource(canonicalFile, uri);
455 } 453 }
456 } 454 }
457 return new FileBasedSource( 455 return new FileBasedSource(
458 getCanonicalFile(_packagesDirectories[0], pkgName, relPath), 456 getCanonicalFile(_packagesDirectories[0], pkgName, relPath),
459 actualUri != null ? actualUri : uri); 457 actualUri ?? uri);
460 } 458 }
461 459
462 @override 460 @override
463 Uri restoreAbsolute(Source source) { 461 Uri restoreAbsolute(Source source) {
464 String sourceUri = _toFileUri(source.fullName); 462 String sourceUri = _toFileUri(source.fullName);
465 for (JavaFile packagesDirectory in _packagesDirectories) { 463 for (JavaFile packagesDirectory in _packagesDirectories) {
466 List<JavaFile> pkgFolders = packagesDirectory.listFiles(); 464 List<JavaFile> pkgFolders = packagesDirectory.listFiles();
467 if (pkgFolders != null) { 465 if (pkgFolders != null) {
468 for (JavaFile pkgFolder in pkgFolders) { 466 for (JavaFile pkgFolder in pkgFolders) {
469 try { 467 try {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 536
539 @override 537 @override
540 Source resolveAbsolute(Uri uri, [Uri actualUri]) { 538 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
541 String rootPath = _rootDirectory.toURI().path; 539 String rootPath = _rootDirectory.toURI().path;
542 String uriPath = uri.path; 540 String uriPath = uri.path;
543 if (uriPath != null && uriPath.startsWith(rootPath)) { 541 if (uriPath != null && uriPath.startsWith(rootPath)) {
544 String filePath = uri.path.substring(rootPath.length); 542 String filePath = uri.path.substring(rootPath.length);
545 for (JavaFile dir in _relativeDirectories) { 543 for (JavaFile dir in _relativeDirectories) {
546 JavaFile file = new JavaFile.relative(dir, filePath); 544 JavaFile file = new JavaFile.relative(dir, filePath);
547 if (file.exists()) { 545 if (file.exists()) {
548 return new FileBasedSource(file, actualUri != null ? actualUri : uri); 546 return new FileBasedSource(file, actualUri ?? uri);
549 } 547 }
550 } 548 }
551 } 549 }
552 return null; 550 return null;
553 } 551 }
554 552
555 /** 553 /**
556 * Return `true` if the given URI is a `file` URI. 554 * Return `true` if the given URI is a `file` URI.
557 * 555 *
558 * @param uri the URI being tested 556 * @param uri the URI being tested
559 * @return `true` if the given URI is a `file` URI 557 * @return `true` if the given URI is a `file` URI
560 */ 558 */
561 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; 559 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME;
562 } 560 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/source.dart ('k') | pkg/analyzer/lib/src/task/strong/checker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698