Index: tests/compiler/dart2js/memory_compiler.dart |
diff --git a/tests/compiler/dart2js/memory_compiler.dart b/tests/compiler/dart2js/memory_compiler.dart |
index 7a4a8090354743755d6165226fd3e9b9a6532315..44902d8c0e7d81930fba9117ae1dd4af199fa0da 100644 |
--- a/tests/compiler/dart2js/memory_compiler.dart |
+++ b/tests/compiler/dart2js/memory_compiler.dart |
@@ -6,15 +6,17 @@ library dart2js.test.memory_compiler; |
import 'memory_source_file_helper.dart'; |
-import 'package:compiler/src/compile_time_constants.dart'; |
-import 'package:compiler/src/dart2jslib.dart' |
- show NullSink; |
+import 'package:compiler/src/null_compiler_output.dart' |
+ show NullCompilerOutput; |
import 'package:compiler/compiler.dart' show |
- CompilerOutputProvider, |
+ DiagnosticHandler; |
+ |
+import 'package:compiler/compiler_new.dart' show |
+ CompilerDiagnostics, |
+ CompilerOutput, |
Diagnostic, |
- DiagnosticHandler, |
PackagesDiscoveryProvider; |
import 'dart:async'; |
@@ -25,6 +27,8 @@ import 'package:compiler/src/mirrors/analyze.dart'; |
import 'package:compiler/src/library_loader.dart' |
show LoadedLibraries; |
+import 'package:compiler/src/old_to_new_api.dart'; |
+ |
export 'output_collector.dart'; |
class DiagnosticMessage { |
@@ -39,11 +43,15 @@ class DiagnosticMessage { |
String toString() => '$uri:$begin:$end:$message:$kind'; |
} |
-class DiagnosticCollector { |
+class DiagnosticCollector implements CompilerDiagnostics { |
List<DiagnosticMessage> messages = <DiagnosticMessage>[]; |
- void call(Uri uri, int begin, int end, String message, |
- Diagnostic kind) { |
+ void call(Uri uri, int begin, int end, String message, Diagnostic kind) { |
+ report(uri, begin, end, message, kind); |
+ } |
+ |
+ @override |
+ void report(Uri uri, int begin, int end, String message, Diagnostic kind) { |
messages.add(new DiagnosticMessage(uri, begin, end, message, kind)); |
} |
@@ -67,24 +75,40 @@ class DiagnosticCollector { |
Iterable<DiagnosticMessage> get infos { |
return filterMessagesByKind(Diagnostic.INFO); |
} |
+ |
+ /// `true` if non-verbose messages has been collected. |
+ bool get hasRegularMessages { |
+ return messages.any((m) => m.kind != Diagnostic.VERBOSE_INFO); |
+ } |
} |
-DiagnosticHandler createDiagnosticHandler(DiagnosticHandler diagnosticHandler, |
- SourceFileProvider provider, |
- bool showDiagnostics) { |
- var handler = diagnosticHandler; |
+class MultiDiagnostics implements CompilerDiagnostics { |
+ final List<CompilerDiagnostics> diagnosticsList; |
+ |
+ const MultiDiagnostics([this.diagnosticsList = const []]); |
+ |
+ @override |
+ void report(Uri uri, int begin, int end, String message, Diagnostic kind) { |
+ for (CompilerDiagnostics diagnostics in diagnosticsList) { |
+ diagnostics.report(uri, begin, end, message, kind); |
+ } |
+ } |
+} |
+ |
+CompilerDiagnostics createCompilerDiagnostics( |
+ CompilerDiagnostics diagnostics, |
+ SourceFileProvider provider, |
+ bool showDiagnostics) { |
+ CompilerDiagnostics handler = diagnostics; |
if (showDiagnostics) { |
- if (diagnosticHandler == null) { |
+ if (diagnostics == null) { |
handler = new FormattingDiagnosticHandler(provider); |
} else { |
var formattingHandler = new FormattingDiagnosticHandler(provider); |
- handler = (Uri uri, int begin, int end, String message, Diagnostic kind) { |
- diagnosticHandler(uri, begin, end, message, kind); |
- formattingHandler(uri, begin, end, message, kind); |
- }; |
+ handler = new MultiDiagnostics([diagnostics, formattingHandler]); |
} |
- } else if (diagnosticHandler == null) { |
- handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {}; |
+ } else if (diagnostics == null) { |
+ handler = new MultiDiagnostics(); |
} |
return handler; |
} |
@@ -94,8 +118,8 @@ Expando<MemorySourceFileProvider> expando = |
Compiler compilerFor( |
Map<String, String> memorySourceFiles, |
- {DiagnosticHandler diagnosticHandler, |
- CompilerOutputProvider outputProvider, |
+ {CompilerDiagnostics diagnosticHandler, |
+ CompilerOutput outputProvider, |
List<String> options: const [], |
Compiler cachedCompiler, |
bool showDiagnostics: true, |
@@ -110,35 +134,28 @@ Compiler compilerFor( |
} |
MemorySourceFileProvider provider; |
- var readStringFromUri; |
if (cachedCompiler == null) { |
provider = new MemorySourceFileProvider(memorySourceFiles); |
- readStringFromUri = provider.readStringFromUri; |
// Saving the provider in case we need it later for a cached compiler. |
- expando[readStringFromUri] = provider; |
+ expando[provider] = provider; |
} else { |
// When using a cached compiler, it has read a number of files from disk |
// already (and will not attempt to read them again due to caching). These |
// files must be available to the new diagnostic handler. |
provider = expando[cachedCompiler.provider]; |
- readStringFromUri = cachedCompiler.provider; |
provider.memorySourceFiles = memorySourceFiles; |
} |
- var handler = |
- createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); |
+ diagnosticHandler = |
+ createCompilerDiagnostics(diagnosticHandler, provider, showDiagnostics); |
- EventSink<String> noOutputProvider(String name, String extension) { |
- if (name != '') throw 'Attempt to output file "$name.$extension"'; |
- return new NullSink('$name.$extension'); |
- } |
if (outputProvider == null) { |
- outputProvider = noOutputProvider; |
+ outputProvider = const NullCompilerOutput(); |
} |
Compiler compiler = new Compiler( |
- readStringFromUri, |
+ provider, |
outputProvider, |
- handler, |
+ diagnosticHandler, |
libraryRoot, |
packageRoot, |
options, |
@@ -236,6 +253,27 @@ class MemoryLoadedLibraries implements LoadedLibraries { |
Uri get rootUri => null; |
} |
+ |
+DiagnosticHandler createDiagnosticHandler(DiagnosticHandler diagnosticHandler, |
+ SourceFileProvider provider, |
+ bool showDiagnostics) { |
+ var handler = diagnosticHandler; |
+ if (showDiagnostics) { |
+ if (diagnosticHandler == null) { |
+ handler = new FormattingDiagnosticHandler(provider); |
+ } else { |
+ var formattingHandler = new FormattingDiagnosticHandler(provider); |
+ handler = (Uri uri, int begin, int end, String message, Diagnostic kind) { |
+ diagnosticHandler(uri, begin, end, message, kind); |
+ formattingHandler(uri, begin, end, message, kind); |
+ }; |
+ } |
+ } else if (diagnosticHandler == null) { |
+ handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {}; |
+ } |
+ return handler; |
+} |
+ |
Future<MirrorSystem> mirrorSystemFor(Map<String,String> memorySourceFiles, |
{DiagnosticHandler diagnosticHandler, |
List<String> options: const [], |