| 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.hover; | 5 library computer.hover; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol.dart' show HoverInformation; | 7 import 'package:analysis_server/src/protocol.dart' show HoverInformation; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/element.dart'; | 9 import 'package:analyzer/src/generated/element.dart'; |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 final CompilationUnit _unit; | 61 final CompilationUnit _unit; |
| 62 final int _offset; | 62 final int _offset; |
| 63 | 63 |
| 64 DartUnitHoverComputer(this._unit, this._offset); | 64 DartUnitHoverComputer(this._unit, this._offset); |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * Returns the computed hover, maybe `null`. | 67 * Returns the computed hover, maybe `null`. |
| 68 */ | 68 */ |
| 69 HoverInformation compute() { | 69 HoverInformation compute() { |
| 70 AstNode node = new NodeLocator.con1(_offset).searchWithin(_unit); | 70 AstNode node = new NodeLocator.con1(_offset).searchWithin(_unit); |
| 71 if (node == null) { |
| 72 return null; |
| 73 } |
| 71 if (node.parent is TypeName && | 74 if (node.parent is TypeName && |
| 72 node.parent.parent is ConstructorName && | 75 node.parent.parent is ConstructorName && |
| 73 node.parent.parent.parent is InstanceCreationExpression) { | 76 node.parent.parent.parent is InstanceCreationExpression) { |
| 74 node = node.parent.parent.parent; | 77 node = node.parent.parent.parent; |
| 75 } | 78 } |
| 76 if (node.parent is ConstructorName && | 79 if (node.parent is ConstructorName && |
| 77 node.parent.parent is InstanceCreationExpression) { | 80 node.parent.parent is InstanceCreationExpression) { |
| 78 node = node.parent.parent; | 81 node = node.parent.parent; |
| 79 } | 82 } |
| 80 if (node is Expression) { | 83 if (node is Expression) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 hover.propagatedType = _safeToString(expression.propagatedType); | 115 hover.propagatedType = _safeToString(expression.propagatedType); |
| 113 // done | 116 // done |
| 114 return hover; | 117 return hover; |
| 115 } | 118 } |
| 116 // not an expression | 119 // not an expression |
| 117 return null; | 120 return null; |
| 118 } | 121 } |
| 119 | 122 |
| 120 static _safeToString(obj) => obj != null ? obj.toString() : null; | 123 static _safeToString(obj) => obj != null ? obj.toString() : null; |
| 121 } | 124 } |
| OLD | NEW |