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

Side by Side Diff: pkg/front_end/lib/src/fasta/testing/environment_variable.dart

Issue 2970273004: Deprecate all diagnostics methods that use strings. (Closed)
Patch Set: Merged with 4df146dd9a465d63344330bf3e45524b927c92ec Created 3 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 fasta.testing.environment_variable; 5 library fasta.testing.environment_variable;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'dart:io' show Directory, File, Platform; 9 import 'dart:io' show Directory, File, Platform;
10 10
11 import '../errors.dart' show inputError; 11 import '../deprecated_problems.dart' show deprecated_inputError;
12 12
13 class EnvironmentVariable { 13 class EnvironmentVariable {
14 final String name; 14 final String name;
15 15
16 final String what; 16 final String what;
17 17
18 const EnvironmentVariable(this.name, this.what); 18 const EnvironmentVariable(this.name, this.what);
19 19
20 Future<String> get value async { 20 Future<String> get value async {
21 String value = Platform.environment[name]; 21 String value = Platform.environment[name];
22 if (value == null) return variableNotDefined(); 22 if (value == null) return variableNotDefined();
23 await validate(value); 23 await validate(value);
24 return value; 24 return value;
25 } 25 }
26 26
27 Future<Null> validate(String value) => new Future<Null>.value(); 27 Future<Null> validate(String value) => new Future<Null>.value();
28 28
29 variableNotDefined() { 29 variableNotDefined() {
30 inputError( 30 deprecated_inputError(
31 null, null, "The environment variable '$name' isn't defined. $what"); 31 null, null, "The environment variable '$name' isn't defined. $what");
32 } 32 }
33 } 33 }
34 34
35 class EnvironmentVariableFile extends EnvironmentVariable { 35 class EnvironmentVariableFile extends EnvironmentVariable {
36 const EnvironmentVariableFile(String name, String what) : super(name, what); 36 const EnvironmentVariableFile(String name, String what) : super(name, what);
37 37
38 Future<Null> validate(String value) async { 38 Future<Null> validate(String value) async {
39 if (!await new File(value).exists()) notFound(value); 39 if (!await new File(value).exists()) notFound(value);
40 return null; 40 return null;
41 } 41 }
42 42
43 notFound(String value) { 43 notFound(String value) {
44 inputError( 44 deprecated_inputError(
45 null, 45 null,
46 null, 46 null,
47 "The environment variable '$name' has the value " 47 "The environment variable '$name' has the value "
48 "'$value', that isn't a file. $what"); 48 "'$value', that isn't a file. $what");
49 } 49 }
50 } 50 }
51 51
52 class EnvironmentVariableDirectory extends EnvironmentVariable { 52 class EnvironmentVariableDirectory extends EnvironmentVariable {
53 const EnvironmentVariableDirectory(String name, String what) 53 const EnvironmentVariableDirectory(String name, String what)
54 : super(name, what); 54 : super(name, what);
55 55
56 Future<Null> validate(String value) async { 56 Future<Null> validate(String value) async {
57 if (!await new Directory(value).exists()) notFound(value); 57 if (!await new Directory(value).exists()) notFound(value);
58 return null; 58 return null;
59 } 59 }
60 60
61 notFound(String value) { 61 notFound(String value) {
62 inputError( 62 deprecated_inputError(
63 null, 63 null,
64 null, 64 null,
65 "The environment variable '$name' has the value " 65 "The environment variable '$name' has the value "
66 "'$value', that isn't a directory. $what"); 66 "'$value', that isn't a directory. $what");
67 } 67 }
68 } 68 }
69 69
70 Future<bool> fileExists(Uri base, String path) async { 70 Future<bool> fileExists(Uri base, String path) async {
71 return await new File.fromUri(base.resolve(path)).exists(); 71 return await new File.fromUri(base.resolve(path)).exists();
72 } 72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698