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

Side by Side Diff: lib/src/checker/resolver.dart

Issue 988483006: Add widget to display errors, and report dependency_graph errors correctly (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /// Encapsulates how to invoke the analyzer resolver and overrides how it 5 /// Encapsulates how to invoke the analyzer resolver and overrides how it
6 /// computes types on expressions to use our restricted set of types. 6 /// computes types on expressions to use our restricted set of types.
7 library dev_compiler.src.checker.resolver; 7 library dev_compiler.src.checker.resolver;
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
11 import 'package:analyzer/src/generated/element.dart'; 11 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/engine.dart'; 12 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/error.dart'; 13 import 'package:analyzer/src/generated/error.dart' as analyzer;
14 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; 14 import 'package:analyzer/src/generated/java_io.dart' show JavaFile;
15 import 'package:analyzer/src/generated/resolver.dart'; 15 import 'package:analyzer/src/generated/resolver.dart';
16 import 'package:analyzer/src/generated/static_type_analyzer.dart'; 16 import 'package:analyzer/src/generated/static_type_analyzer.dart';
17 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; 17 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk;
18 import 'package:analyzer/src/generated/source.dart' show DartUriResolver; 18 import 'package:analyzer/src/generated/source.dart' show DartUriResolver;
19 import 'package:analyzer/src/generated/source.dart' show Source; 19 import 'package:analyzer/src/generated/source.dart' show Source;
20 import 'package:analyzer/src/generated/source_io.dart'; 20 import 'package:analyzer/src/generated/source_io.dart';
21 import 'package:logging/logging.dart' as logger; 21 import 'package:logging/logging.dart' as logger;
22 22
23 import 'package:dev_compiler/src/options.dart'; 23 import 'package:dev_compiler/src/options.dart';
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 /// Find the corresponding [Source] for [uri]. 67 /// Find the corresponding [Source] for [uri].
68 Source findSource(Uri uri) { 68 Source findSource(Uri uri) {
69 var source = _sources[uri]; 69 var source = _sources[uri];
70 if (source != null) return source; 70 if (source != null) return source;
71 return _sources[uri] = context.sourceFactory.forUri('$uri'); 71 return _sources[uri] = context.sourceFactory.forUri('$uri');
72 } 72 }
73 73
74 /// Log any errors encountered when resolving [source] and return whether any 74 /// Log any errors encountered when resolving [source] and return whether any
75 /// errors were found. 75 /// errors were found.
76 bool logErrors(Source source, CheckerReporter reporter) { 76 bool logErrors(Source source, CheckerReporter reporter) {
77 List<AnalysisError> errors = context.getErrors(source).errors; 77 List<analyzer.AnalysisError> errors = context.getErrors(source).errors;
78 bool failure = false; 78 bool failure = false;
79 if (errors.isNotEmpty) { 79 if (errors.isNotEmpty) {
80 for (var error in errors) { 80 for (var error in errors) {
81 var severity = error.errorCode.errorSeverity; 81 var message = new AnalyzerError.from(error);
82 var isError = severity == ErrorSeverity.ERROR; 82 if (message.level == logger.Level.SEVERE) failure = true;
83 if (isError) failure = true; 83 reporter.log(message);
Siggi Cherem (dart-lang) 2015/03/07 02:43:01 I am unifying the error reporting using the new [M
vsm 2015/03/09 15:14:36 Nice!
84 var level = isError ? logger.Level.SEVERE : logger.Level.WARNING;
85 reporter.logAnalyzerError(
86 error.message, level, error.offset, error.offset + error.length);
87 } 84 }
88 } 85 }
89 return failure; 86 return failure;
90 } 87 }
91 } 88 }
92 89
90 class AnalyzerError extends Message {
91 factory AnalyzerError.from(analyzer.AnalysisError error) {
92 var severity = error.errorCode.errorSeverity;
93 var isError = severity == analyzer.ErrorSeverity.ERROR;
94 var level = isError ? logger.Level.SEVERE : logger.Level.WARNING;
95 int begin = error.offset;
96 int end = begin + error.length;
97 return new AnalyzerError(error.message, level, begin, end);
98 }
99
100 const AnalyzerError(String message, logger.Level level, int begin, int end)
101 : super('[from analyzer]: $message', level, begin, end);
102 }
103
93 /// Creates an analysis context that contains our restricted typing rules. 104 /// Creates an analysis context that contains our restricted typing rules.
94 InternalAnalysisContext _initContext(ResolverOptions options) { 105 InternalAnalysisContext _initContext(ResolverOptions options) {
95 var analysisOptions = new AnalysisOptionsImpl()..cacheSize = 512; 106 var analysisOptions = new AnalysisOptionsImpl()..cacheSize = 512;
96 AnalysisContextImpl res = AnalysisEngine.instance.createAnalysisContext(); 107 AnalysisContextImpl res = AnalysisEngine.instance.createAnalysisContext();
97 res.analysisOptions = analysisOptions; 108 res.analysisOptions = analysisOptions;
98 res.resolverVisitorFactory = RestrictedResolverVisitor.constructor(options); 109 res.resolverVisitorFactory = RestrictedResolverVisitor.constructor(options);
99 if (options.inferFromOverrides) { 110 if (options.inferFromOverrides) {
100 res.typeResolverVisitorFactory = RestrictedTypeResolverVisitor.constructor; 111 res.typeResolverVisitorFactory = RestrictedTypeResolverVisitor.constructor;
101 } 112 }
102 return res; 113 return res;
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 element.returnType.isDynamic && 449 element.returnType.isDynamic &&
439 node.returnType == null) { 450 node.returnType == null) {
440 var type = searchTypeFor(element.enclosingElement.type, element); 451 var type = searchTypeFor(element.enclosingElement.type, element);
441 if (type != null && !type.returnType.isDynamic) { 452 if (type != null && !type.returnType.isDynamic) {
442 element.returnType = type.returnType; 453 element.returnType = type.returnType;
443 } 454 }
444 } 455 }
445 return res; 456 return res;
446 } 457 }
447 } 458 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698