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/plugin/protocol/protocol.dart' | 7 import 'package:analysis_server/plugin/protocol/protocol.dart' |
8 show HoverInformation; | 8 show HoverInformation; |
9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 95 } |
96 // description | 96 // description |
97 hover.elementDescription = element.toString(); | 97 hover.elementDescription = element.toString(); |
98 hover.elementKind = element.kind.displayName; | 98 hover.elementKind = element.kind.displayName; |
99 // not local element | 99 // not local element |
100 if (element.enclosingElement is! ExecutableElement) { | 100 if (element.enclosingElement is! ExecutableElement) { |
101 // containing class | 101 // containing class |
102 ClassElement containingClass = | 102 ClassElement containingClass = |
103 element.getAncestor((e) => e is ClassElement); | 103 element.getAncestor((e) => e is ClassElement); |
104 if (containingClass != null) { | 104 if (containingClass != null) { |
105 hover.containingClassDescription = containingClass.toString(); | 105 hover.containingClassDescription = containingClass.displayName; |
106 } | 106 } |
107 // containing library | 107 // containing library |
108 LibraryElement library = element.library; | 108 LibraryElement library = element.library; |
109 if (library != null) { | 109 if (library != null) { |
110 hover.containingLibraryName = library.name; | 110 hover.containingLibraryName = library.name; |
111 hover.containingLibraryPath = library.source.fullName; | 111 hover.containingLibraryPath = library.source.fullName; |
112 } | 112 } |
113 } | 113 } |
114 // documentation | 114 // documentation |
115 hover.dartdoc = _computeDocumentation(element); | 115 hover.dartdoc = _computeDocumentation(element); |
116 } | 116 } |
117 // parameter | 117 // parameter |
118 hover.parameter = _safeToString(expression.bestParameterElement); | 118 hover.parameter = _safeToString(expression.bestParameterElement); |
119 // types | 119 // types |
120 hover.staticType = _safeToString(expression.staticType); | 120 if (element == null || element is VariableElement) { |
| 121 hover.staticType = _safeToString(expression.staticType); |
| 122 } |
121 hover.propagatedType = _safeToString(expression.propagatedType); | 123 hover.propagatedType = _safeToString(expression.propagatedType); |
122 // done | 124 // done |
123 return hover; | 125 return hover; |
124 } | 126 } |
125 // not an expression | 127 // not an expression |
126 return null; | 128 return null; |
127 } | 129 } |
128 | 130 |
129 String _computeDocumentation(Element element) { | 131 String _computeDocumentation(Element element) { |
130 if (element is ParameterElement) { | 132 if (element is ParameterElement) { |
131 element = element.enclosingElement; | 133 element = element.enclosingElement; |
132 } | 134 } |
133 String dartDoc = element.computeDocumentationComment(); | 135 String dartDoc = element.computeDocumentationComment(); |
134 return _removeDartDocDelimiters(dartDoc); | 136 return _removeDartDocDelimiters(dartDoc); |
135 } | 137 } |
136 | 138 |
137 static _safeToString(obj) => obj != null ? obj.toString() : null; | 139 static _safeToString(obj) => obj != null ? obj.toString() : null; |
138 } | 140 } |
OLD | NEW |