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

Side by Side Diff: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/editor/DartTextHover.java

Issue 86073004: Issue 14868. Show both errors/warnings and Dart doc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012, the Dart project authors. 2 * Copyright (c) 2012, the Dart project authors.
3 * 3 *
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except
5 * in compliance with the License. You may obtain a copy of the License at 5 * in compliance with the License. You may obtain a copy of the License at
6 * 6 *
7 * http://www.eclipse.org/legal/epl-v10.html 7 * http://www.eclipse.org/legal/epl-v10.html
8 * 8 *
9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License 9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 /** 76 /**
77 * Remove a hover contributor 77 * Remove a hover contributor
78 * 78 *
79 * @param hoverContributor 79 * @param hoverContributor
80 */ 80 */
81 public static void removeContributer(ITextHover hoverContributor) { 81 public static void removeContributer(ITextHover hoverContributor) {
82 hoverContributors.remove(hoverContributor); 82 hoverContributors.remove(hoverContributor);
83 } 83 }
84 84
85 private static StringBuilder append(StringBuilder buffer, String s) {
86 if (buffer.length() != 0) {
87 buffer.append("<br><br>");
88 }
89 if (s != null) {
90 buffer.append(s);
91 }
92 return buffer;
93 }
94
85 private CompilationUnitEditor editor; 95 private CompilationUnitEditor editor;
86 96
87 private DartSourceViewerConfiguration sourceViewerConfiguration; 97 private DartSourceViewerConfiguration sourceViewerConfiguration;
88 98
89 private ITextHover lastReturnedHover; 99 private ITextHover lastReturnedHover;
90 100
91 public DartTextHover(ITextEditor editor, ISourceViewer sourceViewer, 101 public DartTextHover(ITextEditor editor, ISourceViewer sourceViewer,
92 DartSourceViewerConfiguration sourceViewerConfiguration) { 102 DartSourceViewerConfiguration sourceViewerConfiguration) {
93 super(sourceViewer); 103 super(sourceViewer);
94 104
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 // Check for a dartdoc contribution. 142 // Check for a dartdoc contribution.
133 return getDartDocHover(region); 143 return getDartDocHover(region);
134 } 144 }
135 145
136 @Override 146 @Override
137 public Object getHoverInfo2(ITextViewer textViewer, IRegion region) { 147 public Object getHoverInfo2(ITextViewer textViewer, IRegion region) {
138 // Overridden from ITextHoverExtension2. We try and return the richest help available; this 148 // Overridden from ITextHoverExtension2. We try and return the richest help available; this
139 // means trying to call getHoverInfo2() on any contributors, and falling bac k on getHoverInfo(). 149 // means trying to call getHoverInfo2() on any contributors, and falling bac k on getHoverInfo().
140 lastReturnedHover = null; 150 lastReturnedHover = null;
141 151
142 // Return any annotation info - i.e. errors and warnings. 152 StringBuilder buffer = new StringBuilder();
153
154 // Append any annotation info - i.e. errors and warnings.
143 String annotationHover = super.getHoverInfo(textViewer, region); 155 String annotationHover = super.getHoverInfo(textViewer, region);
144 156 append(buffer, escapeHtmlEntities(annotationHover));
145 if (annotationHover != null) {
146 return escapeHtmlEntities(annotationHover);
147 }
148 157
149 // Check through the contributed hover providers. 158 // Check through the contributed hover providers.
150 for (ITextHover hoverContributer : hoverContributors) { 159 for (ITextHover hoverContributer : hoverContributors) {
151 if (hoverContributer instanceof ITextHoverExtension2) { 160 if (hoverContributer instanceof ITextHoverExtension2) {
152 Object hoverInfo = ((ITextHoverExtension2) hoverContributer).getHoverInf o2( 161 Object hoverInfo = ((ITextHoverExtension2) hoverContributer).getHoverInf o2(
153 textViewer, 162 textViewer,
154 region); 163 region);
155 164
156 if (hoverInfo != null) { 165 if (hoverInfo != null) {
157 lastReturnedHover = hoverContributer; 166 lastReturnedHover = hoverContributer;
158
159 return hoverInfo; 167 return hoverInfo;
160 } 168 }
161 } else { 169 } else {
162 String hoverText = hoverContributer.getHoverInfo(textViewer, region); 170 String hoverText = hoverContributer.getHoverInfo(textViewer, region);
163 171
164 if (hoverText != null) { 172 if (hoverText != null) {
165 lastReturnedHover = hoverContributer; 173 lastReturnedHover = hoverContributer;
166
167 return hoverText; 174 return hoverText;
168 } 175 }
169 } 176 }
170 } 177 }
171 178
172 // Check for a dartdoc contribution. 179 // Check for a dartdoc contribution.
173 return getDartDocHover(region); 180 String dartDocHover = getDartDocHover(region);
181 return append(buffer, dartDocHover).toString();
174 } 182 }
175 183
176 @Override 184 @Override
177 protected boolean isIncluded(Annotation annotation) { 185 protected boolean isIncluded(Annotation annotation) {
178 return sourceViewerConfiguration.isShownInText(annotation); 186 return sourceViewerConfiguration.isShownInText(annotation);
179 } 187 }
180 188
181 private String escapeHtmlEntities(String str) { 189 private String escapeHtmlEntities(String str) {
182 str = str.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;"); 190 str = str.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
183 191
184 return str; 192 return str;
185 } 193 }
186 194
187 /** 195 /**
188 * Return the associated DartDoc hover, if any. 196 * Return the associated DartDoc hover, if any.
189 */ 197 */
190 private String getDartDocHover(IRegion region) { 198 private String getDartDocHover(IRegion region) {
191 if (editor != null) { 199 if (editor != null) {
192 Element element = NewSelectionConverter.getElementAtOffset(editor, region. getOffset()); 200 Element element = NewSelectionConverter.getElementAtOffset(editor, region. getOffset());
193 return getElementDocumentationHtml(element); 201 return getElementDocumentationHtml(element);
194 } 202 }
195 203
196 return null; 204 return null;
197 } 205 }
198 206
199 } 207 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698