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

Side by Side Diff: lib/src/utils.dart

Issue 1751963002: refactor/simplify nullable inference code (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 9 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /// Holds a couple utility functions used at various places in the system. 5 /// Holds a couple utility functions used at various places in the system.
6 6
7 import 'dart:io'; 7 import 'dart:io';
8
9 import 'package:path/path.dart' as path; 8 import 'package:path/path.dart' as path;
10 import 'package:analyzer/src/generated/ast.dart' 9 import 'package:analyzer/src/generated/ast.dart'
11 show 10 show
12 ImportDirective, 11 ImportDirective,
13 ExportDirective, 12 ExportDirective,
14 PartDirective, 13 PartDirective,
15 CompilationUnit, 14 CompilationUnit,
16 Identifier, 15 Identifier,
17 AnnotatedNode, 16 AnnotatedNode,
18 AstNode, 17 AstNode,
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 446
448 /// Gets the "simple" name of an enum value. 447 /// Gets the "simple" name of an enum value.
449 getEnumName(v) { 448 getEnumName(v) {
450 var parts = '$v'.split('.'); 449 var parts = '$v'.split('.');
451 if (parts.length != 2 || !parts.every((p) => p.isNotEmpty)) { 450 if (parts.length != 2 || !parts.every((p) => p.isNotEmpty)) {
452 throw new ArgumentError('Invalid enum value: $v'); 451 throw new ArgumentError('Invalid enum value: $v');
453 } 452 }
454 return parts[1]; 453 return parts[1];
455 } 454 }
456 455
457 /// Simplistic directed graph.
458 class DirectedGraph<V> {
459 final _adjacencyList = <V, Set<V>>{};
460
461 void addEdge(V from, V to) {
462 _adjacencyList.putIfAbsent(from, () => new Set<V>()).add(to);
463 }
464
465 /// Get all the vertices reachable from the provided [roots].
466 Set<V> getTransitiveClosure(Iterable<V> roots) {
467 final reached = new Set<V>();
468
469 visit(V e) {
470 if (reached.add(e)) {
471 var destinations = _adjacencyList[e];
472 if (destinations != null) destinations.forEach(visit);
473 }
474 }
475 roots.forEach(visit);
476
477 return reached;
478 }
479 }
480
481 class FileSystem { 456 class FileSystem {
482 const FileSystem(); 457 const FileSystem();
483 458
484 void _ensureParentExists(String file) { 459 void _ensureParentExists(String file) {
485 var dir = new Directory(path.dirname(file)); 460 var dir = new Directory(path.dirname(file));
486 if (!dir.existsSync()) dir.createSync(recursive: true); 461 if (!dir.existsSync()) dir.createSync(recursive: true);
487 } 462 }
488 463
489 void copySync(String source, String destination) { 464 void copySync(String source, String destination) {
490 _ensureParentExists(destination); 465 _ensureParentExists(destination);
491 new File(source).copySync(destination); 466 new File(source).copySync(destination);
492 } 467 }
493 468
494 void writeAsStringSync(String file, String contents) { 469 void writeAsStringSync(String file, String contents) {
495 _ensureParentExists(file); 470 _ensureParentExists(file);
496 new File(file).writeAsStringSync(contents); 471 new File(file).writeAsStringSync(contents);
497 } 472 }
498 } 473 }
474
475 DartType getStaticType(Expression e) =>
476 e.staticType ?? DynamicTypeImpl.instance;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698