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

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

Issue 389413002: Use HasToJson when set Reponse/Notification parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
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 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analysis_server/src/collections.dart';
9 import 'package:analysis_server/src/constants.dart'; 10 import 'package:analysis_server/src/constants.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 11 import 'package:analyzer/src/generated/ast.dart';
11 import 'package:analyzer/src/generated/element.dart'; 12 import 'package:analyzer/src/generated/element.dart';
12 13
13 14
14 /** 15 /**
15 * Converts [str] from a Dart Doc string with slashes and stars to a plain text 16 * Converts [str] from a Dart Doc string with slashes and stars to a plain text
16 * representation of the comment. 17 * representation of the comment.
17 */ 18 */
18 String _removeDartDocDelimiters(String str) { 19 String _removeDartDocDelimiters(String str) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 */ 62 */
62 class DartUnitHoverComputer { 63 class DartUnitHoverComputer {
63 final CompilationUnit _unit; 64 final CompilationUnit _unit;
64 final int _offset; 65 final int _offset;
65 66
66 DartUnitHoverComputer(this._unit, this._offset); 67 DartUnitHoverComputer(this._unit, this._offset);
67 68
68 /** 69 /**
69 * Returns the computed hover, maybe `null`. 70 * Returns the computed hover, maybe `null`.
70 */ 71 */
71 Map<String, Object> compute() { 72 Hover compute() {
72 AstNode node = new NodeLocator.con1(_offset).searchWithin(_unit); 73 AstNode node = new NodeLocator.con1(_offset).searchWithin(_unit);
73 if (node is Expression) { 74 if (node is Expression) {
74 Hover hover = new Hover(node.offset, node.length); 75 Hover hover = new Hover(node.offset, node.length);
75 // element 76 // element
76 Element element = ElementLocator.locateWithOffset(node, _offset); 77 Element element = ElementLocator.locateWithOffset(node, _offset);
77 if (element != null) { 78 if (element != null) {
78 // variable, if synthetic accessor 79 // variable, if synthetic accessor
79 if (element is PropertyAccessorElement) { 80 if (element is PropertyAccessorElement) {
80 PropertyAccessorElement accessor = element; 81 PropertyAccessorElement accessor = element;
81 if (accessor.isSynthetic) { 82 if (accessor.isSynthetic) {
(...skipping 13 matching lines...) Expand all
95 String dartDoc = element.computeDocumentationComment(); 96 String dartDoc = element.computeDocumentationComment();
96 dartDoc = _removeDartDocDelimiters(dartDoc); 97 dartDoc = _removeDartDocDelimiters(dartDoc);
97 hover.dartDoc = dartDoc; 98 hover.dartDoc = dartDoc;
98 } 99 }
99 // parameter 100 // parameter
100 hover.parameter = _safeToString(node.bestParameterElement); 101 hover.parameter = _safeToString(node.bestParameterElement);
101 // types 102 // types
102 hover.staticType = _safeToString(node.staticType); 103 hover.staticType = _safeToString(node.staticType);
103 hover.propagatedType = _safeToString(node.propagatedType); 104 hover.propagatedType = _safeToString(node.propagatedType);
104 // done 105 // done
105 return hover.toJson(); 106 return hover;
106 } 107 }
107 // not an expression 108 // not an expression
108 return null; 109 return null;
109 } 110 }
110 111
111 static _safeToString(obj) => obj != null ? obj.toString() : null; 112 static _safeToString(obj) => obj != null ? obj.toString() : null;
112 } 113 }
113 114
114 115
115 class Hover { 116 class Hover implements HasToJson {
116 final int offset; 117 final int offset;
117 final int length; 118 final int length;
118 String containingLibraryName; 119 String containingLibraryName;
119 String containingLibraryPath; 120 String containingLibraryPath;
120 String dartDoc; 121 String dartDoc;
121 String elementDescription; 122 String elementDescription;
122 String elementKind; 123 String elementKind;
123 String parameter; 124 String parameter;
124 String propagatedType; 125 String propagatedType;
125 String staticType; 126 String staticType;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 166 }
166 if (propagatedType != null) { 167 if (propagatedType != null) {
167 json[PROPAGATED_TYPE] = propagatedType; 168 json[PROPAGATED_TYPE] = propagatedType;
168 } 169 }
169 if (staticType != null) { 170 if (staticType != null) {
170 json[STATIC_TYPE] = staticType; 171 json[STATIC_TYPE] = staticType;
171 } 172 }
172 return json; 173 return json;
173 } 174 }
174 } 175 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698