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

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

Issue 1363993004: Report info messages together with their error, warning, or hint. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comment. Created 5 years, 2 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
« no previous file with comments | « tests/compiler/dart2js/mock_compiler.dart ('k') | tests/compiler/dart2js/parser_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 parser_helper; 5 library parser_helper;
6 6
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 8
9 import "package:compiler/src/elements/elements.dart"; 9 import "package:compiler/src/elements/elements.dart";
10 import "package:compiler/src/tree/tree.dart"; 10 import "package:compiler/src/tree/tree.dart";
(...skipping 19 matching lines...) Expand all
30 30
31 export "package:compiler/src/diagnostics/diagnostic_listener.dart"; 31 export "package:compiler/src/diagnostics/diagnostic_listener.dart";
32 export 'package:compiler/src/parser/listener.dart'; 32 export 'package:compiler/src/parser/listener.dart';
33 export 'package:compiler/src/parser/node_listener.dart'; 33 export 'package:compiler/src/parser/node_listener.dart';
34 export 'package:compiler/src/parser/parser.dart'; 34 export 'package:compiler/src/parser/parser.dart';
35 export 'package:compiler/src/parser/partial_parser.dart'; 35 export 'package:compiler/src/parser/partial_parser.dart';
36 export 'package:compiler/src/parser/partial_elements.dart'; 36 export 'package:compiler/src/parser/partial_elements.dart';
37 export "package:compiler/src/tokens/token.dart"; 37 export "package:compiler/src/tokens/token.dart";
38 export "package:compiler/src/tokens/token_constants.dart"; 38 export "package:compiler/src/tokens/token_constants.dart";
39 39
40 class LoggerCanceler implements DiagnosticListener { 40 class LoggerCanceler extends DiagnosticListener {
41 void log(message) { 41 void log(message) {
42 print(message); 42 print(message);
43 } 43 }
44 44
45 void internalError(node, String message) { 45 void internalError(node, String message) {
46 log(message); 46 log(message);
47 } 47 }
48 48
49 SourceSpan spanFromSpannable(node) { 49 SourceSpan spanFromSpannable(node) {
50 throw 'unsupported operation'; 50 throw 'unsupported operation';
51 } 51 }
52 52
53 void reportMessage(SourceSpan span, Message message, kind) { 53 void reportError(
54 DiagnosticMessage message,
55 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) {
54 log(message); 56 log(message);
57 infos.forEach(log);
55 } 58 }
56 59
57 void reportFatalError(Spannable node, 60 void reportWarning(
58 MessageKind errorCode, 61 DiagnosticMessage message,
59 [Map arguments]) { 62 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) {
60 log(new Message(MessageTemplate.TEMPLATES[errorCode], arguments, false)); 63 log(message);
61 } 64 infos.forEach(log);
62
63 void reportError(Spannable node, MessageKind errorCode, [Map arguments]) {
64 log(new Message(MessageTemplate.TEMPLATES[errorCode], arguments, false));
65 }
66
67 void reportWarning(Spannable node, MessageKind errorCode, [Map arguments]) {
68 log(new Message(MessageTemplate.TEMPLATES[errorCode], arguments, false));
69 } 65 }
70 66
71 void reportInfo(Spannable node, MessageKind errorCode, [Map arguments]) { 67 void reportInfo(Spannable node, MessageKind errorCode, [Map arguments]) {
72 log(new Message(MessageTemplate.TEMPLATES[errorCode], arguments, false)); 68 log(new Message(MessageTemplate.TEMPLATES[errorCode], arguments, false));
73 } 69 }
74 70
75 void reportHint(Spannable node, MessageKind errorCode, [Map arguments]) { 71 void reportHint(
76 log(new Message(MessageTemplate.TEMPLATES[errorCode], arguments, false)); 72 DiagnosticMessage message,
73 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) {
74 log(message);
75 infos.forEach(log);
77 } 76 }
78 77
79 withCurrentElement(Element element, f()) => f(); 78 withCurrentElement(Element element, f()) => f();
79
80 @override
81 DiagnosticMessage createMessage(
82 Spannable spannable,
83 MessageKind messageKind,
84 [Map arguments = const {}]) {
85 return new DiagnosticMessage(
86 null, spannable,
87 new Message(MessageTemplate.TEMPLATES[messageKind], arguments, false));
88 }
80 } 89 }
81 90
82 Token scan(String text) => 91 Token scan(String text) =>
83 new StringScanner.fromString(text) 92 new StringScanner.fromString(text)
84 .tokenize(); 93 .tokenize();
85 94
86 Node parseBodyCode(String text, Function parseMethod, 95 Node parseBodyCode(String text, Function parseMethod,
87 {DiagnosticListener diagnosticHandler}) { 96 {DiagnosticListener diagnosticHandler}) {
88 Token tokens = scan(text); 97 Token tokens = scan(text);
89 if (diagnosticHandler == null) diagnosticHandler = new LoggerCanceler(); 98 if (diagnosticHandler == null) diagnosticHandler = new LoggerCanceler();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 ElementListener listener = new ElementListener(compiler, unit, () => id++); 147 ElementListener listener = new ElementListener(compiler, unit, () => id++);
139 PartialParser parser = new PartialParser(listener); 148 PartialParser parser = new PartialParser(listener);
140 compiler.withCurrentElement(unit, () => parser.parseUnit(tokens)); 149 compiler.withCurrentElement(unit, () => parser.parseUnit(tokens));
141 return unit.localMembers; 150 return unit.localMembers;
142 } 151 }
143 152
144 NodeList fullParseUnit(String source, {DiagnosticListener diagnosticHandler}) { 153 NodeList fullParseUnit(String source, {DiagnosticListener diagnosticHandler}) {
145 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens), 154 return parseBodyCode(source, (parser, tokens) => parser.parseUnit(tokens),
146 diagnosticHandler: diagnosticHandler); 155 diagnosticHandler: diagnosticHandler);
147 } 156 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/mock_compiler.dart ('k') | tests/compiler/dart2js/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698