Changeset 23 in default for trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src
- Timestamp:
- 11/02/10 10:22:17 (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
r22 r23 3 3 import java.util.ArrayList; 4 4 5 import org.eclipse.emf.common.util.EList;6 5 import org.eclipse.emf.ecore.EObject; 7 6 import org.eclipse.xtext.parsetree.AbstractNode; 8 7 import org.eclipse.xtext.parsetree.CompositeNode; 9 8 import org.eclipse.xtext.parsetree.LeafNode; 10 import org.eclipse.xtext.parsetree.NodeAdapter;11 9 import org.eclipse.xtext.parsetree.NodeUtil; 12 10 … … 40 38 private int bufferPosition = 0; 41 39 private int bufferPositionOriginalText = 0; 42 private int commentPosition = 0;43 40 private int allCommentsPosition = 0; 44 41 private ArrayList<LeafNode> allComments = new ArrayList<LeafNode>(); 45 private ArrayList<String> collectedComments = new ArrayList<String>();46 42 47 43 private boolean lastWasSectionHeading=false; 48 44 private CompositeNode parserEtsiBnfNode; 49 45 private String originalText; 50 private String originalTextNoWhitespaces;51 46 private int bufferPositionFormattedText; 52 47 private String formattedText; 53 48 private String bufNoWhitespaces; 49 private String originalTextNoWhitespaces; 54 50 55 51 public EbnfFormatterVisitor(EObject rootNode, FormatterConfig config) { … … 90 86 } 91 87 92 // private ArrayList<String> collectComments(CompositeNode node) {93 // collectedComments.clear();94 //// System.out.println(node);95 //// System.out.println(node.serialize());96 //// searchSubTree(node);97 // return collectedComments;98 // }99 100 88 private boolean isSingleLineComment(String str) { 101 89 if (str.startsWith("//")) … … 183 171 LeafNode currentComment = allComments.get(allCommentsPosition); 184 172 if (currentComment.getTotalOffset() == bufferPositionOriginalText) { 185 186 187 173 if (isMultiLineComment(currentComment.getText())) { 188 174 result.append(currentComment.getText()); 189 175 result.append("\n"); 190 } else {176 } else if (isSingleLineComment(currentComment.getText())) { 191 177 String lastWhiteSpaces = scanBackWhitespaces(result.toString(), result.toString().length()-1); 192 178 result.delete(result.toString().length() - lastWhiteSpaces.length(), result.toString().length()); … … 209 195 210 196 } 211 212 private void appendComments(EObject node) { 213 // String currentBuf = buf.toString().replaceAll("[ \t\n\r]", ""); 214 // while (bufferPosition < currentBuf.length()) { 215 // skipWhitespacesOriginalText(); 216 // System.out.print(currentBuf.charAt(bufferPosition)); 217 // System.out.print(originalText.charAt(bufferPositionOriginalText)); 218 // bufferPositionOriginalText++; 219 // bufferPosition++; 220 // } 221 222 // 223 // ArrayList<String> comments = collectComments(parseTreeNode); 224 // for (int i=0; i < comments.size(); i++) { 225 // if (isSingleLineComment(comments.get(i))) { 226 // buf.append(" "); 227 // buf.append(comments.get(i).trim()); 228 // if (i+1 < comments.size()) 229 // buf.append("\n"); 230 // } else if (isMultiLineComment(comments.get(i))) { 231 // buf.append("\n"); 232 // buf.append(comments.get(i)); 233 // if (i+1 < comments.size()) 234 // buf.append("\n"); 235 // } 236 // } 237 238 } 197 239 198 240 199 // ----------------------------------------------------------------------------- … … 252 211 buf.append(";"); 253 212 254 appendComments(node);255 256 213 buf.append("\n\n"); 257 214 } … … 334 291 protected void visitBefore(Import node) { 335 292 buf.append("import \"" + node.getImportURI() + "\";"); 336 appendComments(node);337 293 buf.append("\n"); 338 339 294 } 340 295 … … 407 362 408 363 buf.append(node.getSectionHeader()); 409 410 appendComments(node);411 364 } 412 365
Note: See TracChangeset
for help on using the changeset viewer.