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:analysis_server/src/computer/computer_overrides.dart'; | 9 import 'package:analysis_server/src/computer/computer_overrides.dart'; |
10 import 'package:analysis_server/src/utilities/documentation.dart'; | 10 import 'package:analysis_server/src/utilities/documentation.dart'; |
11 import 'package:analyzer/dart/ast/ast.dart'; | 11 import 'package:analyzer/dart/ast/ast.dart'; |
12 import 'package:analyzer/dart/element/element.dart'; | 12 import 'package:analyzer/dart/element/element.dart'; |
| 13 import 'package:analyzer/dart/element/type.dart'; |
13 import 'package:analyzer/src/dart/ast/utilities.dart'; | 14 import 'package:analyzer/src/dart/ast/utilities.dart'; |
14 | 15 |
15 /** | 16 /** |
16 * A computer for the hover at the specified offset of a Dart [CompilationUnit]. | 17 * A computer for the hover at the specified offset of a Dart [CompilationUnit]. |
17 */ | 18 */ |
18 class DartUnitHoverComputer { | 19 class DartUnitHoverComputer { |
19 final CompilationUnit _unit; | 20 final CompilationUnit _unit; |
20 final int _offset; | 21 final int _offset; |
21 | 22 |
22 DartUnitHoverComputer(this._unit, this._offset); | 23 DartUnitHoverComputer(this._unit, this._offset); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 hover.containingLibraryName = library.name; | 70 hover.containingLibraryName = library.name; |
70 hover.containingLibraryPath = library.source.fullName; | 71 hover.containingLibraryPath = library.source.fullName; |
71 } | 72 } |
72 } | 73 } |
73 // documentation | 74 // documentation |
74 hover.dartdoc = _computeDocumentation(element); | 75 hover.dartdoc = _computeDocumentation(element); |
75 } | 76 } |
76 // parameter | 77 // parameter |
77 hover.parameter = _safeToString(expression.bestParameterElement); | 78 hover.parameter = _safeToString(expression.bestParameterElement); |
78 // types | 79 // types |
79 if (element == null || element is VariableElement) { | 80 { |
80 hover.staticType = _safeToString(expression.staticType); | 81 AstNode parent = expression.parent; |
| 82 DartType staticType = null; |
| 83 DartType propagatedType = expression.propagatedType; |
| 84 if (element == null || element is VariableElement) { |
| 85 staticType = expression.staticType; |
| 86 } |
| 87 if (parent is MethodInvocation && parent.methodName == expression) { |
| 88 staticType = parent.staticInvokeType; |
| 89 propagatedType = parent.propagatedInvokeType; |
| 90 if (staticType != null && staticType.isDynamic) { |
| 91 staticType = null; |
| 92 } |
| 93 if (propagatedType != null && propagatedType.isDynamic) { |
| 94 propagatedType = null; |
| 95 } |
| 96 } |
| 97 hover.staticType = _safeToString(staticType); |
| 98 hover.propagatedType = _safeToString(propagatedType); |
81 } | 99 } |
82 hover.propagatedType = _safeToString(expression.propagatedType); | |
83 // done | 100 // done |
84 return hover; | 101 return hover; |
85 } | 102 } |
86 // not an expression | 103 // not an expression |
87 return null; | 104 return null; |
88 } | 105 } |
89 | 106 |
90 String _computeDocumentation(Element element) { | 107 String _computeDocumentation(Element element) { |
91 if (element is ParameterElement) { | 108 if (element is ParameterElement) { |
92 element = element.enclosingElement; | 109 element = element.enclosingElement; |
(...skipping 12 matching lines...) Expand all Loading... |
105 Element interfaceClass = superElement.enclosingElement; | 122 Element interfaceClass = superElement.enclosingElement; |
106 return removeDartDocDelimiters(rawDoc) + | 123 return removeDartDocDelimiters(rawDoc) + |
107 '\n\nCopied from `${interfaceClass.displayName}`.'; | 124 '\n\nCopied from `${interfaceClass.displayName}`.'; |
108 } | 125 } |
109 } | 126 } |
110 return null; | 127 return null; |
111 } | 128 } |
112 | 129 |
113 static _safeToString(obj) => obj != null ? obj.toString() : null; | 130 static _safeToString(obj) => obj != null ? obj.toString() : null; |
114 } | 131 } |
OLD | NEW |