Changeset 24 in default
- Timestamp:
- 11/02/10 10:31:59 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/EbnfFormatterVisitor.java
r23 r24 154 154 } 155 155 156 private int scanBackNewlinesCount(String str, int position) { 157 int newLinesCount = 0; 158 int currentPosition = position; 159 while ((str.charAt(currentPosition) == '\n') || (str.charAt(currentPosition) == '\r')) { 160 if (str.charAt(currentPosition) == '\n') { 161 if (str.charAt(currentPosition - 1) == '\r') { 162 currentPosition -= 2; 163 } else { 164 currentPosition -= 1; 165 } 166 newLinesCount++; 167 } else if (str.charAt(currentPosition) == '\r') { 168 currentPosition -= 1; 169 newLinesCount++; 170 } 171 } 172 173 return newLinesCount; 174 } 175 156 176 private void weaveComments() { 157 177 bufferPosition = 0; … … 172 192 if (currentComment.getTotalOffset() == bufferPositionOriginalText) { 173 193 if (isMultiLineComment(currentComment.getText())) { 174 result.append(currentComment.getText()); 175 result.append("\n"); 194 int newLinesCount = scanBackNewlinesCount(originalText, bufferPositionOriginalText-1); 195 if (newLinesCount > 0) { 196 result.append(currentComment.getText()); 197 result.append("\n"); 198 } else { 199 String lastWhiteSpaces = scanBackWhitespaces(result.toString(), result.toString().length()-1); 200 result.delete(result.toString().length() - lastWhiteSpaces.length(), result.toString().length()); 201 result.append(" " + stripEndingNewline(currentComment.getText())); 202 result.append(lastWhiteSpaces); 203 } 176 204 } else if (isSingleLineComment(currentComment.getText())) { 205 int newLinesCount = scanBackNewlinesCount(originalText, bufferPositionOriginalText-1); 177 206 String lastWhiteSpaces = scanBackWhitespaces(result.toString(), result.toString().length()-1); 178 207 result.delete(result.toString().length() - lastWhiteSpaces.length(), result.toString().length()); 179 result.append(" " + stripEndingNewline(currentComment.getText())); 208 if (newLinesCount > 0) { 209 result.append("\n\n" + stripEndingNewline(currentComment.getText())); 210 } else { 211 result.append(" " + stripEndingNewline(currentComment.getText())); 212 } 180 213 result.append(lastWhiteSpaces); 181 214 }
Note: See TracChangeset
for help on using the changeset viewer.