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

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

Issue 1632033002: Issue 25542. If an element does not have its own documentation, use the documentation from the over… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: New test cases and tweaks. Created 4 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/computer/computer_overrides.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/utilities/documentation.dart'; 10 import 'package:analysis_server/src/utilities/documentation.dart';
10 import 'package:analyzer/dart/element/element.dart'; 11 import 'package:analyzer/dart/element/element.dart';
11 import 'package:analyzer/src/generated/ast.dart'; 12 import 'package:analyzer/src/generated/ast.dart';
12 import 'package:analyzer/src/generated/element.dart'; 13 import 'package:analyzer/src/generated/element.dart';
13 14
14 /** 15 /**
15 * A computer for the hover at the specified offset of a Dart [CompilationUnit]. 16 * A computer for the hover at the specified offset of a Dart [CompilationUnit].
16 */ 17 */
17 class DartUnitHoverComputer { 18 class DartUnitHoverComputer {
18 final CompilationUnit _unit; 19 final CompilationUnit _unit;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 if (containingClass != null) { 63 if (containingClass != null) {
63 hover.containingClassDescription = containingClass.displayName; 64 hover.containingClassDescription = containingClass.displayName;
64 } 65 }
65 // containing library 66 // containing library
66 LibraryElement library = element.library; 67 LibraryElement library = element.library;
67 if (library != null) { 68 if (library != null) {
68 hover.containingLibraryName = library.name; 69 hover.containingLibraryName = library.name;
69 hover.containingLibraryPath = library.source.fullName; 70 hover.containingLibraryPath = library.source.fullName;
70 } 71 }
71 } 72 }
72
73 // documentation 73 // documentation
74 hover.dartdoc = _computeDocumentation(element); 74 hover.dartdoc = _computeDocumentation(element);
75 } 75 }
76 // parameter 76 // parameter
77 hover.parameter = _safeToString(expression.bestParameterElement); 77 hover.parameter = _safeToString(expression.bestParameterElement);
78 // types 78 // types
79 if (element == null || element is VariableElement) { 79 if (element == null || element is VariableElement) {
80 hover.staticType = _safeToString(expression.staticType); 80 hover.staticType = _safeToString(expression.staticType);
81 } 81 }
82 hover.propagatedType = _safeToString(expression.propagatedType); 82 hover.propagatedType = _safeToString(expression.propagatedType);
83 // done 83 // done
84 return hover; 84 return hover;
85 } 85 }
86 // not an expression 86 // not an expression
87 return null; 87 return null;
88 } 88 }
89 89
90 String _computeDocumentation(Element element) { 90 String _computeDocumentation(Element element) {
91 if (element is ParameterElement) { 91 if (element is ParameterElement) {
92 element = element.enclosingElement; 92 element = element.enclosingElement;
93 } 93 }
94 return removeDartDocDelimiters(element.documentationComment); 94 // The documentation of the element itself.
95 if (element.documentationComment != null) {
96 return removeDartDocDelimiters(element.documentationComment);
97 }
98 // Look for documentation comments of overridden members.
99 OverriddenElements overridden = findOverriddenElements(element);
100 for (Element superElement in []
101 ..addAll(overridden.superElements)
102 ..addAll(overridden.interfaceElements)) {
103 String rawDoc = superElement.documentationComment;
104 if (rawDoc != null) {
105 Element interfaceClass = superElement.enclosingElement;
106 return removeDartDocDelimiters(rawDoc) +
107 '\n\nCopied from `${interfaceClass.displayName}`.';
108 }
109 }
110 return null;
95 } 111 }
96 112
97 static _safeToString(obj) => obj != null ? obj.toString() : null; 113 static _safeToString(obj) => obj != null ? obj.toString() : null;
98 } 114 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/computer/computer_overrides.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698