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