Skip to content

Commit

Permalink
fixes #25, most analyzer errors were not computed
Browse files Browse the repository at this point in the history
It helps to call computeErrors ;)

R=vsm@google.com

Review URL: https://codereview.chromium.org/1183733004.
  • Loading branch information
John Messerly committed Jun 15, 2015
1 parent d1a4c5d commit b769aa5
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 40 deletions.
19 changes: 15 additions & 4 deletions pkg/dev_compiler/lib/devc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:analyzer/src/generated/error.dart' as analyzer;
import 'package:analyzer/src/generated/error.dart'
show AnalysisError, ErrorSeverity, ErrorType;
import 'package:analyzer/src/generated/engine.dart'
show AnalysisContext, ChangeSet;
import 'package:analyzer/src/generated/source.dart' show Source;
Expand All @@ -27,7 +28,7 @@ import 'src/codegen/html_codegen.dart';
import 'src/codegen/js_codegen.dart';
import 'src/dependency_graph.dart';
import 'src/info.dart'
show AnalyzerError, CheckerResults, LibraryInfo, LibraryUnit;
show AnalyzerMessage, CheckerResults, LibraryInfo, LibraryUnit;
import 'src/options.dart';
import 'src/report.dart';
import 'src/utils.dart';
Expand Down Expand Up @@ -201,11 +202,21 @@ class Compiler implements AbstractCompiler {
/// Log any errors encountered when resolving [source] and return whether any
/// errors were found.
bool logErrors(Source source) {
List<analyzer.AnalysisError> errors = context.getErrors(source).errors;
context.computeErrors(source);
List<AnalysisError> errors = context.getErrors(source).errors;
bool failure = false;
if (errors.isNotEmpty) {
for (var error in errors) {
var message = new AnalyzerError.from(error);
// Always skip TODOs.
if (error.errorCode.type == ErrorType.TODO) continue;

// Skip hints for now. In the future these could be turned on via flags.
if (error.errorCode.errorSeverity.ordinal <
ErrorSeverity.WARNING.ordinal) {
continue;
}

var message = new AnalyzerMessage.from(error);
if (message.level == Level.SEVERE) failure = true;
_reporter.log(message);
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/dev_compiler/lib/src/info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ library dev_compiler.src.info;

import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/element.dart';
import 'package:analyzer/src/generated/error.dart' as analyzer;
import 'package:analyzer/src/generated/error.dart'
show AnalysisError, ErrorSeverity;
import 'package:logging/logging.dart' show Level;

import 'package:dev_compiler/src/checker/rules.dart';
Expand Down Expand Up @@ -528,16 +529,16 @@ class InvalidSuperInvocation extends StaticError {
"(see http://goo.gl/q1T4BB): $node";
}

class AnalyzerError extends Message {
factory AnalyzerError.from(analyzer.AnalysisError error) {
class AnalyzerMessage extends Message {
factory AnalyzerMessage.from(AnalysisError error) {
var severity = error.errorCode.type.severity;
var isError = severity == analyzer.ErrorSeverity.WARNING;
var isError = severity == ErrorSeverity.WARNING;
var level = isError ? Level.SEVERE : Level.WARNING;
int begin = error.offset;
int end = begin + error.length;
return new AnalyzerError(error.message, level, begin, end);
return new AnalyzerMessage(error.message, level, begin, end);
}

const AnalyzerError(String message, Level level, int begin, int end)
const AnalyzerMessage(String message, Level level, int begin, int end)
: super(message, level, begin, end);
}
3 changes: 3 additions & 0 deletions pkg/dev_compiler/test/codegen/expect/temps.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
// Messages from compiling temps.dart
warning: line 16, column 22 of test/codegen/temps.dart: [AnalyzerMessage] Named optional parameters cannot start with an underscore
OptionalArg.named({this._opt: 456});
^^^^^^^^^
6 changes: 4 additions & 2 deletions pkg/dev_compiler/test/report_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ void main() {

_verifySummary(GlobalSummary summary) {
var mainLib = summary.loose['file:///main.dart'];
expect(mainLib.messages.length, 1);
expect(mainLib.messages.length, 2);
var analyzerMsg = mainLib.messages[0];
expect(analyzerMsg.kind, "AnalyzerMessage");

var mainMessage = mainLib.messages[0];
var mainMessage = mainLib.messages[1];
expect(mainMessage.kind, "StaticTypeError");
expect(mainMessage.level, "severe");
expect(mainMessage.span.text, '"hi"');
Expand Down
Loading

0 comments on commit b769aa5

Please sign in to comment.