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

Side by Side Diff: tests/compiler/dart2js/memory_compiler.dart

Issue 1247773002: Add access the Message in CompilerDiagnostics.report. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comment. Created 5 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 dart2js.test.memory_compiler; 5 library dart2js.test.memory_compiler;
6 6
7 import 'memory_source_file_helper.dart'; 7 import 'memory_source_file_helper.dart';
8 8
9 9
10 import 'package:compiler/src/null_compiler_output.dart' 10 import 'package:compiler/src/null_compiler_output.dart' show
11 show NullCompilerOutput; 11 NullCompilerOutput;
12
13 import 'package:compiler/src/dart2jslib.dart' show
14 Message;
12 15
13 import 'package:compiler/compiler.dart' show 16 import 'package:compiler/compiler.dart' show
14 DiagnosticHandler; 17 DiagnosticHandler;
15 18
16 import 'package:compiler/compiler_new.dart' show 19 import 'package:compiler/compiler_new.dart' show
20 CompilationResult,
17 CompilerDiagnostics, 21 CompilerDiagnostics,
18 CompilerOutput, 22 CompilerOutput,
19 Diagnostic, 23 Diagnostic,
20 PackagesDiscoveryProvider; 24 PackagesDiscoveryProvider;
21 25
22 import 'dart:async'; 26 import 'dart:async';
23 27
24 import 'package:compiler/src/mirrors/source_mirrors.dart'; 28 import 'package:compiler/src/mirrors/source_mirrors.dart';
25 import 'package:compiler/src/mirrors/analyze.dart'; 29 import 'package:compiler/src/mirrors/analyze.dart';
26 30
27 import 'package:compiler/src/library_loader.dart' 31 import 'package:compiler/src/library_loader.dart'
28 show LoadedLibraries; 32 show LoadedLibraries;
29 33
30 import 'package:compiler/src/old_to_new_api.dart';
31
32 export 'output_collector.dart'; 34 export 'output_collector.dart';
35 export 'package:compiler/compiler_new.dart' show
36 CompilationResult;
33 37
34 class DiagnosticMessage { 38 class DiagnosticMessage {
39 final Message message;
35 final Uri uri; 40 final Uri uri;
36 final int begin; 41 final int begin;
37 final int end; 42 final int end;
38 final String message; 43 final String text;
39 final Diagnostic kind; 44 final Diagnostic kind;
40 45
41 DiagnosticMessage(this.uri, this.begin, this.end, this.message, this.kind); 46 DiagnosticMessage(
47 this.message, this.uri, this.begin, this.end, this.text, this.kind);
42 48
43 String toString() => '$uri:$begin:$end:$message:$kind'; 49 String toString() => '$uri:$begin:$end:$text:$kind';
44 } 50 }
45 51
46 class DiagnosticCollector implements CompilerDiagnostics { 52 class DiagnosticCollector implements CompilerDiagnostics {
47 List<DiagnosticMessage> messages = <DiagnosticMessage>[]; 53 List<DiagnosticMessage> messages = <DiagnosticMessage>[];
48 54
49 void call(Uri uri, int begin, int end, String message, Diagnostic kind) { 55 void call(Uri uri, int begin, int end, String message, Diagnostic kind) {
50 report(uri, begin, end, message, kind); 56 report(null, uri, begin, end, message, kind);
51 } 57 }
52 58
53 @override 59 @override
54 void report(Uri uri, int begin, int end, String message, Diagnostic kind) { 60 void report(Message message,
55 messages.add(new DiagnosticMessage(uri, begin, end, message, kind)); 61 Uri uri, int begin, int end, String text, Diagnostic kind) {
62 messages.add(new DiagnosticMessage(message, uri, begin, end, text, kind));
56 } 63 }
57 64
58 Iterable<DiagnosticMessage> filterMessagesByKind(Diagnostic kind) { 65 Iterable<DiagnosticMessage> filterMessagesByKind(Diagnostic kind) {
59 return messages.where( 66 return messages.where(
60 (DiagnosticMessage message) => message.kind == kind); 67 (DiagnosticMessage message) => message.kind == kind);
61 } 68 }
62 69
63 Iterable<DiagnosticMessage> get errors { 70 Iterable<DiagnosticMessage> get errors {
64 return filterMessagesByKind(Diagnostic.ERROR); 71 return filterMessagesByKind(Diagnostic.ERROR);
65 } 72 }
(...skipping 15 matching lines...) Expand all
81 return messages.any((m) => m.kind != Diagnostic.VERBOSE_INFO); 88 return messages.any((m) => m.kind != Diagnostic.VERBOSE_INFO);
82 } 89 }
83 } 90 }
84 91
85 class MultiDiagnostics implements CompilerDiagnostics { 92 class MultiDiagnostics implements CompilerDiagnostics {
86 final List<CompilerDiagnostics> diagnosticsList; 93 final List<CompilerDiagnostics> diagnosticsList;
87 94
88 const MultiDiagnostics([this.diagnosticsList = const []]); 95 const MultiDiagnostics([this.diagnosticsList = const []]);
89 96
90 @override 97 @override
91 void report(Uri uri, int begin, int end, String message, Diagnostic kind) { 98 void report(Message message, Uri uri, int begin, int end,
99 String text, Diagnostic kind) {
92 for (CompilerDiagnostics diagnostics in diagnosticsList) { 100 for (CompilerDiagnostics diagnostics in diagnosticsList) {
93 diagnostics.report(uri, begin, end, message, kind); 101 diagnostics.report(message, uri, begin, end, text, kind);
94 } 102 }
95 } 103 }
96 } 104 }
97 105
98 CompilerDiagnostics createCompilerDiagnostics( 106 CompilerDiagnostics createCompilerDiagnostics(
99 CompilerDiagnostics diagnostics, 107 CompilerDiagnostics diagnostics,
100 SourceFileProvider provider, 108 SourceFileProvider provider,
101 bool showDiagnostics) { 109 bool showDiagnostics) {
102 CompilerDiagnostics handler = diagnostics; 110 CompilerDiagnostics handler = diagnostics;
103 if (showDiagnostics) { 111 if (showDiagnostics) {
104 if (diagnostics == null) { 112 if (diagnostics == null) {
105 handler = new FormattingDiagnosticHandler(provider); 113 handler = new FormattingDiagnosticHandler(provider);
106 } else { 114 } else {
107 var formattingHandler = new FormattingDiagnosticHandler(provider); 115 var formattingHandler = new FormattingDiagnosticHandler(provider);
108 handler = new MultiDiagnostics([diagnostics, formattingHandler]); 116 handler = new MultiDiagnostics([diagnostics, formattingHandler]);
109 } 117 }
110 } else if (diagnostics == null) { 118 } else if (diagnostics == null) {
111 handler = new MultiDiagnostics(); 119 handler = new MultiDiagnostics();
112 } 120 }
113 return handler; 121 return handler;
114 } 122 }
115 123
116 Expando<MemorySourceFileProvider> expando = 124 Expando<MemorySourceFileProvider> expando =
117 new Expando<MemorySourceFileProvider>(); 125 new Expando<MemorySourceFileProvider>();
118 126
127 Future<CompilationResult> runCompiler(
128 {Map<String, String> memorySourceFiles: const <String, String>{},
129 Uri entryPoint,
130 List<Uri> entryPoints,
131 CompilerDiagnostics diagnosticHandler,
132 CompilerOutput outputProvider,
133 List<String> options: const <String>[],
134 Compiler cachedCompiler,
135 bool showDiagnostics: true,
136 Uri packageRoot,
137 Uri packageConfig,
138 PackagesDiscoveryProvider packagesDiscoveryProvider,
139 void beforeRun(Compiler compiler)}) async {
140 if (entryPoint == null) {
141 entryPoint = Uri.parse('memory:main.dart');
142 }
143 Compiler compiler = compilerFor(
144 memorySourceFiles,
145 diagnosticHandler: diagnosticHandler,
146 outputProvider: outputProvider,
147 options: options,
148 cachedCompiler: cachedCompiler,
149 showDiagnostics: showDiagnostics,
150 packageRoot: packageRoot,
151 packageConfig: packageConfig,
152 packagesDiscoveryProvider: packagesDiscoveryProvider);
153 compiler.librariesToAnalyzeWhenRun = entryPoints;
154 if (beforeRun != null) {
155 beforeRun(compiler);
156 }
157 bool isSuccess = await compiler.run(entryPoint);
158 return new CompilationResult(compiler, isSuccess: isSuccess);
159 }
160
119 Compiler compilerFor( 161 Compiler compilerFor(
120 Map<String, String> memorySourceFiles, 162 Map<String, String> memorySourceFiles,
121 {CompilerDiagnostics diagnosticHandler, 163 {CompilerDiagnostics diagnosticHandler,
122 CompilerOutput outputProvider, 164 CompilerOutput outputProvider,
123 List<String> options: const [], 165 List<String> options: const <String>[],
124 Compiler cachedCompiler, 166 Compiler cachedCompiler,
125 bool showDiagnostics: true, 167 bool showDiagnostics: true,
126 Uri packageRoot, 168 Uri packageRoot,
127 Uri packageConfig, 169 Uri packageConfig,
128 PackagesDiscoveryProvider packagesDiscoveryProvider}) { 170 PackagesDiscoveryProvider packagesDiscoveryProvider}) {
129 Uri libraryRoot = Uri.base.resolve('sdk/'); 171 Uri libraryRoot = Uri.base.resolve('sdk/');
130 if (packageRoot == null && 172 if (packageRoot == null &&
131 packageConfig == null && 173 packageConfig == null &&
132 packagesDiscoveryProvider == null) { 174 packagesDiscoveryProvider == null) {
133 packageRoot = Uri.base.resolveUri(new Uri.file('${Platform.packageRoot}/')); 175 packageRoot = Uri.base.resolveUri(new Uri.file('${Platform.packageRoot}/'));
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); 329 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics);
288 330
289 List<Uri> libraries = <Uri>[]; 331 List<Uri> libraries = <Uri>[];
290 memorySourceFiles.forEach((String path, _) { 332 memorySourceFiles.forEach((String path, _) {
291 libraries.add(new Uri(scheme: 'memory', path: path)); 333 libraries.add(new Uri(scheme: 'memory', path: path));
292 }); 334 });
293 335
294 return analyze(libraries, libraryRoot, packageRoot, 336 return analyze(libraries, libraryRoot, packageRoot,
295 provider, handler, options); 337 provider, handler, options);
296 } 338 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/import_mirrors_test.dart ('k') | tests/compiler/dart2js/missing_file_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698