| 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/protocol2.dart'; | 7 import 'package:analysis_server/src/protocol2.dart'; |
| 8 import 'package:analyzer/src/generated/engine.dart' as engine; | 8 import 'package:analyzer/src/generated/engine.dart' as engine; |
| 9 import 'package:analyzer/src/generated/error.dart' as engine; | 9 import 'package:analyzer/src/generated/error.dart' as engine; |
| 10 import 'package:analyzer/src/generated/source.dart' as engine; | 10 import 'package:analyzer/src/generated/source.dart' as engine; |
| 11 | 11 |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Returns a JSON correponding to the given list of Engine errors. | 14 * Returns a JSON correponding to the given list of Engine errors. |
| 15 */ | 15 */ |
| 16 List<Map<String, Object>> engineErrorInfoToJson(engine.AnalysisErrorInfo info) { | 16 List<Map<String, Object>> engineErrorInfoToJson(engine.AnalysisErrorInfo info) { |
| 17 return engineErrorsToJson(info.lineInfo, info.errors); | 17 return engineErrorsToJson(info.lineInfo, info.errors); |
| 18 } | 18 } |
| 19 | 19 |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Returns a JSON correponding to the given list of Engine errors. | 22 * Returns a JSON correponding to the given list of Engine errors. |
| 23 */ | 23 */ |
| 24 List<Map<String, Object>> engineErrorsToJson(engine.LineInfo lineInfo, | 24 List<Map<String, Object>> engineErrorsToJson(engine.LineInfo lineInfo, |
| 25 List<engine.AnalysisError> errors) { | 25 List<engine.AnalysisError> errors) { |
| 26 return errors.map((engine.AnalysisError error) { | 26 return errors.map((engine.AnalysisError error) { |
| 27 return analysisErrorFromEngine(lineInfo, error).toJson(); | 27 return new AnalysisError.fromEngine(lineInfo, error).toJson(); |
| 28 }).toList(); | 28 }).toList(); |
| 29 } | 29 } |
| 30 | |
| 31 | |
| 32 AnalysisError analysisErrorFromEngine(engine.LineInfo lineInfo, | |
| 33 engine.AnalysisError error) { | |
| 34 engine.ErrorCode errorCode = error.errorCode; | |
| 35 // prepare location | |
| 36 Location location; | |
| 37 { | |
| 38 String file = error.source.fullName; | |
| 39 int offset = error.offset; | |
| 40 int length = error.length; | |
| 41 int startLine = -1; | |
| 42 int startColumn = -1; | |
| 43 if (lineInfo != null) { | |
| 44 engine.LineInfo_Location lineLocation = lineInfo.getLocation(offset); | |
| 45 if (lineLocation != null) { | |
| 46 startLine = lineLocation.lineNumber; | |
| 47 startColumn = lineLocation.columnNumber; | |
| 48 } | |
| 49 } | |
| 50 location = new Location(file, offset, length, startLine, startColumn); | |
| 51 } | |
| 52 // done | |
| 53 var severity = new ErrorSeverity(errorCode.errorSeverity.name); | |
| 54 var type = new ErrorType(errorCode.type.name); | |
| 55 String message = error.message; | |
| 56 String correction = error.correction; | |
| 57 return new AnalysisError(severity, type, location, message, | |
| 58 correction: correction); | |
| 59 } | |
| OLD | NEW |