| OLD | NEW |
| 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 |
| 11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
| 12 * the License. | 12 * the License. |
| 13 */ | 13 */ |
| 14 | 14 |
| 15 package com.google.dart.tools.core.utilities.dartdoc; | 15 package com.google.dart.tools.core.utilities.dartdoc; |
| 16 | 16 |
| 17 import com.google.dart.engine.context.AnalysisException; | 17 import com.google.dart.engine.context.AnalysisException; |
| 18 import com.google.dart.engine.element.ClassElement; | 18 import com.google.dart.engine.element.ClassElement; |
| 19 import com.google.dart.engine.element.CompilationUnitElement; | 19 import com.google.dart.engine.element.CompilationUnitElement; |
| 20 import com.google.dart.engine.element.ConstructorElement; | 20 import com.google.dart.engine.element.ConstructorElement; |
| 21 import com.google.dart.engine.element.Element; | 21 import com.google.dart.engine.element.Element; |
| 22 import com.google.dart.engine.element.ExecutableElement; | 22 import com.google.dart.engine.element.ExecutableElement; |
| 23 import com.google.dart.engine.element.FieldElement; | 23 import com.google.dart.engine.element.FieldElement; |
| 24 import com.google.dart.engine.element.FieldFormalParameterElement; | 24 import com.google.dart.engine.element.FieldFormalParameterElement; |
| 25 import com.google.dart.engine.element.FunctionElement; |
| 25 import com.google.dart.engine.element.LibraryElement; | 26 import com.google.dart.engine.element.LibraryElement; |
| 26 import com.google.dart.engine.element.LocalVariableElement; | 27 import com.google.dart.engine.element.LocalVariableElement; |
| 27 import com.google.dart.engine.element.MethodElement; | 28 import com.google.dart.engine.element.MethodElement; |
| 28 import com.google.dart.engine.element.ParameterElement; | 29 import com.google.dart.engine.element.ParameterElement; |
| 29 import com.google.dart.engine.element.PropertyAccessorElement; | 30 import com.google.dart.engine.element.PropertyAccessorElement; |
| 30 import com.google.dart.engine.element.TopLevelVariableElement; | 31 import com.google.dart.engine.element.TopLevelVariableElement; |
| 31 import com.google.dart.engine.element.TypeParameterElement; | 32 import com.google.dart.engine.element.TypeParameterElement; |
| 32 import com.google.dart.engine.element.VariableElement; | 33 import com.google.dart.engine.element.VariableElement; |
| 33 import com.google.dart.engine.element.visitor.SimpleElementVisitor; | 34 import com.google.dart.engine.element.visitor.SimpleElementVisitor; |
| 34 import com.google.dart.engine.source.Source; | 35 import com.google.dart.engine.source.Source; |
| 35 import com.google.dart.engine.source.Source.ContentReceiver; | 36 import com.google.dart.engine.source.Source.ContentReceiver; |
| 37 import com.google.dart.engine.type.Type; |
| 36 import com.google.dart.engine.utilities.dart.ParameterKind; | 38 import com.google.dart.engine.utilities.dart.ParameterKind; |
| 37 import com.google.dart.engine.utilities.source.SourceRange; | 39 import com.google.dart.engine.utilities.source.SourceRange; |
| 38 import com.google.dart.tools.core.DartCore; | 40 import com.google.dart.tools.core.DartCore; |
| 39 | 41 |
| 40 import java.io.BufferedReader; | 42 import java.io.BufferedReader; |
| 41 import java.io.IOException; | 43 import java.io.IOException; |
| 42 import java.io.StringReader; | 44 import java.io.StringReader; |
| 43 import java.nio.CharBuffer; | 45 import java.nio.CharBuffer; |
| 44 | 46 |
| 45 /** | 47 /** |
| 46 * A utility class for dealing with Dart doc text. | 48 * A utility class for dealing with Dart doc text. |
| 47 * | 49 * |
| 48 * @coverage dart.tools.core.utilities | 50 * @coverage dart.tools.core.utilities |
| 49 */ | 51 */ |
| 50 public final class DartDocUtilities { | 52 public final class DartDocUtilities { |
| 51 | 53 |
| 52 private static class DocumentingVisitor extends SimpleElementVisitor<String> { | 54 private static class DocumentingVisitor extends SimpleElementVisitor<String> { |
| 55 private Type elementType; |
| 56 |
| 57 public DocumentingVisitor(Type type) { |
| 58 this.elementType = type; |
| 59 } |
| 60 |
| 53 @Override | 61 @Override |
| 54 public String visitClassElement(ClassElement element) { | 62 public String visitClassElement(ClassElement element) { |
| 55 | 63 |
| 56 LibraryElement library = element.getLibrary(); | 64 LibraryElement library = element.getLibrary(); |
| 57 | 65 |
| 58 if (library != null) { | 66 if (library != null) { |
| 59 String libraryName = library.getDisplayName(); | 67 String libraryName = library.getDisplayName(); |
| 60 if (libraryName != null && libraryName.length() > 0) { | 68 if (libraryName != null && libraryName.length() > 0) { |
| 61 return getTypeName(element) + " - " + libraryName; | 69 return getTypeName(element) + " - " + libraryName; |
| 62 } | 70 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 80 public String visitFieldElement(FieldElement element) { | 88 public String visitFieldElement(FieldElement element) { |
| 81 return getTypeName(element) + " " + element.getDisplayName(); | 89 return getTypeName(element) + " " + element.getDisplayName(); |
| 82 } | 90 } |
| 83 | 91 |
| 84 @Override | 92 @Override |
| 85 public String visitFieldFormalParameterElement(FieldFormalParameterElement e
lement) { | 93 public String visitFieldFormalParameterElement(FieldFormalParameterElement e
lement) { |
| 86 return getTypeName(element) + " " + element.getDisplayName(); | 94 return getTypeName(element) + " " + element.getDisplayName(); |
| 87 } | 95 } |
| 88 | 96 |
| 89 @Override | 97 @Override |
| 90 public String visitFunctionElement(com.google.dart.engine.element.FunctionEl
ement element) { | 98 public String visitFunctionElement(FunctionElement element) { |
| 91 return getDescription(element); | 99 return getDescription(element); |
| 92 } | 100 } |
| 93 | 101 |
| 94 @Override | 102 @Override |
| 95 public String visitLocalVariableElement(LocalVariableElement element) { | 103 public String visitLocalVariableElement(LocalVariableElement element) { |
| 96 return getTypeName(element) + " " + element.getDisplayName(); | 104 return getTypeName(element) + " " + element.getDisplayName(); |
| 97 } | 105 } |
| 98 | 106 |
| 99 @Override | 107 @Override |
| 100 public String visitMethodElement(MethodElement element) { | 108 public String visitMethodElement(MethodElement element) { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 } | 275 } |
| 268 } | 276 } |
| 269 return "dynamic"; | 277 return "dynamic"; |
| 270 } | 278 } |
| 271 | 279 |
| 272 private String getTypeName(ClassElement element) { | 280 private String getTypeName(ClassElement element) { |
| 273 return getName(element.getType()); | 281 return getName(element.getType()); |
| 274 } | 282 } |
| 275 | 283 |
| 276 private String getTypeName(VariableElement element) { | 284 private String getTypeName(VariableElement element) { |
| 277 return getName(element.getType()); | 285 Type type = element.getType(); |
| 286 if (elementType != null) { |
| 287 type = elementType; |
| 288 } |
| 289 return getName(type); |
| 278 } | 290 } |
| 279 | 291 |
| 280 } | 292 } |
| 281 | 293 |
| 282 /** | 294 /** |
| 283 * Convert from a Dart doc string with slashes and stars to a plain text repre
sentation of the | 295 * Convert from a Dart doc string with slashes and stars to a plain text repre
sentation of the |
| 284 * comment. | 296 * comment. |
| 285 * | 297 * |
| 286 * @param str | 298 * @param str |
| 287 * @return | 299 * @return |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 public static String getDartDocAsHtml(String docString) { | 378 public static String getDartDocAsHtml(String docString) { |
| 367 if (docString != null) { | 379 if (docString != null) { |
| 368 return convertToHtml(cleanDartDoc(docString)); | 380 return convertToHtml(cleanDartDoc(docString)); |
| 369 } | 381 } |
| 370 return null; | 382 return null; |
| 371 } | 383 } |
| 372 | 384 |
| 373 /** | 385 /** |
| 374 * Return a one-line description of the given Element. | 386 * Return a one-line description of the given Element. |
| 375 * | 387 * |
| 376 * @param the element to document | 388 * @param type the best known {@link Type} of the given {@link Element} |
| 389 * @param element the {@link Element} to document |
| 377 * @return a String summarizing this element, or {@code null} if there is no s
uitable | 390 * @return a String summarizing this element, or {@code null} if there is no s
uitable |
| 378 * documentation | 391 * documentation |
| 379 */ | 392 */ |
| 380 public static String getTextSummary(Element element) { | 393 public static String getTextSummary(Type type, Element element) { |
| 381 | |
| 382 if (element != null) { | 394 if (element != null) { |
| 383 String description = element.accept(new DocumentingVisitor()); | 395 String description = element.accept(new DocumentingVisitor(type)); |
| 384 if (description != null) { | 396 if (description != null) { |
| 385 return description; | 397 return description; |
| 386 } | 398 } |
| 387 } | 399 } |
| 388 | |
| 389 return null; | 400 return null; |
| 390 } | 401 } |
| 391 | 402 |
| 392 /** | 403 /** |
| 393 * Return a one-line description of the given Element as html | 404 * Return a one-line description of the given Element as html |
| 394 */ | 405 */ |
| 395 public static String getTextSummaryAsHtml(Element element) { | 406 public static String getTextSummaryAsHtml(Type type, Element element) { |
| 396 String summary = getTextSummary(element); | 407 String summary = getTextSummary(type, element); |
| 397 if (summary == null) { | 408 if (summary == null) { |
| 398 return null; | 409 return null; |
| 399 } | 410 } |
| 400 return escapeHtmlEntities(summary); | 411 return escapeHtmlEntities(summary); |
| 401 } | 412 } |
| 402 | 413 |
| 403 private static String convertListItems(String[] lines) { | 414 private static String convertListItems(String[] lines) { |
| 404 StringBuffer buf = new StringBuffer(); | 415 StringBuffer buf = new StringBuffer(); |
| 405 | 416 |
| 406 boolean wasCode = false; | 417 boolean wasCode = false; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 } | 511 } |
| 501 builder.append(string, start, string.length()); | 512 builder.append(string, start, string.length()); |
| 502 return builder.toString(); | 513 return builder.toString(); |
| 503 } | 514 } |
| 504 | 515 |
| 505 private DartDocUtilities() { | 516 private DartDocUtilities() { |
| 506 | 517 |
| 507 } | 518 } |
| 508 | 519 |
| 509 } | 520 } |
| OLD | NEW |