| 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.parent is TypeName && |
| 72 node.parent.parent is ConstructorName && |
| 73 node.parent.parent.parent is InstanceCreationExpression) { |
| 74 node = node.parent.parent.parent; |
| 75 } |
| 76 if (node.parent is ConstructorName && |
| 77 node.parent.parent is InstanceCreationExpression) { |
| 78 node = node.parent.parent; |
| 79 } |
| 71 if (node is Expression) { | 80 if (node is Expression) { |
| 72 HoverInformation hover = new HoverInformation(node.offset, node.length); | 81 Expression expression = node; |
| 82 HoverInformation hover = |
| 83 new HoverInformation(expression.offset, expression.length); |
| 73 // element | 84 // element |
| 74 Element element = ElementLocator.locateWithOffset(node, _offset); | 85 Element element = ElementLocator.locateWithOffset(expression, _offset); |
| 75 if (element != null) { | 86 if (element != null) { |
| 76 // variable, if synthetic accessor | 87 // variable, if synthetic accessor |
| 77 if (element is PropertyAccessorElement) { | 88 if (element is PropertyAccessorElement) { |
| 78 PropertyAccessorElement accessor = element; | 89 PropertyAccessorElement accessor = element; |
| 79 if (accessor.isSynthetic) { | 90 if (accessor.isSynthetic) { |
| 80 element = accessor.variable; | 91 element = accessor.variable; |
| 81 } | 92 } |
| 82 } | 93 } |
| 83 // description | 94 // description |
| 84 hover.elementDescription = element.toString(); | 95 hover.elementDescription = element.toString(); |
| 85 hover.elementKind = element.kind.displayName; | 96 hover.elementKind = element.kind.displayName; |
| 86 // library | 97 // library |
| 87 LibraryElement library = element.library; | 98 LibraryElement library = element.library; |
| 88 if (library != null) { | 99 if (library != null) { |
| 89 hover.containingLibraryName = library.name; | 100 hover.containingLibraryName = library.name; |
| 90 hover.containingLibraryPath = library.source.fullName; | 101 hover.containingLibraryPath = library.source.fullName; |
| 91 } | 102 } |
| 92 // documentation | 103 // documentation |
| 93 String dartDoc = element.computeDocumentationComment(); | 104 String dartDoc = element.computeDocumentationComment(); |
| 94 dartDoc = _removeDartDocDelimiters(dartDoc); | 105 dartDoc = _removeDartDocDelimiters(dartDoc); |
| 95 hover.dartdoc = dartDoc; | 106 hover.dartdoc = dartDoc; |
| 96 } | 107 } |
| 97 // parameter | 108 // parameter |
| 98 hover.parameter = _safeToString(node.bestParameterElement); | 109 hover.parameter = _safeToString(expression.bestParameterElement); |
| 99 // types | 110 // types |
| 100 hover.staticType = _safeToString(node.staticType); | 111 hover.staticType = _safeToString(expression.staticType); |
| 101 hover.propagatedType = _safeToString(node.propagatedType); | 112 hover.propagatedType = _safeToString(expression.propagatedType); |
| 102 // done | 113 // done |
| 103 return hover; | 114 return hover; |
| 104 } | 115 } |
| 105 // not an expression | 116 // not an expression |
| 106 return null; | 117 return null; |
| 107 } | 118 } |
| 108 | 119 |
| 109 static _safeToString(obj) => obj != null ? obj.toString() : null; | 120 static _safeToString(obj) => obj != null ? obj.toString() : null; |
| 110 } | 121 } |
| OLD | NEW |