| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library computer.error; |
| 6 |
| 7 import 'package:analysis_server/src/computer/element.dart'; |
| 8 import 'package:analysis_services/constants.dart'; |
| 9 import 'package:analysis_services/json.dart'; |
| 10 import 'package:analyzer/src/generated/error.dart' as engine; |
| 11 import 'package:analyzer/src/generated/source.dart' as engine; |
| 12 |
| 13 |
| 14 /** |
| 15 * An indication of an error, warning, or hint that was produced by the |
| 16 * analysis. |
| 17 */ |
| 18 class AnalysisError implements HasToJson { |
| 19 final String severity; |
| 20 final String type; |
| 21 final Location location; |
| 22 final String message; |
| 23 final String correction; |
| 24 |
| 25 AnalysisError(this.severity, this.type, this.location, this.message, |
| 26 this.correction); |
| 27 |
| 28 factory AnalysisError.fromEngine(engine.LineInfo lineInfo, |
| 29 engine.AnalysisError error) { |
| 30 engine.ErrorCode errorCode = error.errorCode; |
| 31 // prepare location |
| 32 Location location; |
| 33 { |
| 34 String file = error.source.fullName; |
| 35 int offset = error.offset; |
| 36 int length = error.length; |
| 37 int startLine = -1; |
| 38 int startColumn = -1; |
| 39 if (lineInfo != null) { |
| 40 engine.LineInfo_Location lineLocation = lineInfo.getLocation(offset); |
| 41 if (lineLocation != null) { |
| 42 startLine = lineLocation.lineNumber; |
| 43 startColumn = lineLocation.columnNumber; |
| 44 } |
| 45 } |
| 46 location = new Location(file, offset, length, startLine, startColumn); |
| 47 } |
| 48 // done |
| 49 String severity = errorCode.errorSeverity.toString(); |
| 50 String type = errorCode.type.toString(); |
| 51 String message = error.message; |
| 52 String correction = errorCode.correction; |
| 53 return new AnalysisError(severity, type, location, message, correction); |
| 54 } |
| 55 |
| 56 @override |
| 57 Map<String, Object> toJson() { |
| 58 Map<String, Object> json = { |
| 59 SEVERITY: severity, |
| 60 TYPE: type, |
| 61 LOCATION: location.toJson(), |
| 62 MESSAGE: message |
| 63 }; |
| 64 if (correction != null) { |
| 65 json[CORRECTION] = correction; |
| 66 } |
| 67 return json; |
| 68 } |
| 69 |
| 70 @override |
| 71 String toString() { |
| 72 return 'AnalysisError(location=$location message=$message; ' |
| 73 'severity=$severity; type=$type; correction=$correction'; |
| 74 } |
| 75 |
| 76 static AnalysisError fromJson(Map<String, Object> json) { |
| 77 return new AnalysisError( |
| 78 json[SEVERITY], |
| 79 json[TYPE], |
| 80 new Location.fromJson(json[LOCATION]), |
| 81 json[MESSAGE], |
| 82 json[CORRECTION]); |
| 83 } |
| 84 } |
| OLD | NEW |