Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(819)

Side by Side Diff: pkg/analysis_server/lib/src/computer/computer_hover.dart

Issue 2681233005: Analysis.getHover should return the field's documentation for field formal parameters. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // documentation 75 // documentation
76 hover.dartdoc = _computeDocumentation(element); 76 hover.dartdoc = _computeDocumentation(element);
77 } 77 }
78 // parameter 78 // parameter
79 hover.parameter = _safeToString(expression.bestParameterElement); 79 hover.parameter = _safeToString(expression.bestParameterElement);
80 // types 80 // types
81 { 81 {
82 AstNode parent = expression.parent; 82 AstNode parent = expression.parent;
83 DartType staticType = null; 83 DartType staticType = null;
84 DartType propagatedType = expression.propagatedType; 84 DartType propagatedType = expression.propagatedType;
85 if (element == null || element is VariableElement) { 85 if (element is ParameterElement) {
86 staticType = element.type;
87 } else if (element == null || element is VariableElement) {
86 staticType = expression.staticType; 88 staticType = expression.staticType;
87 } 89 }
88 if (parent is MethodInvocation && parent.methodName == expression) { 90 if (parent is MethodInvocation && parent.methodName == expression) {
89 staticType = parent.staticInvokeType; 91 staticType = parent.staticInvokeType;
90 propagatedType = parent.propagatedInvokeType; 92 propagatedType = parent.propagatedInvokeType;
91 if (staticType != null && staticType.isDynamic) { 93 if (staticType != null && staticType.isDynamic) {
92 staticType = null; 94 staticType = null;
93 } 95 }
94 if (propagatedType != null && propagatedType.isDynamic) { 96 if (propagatedType != null && propagatedType.isDynamic) {
95 propagatedType = null; 97 propagatedType = null;
96 } 98 }
97 } 99 }
98 hover.staticType = _safeToString(staticType); 100 hover.staticType = _safeToString(staticType);
99 hover.propagatedType = _safeToString(propagatedType); 101 hover.propagatedType = _safeToString(propagatedType);
100 } 102 }
101 // done 103 // done
102 return hover; 104 return hover;
103 } 105 }
104 // not an expression 106 // not an expression
105 return null; 107 return null;
106 } 108 }
107 109
108 String _computeDocumentation(Element element) { 110 String _computeDocumentation(Element element) {
111 if (element is FieldFormalParameterElement) {
112 element = (element as FieldFormalParameterElement).field;
113 }
109 if (element is ParameterElement) { 114 if (element is ParameterElement) {
110 element = element.enclosingElement; 115 element = element.enclosingElement;
111 } 116 }
112 // The documentation of the element itself. 117 // The documentation of the element itself.
113 if (element.documentationComment != null) { 118 if (element.documentationComment != null) {
114 return removeDartDocDelimiters(element.documentationComment); 119 return removeDartDocDelimiters(element.documentationComment);
115 } 120 }
116 // Look for documentation comments of overridden members. 121 // Look for documentation comments of overridden members.
117 OverriddenElements overridden = findOverriddenElements(element); 122 OverriddenElements overridden = findOverriddenElements(element);
118 for (Element superElement in [] 123 for (Element superElement in []
119 ..addAll(overridden.superElements) 124 ..addAll(overridden.superElements)
120 ..addAll(overridden.interfaceElements)) { 125 ..addAll(overridden.interfaceElements)) {
121 String rawDoc = superElement.documentationComment; 126 String rawDoc = superElement.documentationComment;
122 if (rawDoc != null) { 127 if (rawDoc != null) {
123 Element interfaceClass = superElement.enclosingElement; 128 Element interfaceClass = superElement.enclosingElement;
124 return removeDartDocDelimiters(rawDoc) + 129 return removeDartDocDelimiters(rawDoc) +
125 '\n\nCopied from `${interfaceClass.displayName}`.'; 130 '\n\nCopied from `${interfaceClass.displayName}`.';
126 } 131 }
127 } 132 }
128 return null; 133 return null;
129 } 134 }
130 135
131 static _safeToString(obj) => obj?.toString(); 136 static _safeToString(obj) => obj?.toString();
132 } 137 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698