OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library analysis_server.src.utilities.documentation; |
| 6 |
| 7 String getDartDocSummary(String str) { |
| 8 if (str == null) { |
| 9 return null; |
| 10 } |
| 11 List<String> lines = str.split('\n'); |
| 12 StringBuffer sb = new StringBuffer(); |
| 13 bool firstLine = true; |
| 14 for (String line in lines) { |
| 15 if (sb.length != 0 && line.isEmpty) { |
| 16 return sb.toString(); |
| 17 } |
| 18 if (!firstLine) { |
| 19 sb.write('\n'); |
| 20 } |
| 21 firstLine = false; |
| 22 sb.write(line); |
| 23 } |
| 24 return sb.toString(); |
| 25 } |
| 26 |
| 27 /** |
| 28 * Converts [str] from a Dart Doc string with slashes and stars to a plain text |
| 29 * representation of the comment. |
| 30 */ |
| 31 String removeDartDocDelimiters(String str) { |
| 32 if (str == null) { |
| 33 return null; |
| 34 } |
| 35 // remove /** */ |
| 36 if (str.startsWith('/**')) { |
| 37 str = str.substring(3); |
| 38 } |
| 39 if (str.endsWith("*/")) { |
| 40 str = str.substring(0, str.length - 2); |
| 41 } |
| 42 str = str.trim(); |
| 43 // remove leading '* ' and '/// ' |
| 44 List<String> lines = str.split('\n'); |
| 45 StringBuffer sb = new StringBuffer(); |
| 46 bool firstLine = true; |
| 47 for (String line in lines) { |
| 48 line = line.trim(); |
| 49 if (line.startsWith("*")) { |
| 50 line = line.substring(1); |
| 51 if (line.startsWith(" ")) { |
| 52 line = line.substring(1); |
| 53 } |
| 54 } else if (line.startsWith("///")) { |
| 55 line = line.substring(3); |
| 56 if (line.startsWith(" ")) { |
| 57 line = line.substring(1); |
| 58 } |
| 59 } |
| 60 if (!firstLine) { |
| 61 sb.write('\n'); |
| 62 } |
| 63 firstLine = false; |
| 64 sb.write(line); |
| 65 } |
| 66 str = sb.toString(); |
| 67 // done |
| 68 return str; |
| 69 } |
OLD | NEW |