Changeset 30 in default
- Timestamp:
- 11/02/10 17:25:47 (14 years ago)
- Location:
- trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/EbnfFormatterVisitor.java
r29 r30 8 8 import org.eclipse.xtext.parsetree.CompositeNode; 9 9 import org.eclipse.xtext.parsetree.LeafNode; 10 import org.eclipse.xtext.parsetree.NodeAdapter; 10 11 import org.eclipse.xtext.parsetree.NodeUtil; 11 12 … … 52 53 private int rightHandSideRuleOffset = 0; 53 54 private Stack<Integer> ruleSpacingStack = new Stack<Integer>(); 55 private Double averageSingleDefinitionLength; 54 56 55 57 public EbnfFormatterVisitor(EObject rootNode, FormatterConfig config) { … … 258 260 } 259 261 buf = result; 260 261 262 } 262 263 … … 294 295 originalTextNoWhitespaces = originalText.replaceAll("[ \t\n\r]", ""); 295 296 296 //System.out.println(allComments.toString());297 297 text("grammar " + node.getName()); 298 298 if (node.getType() != null) … … 348 348 349 349 protected void visitBefore(DefinitionList node) { 350 averageSingleDefinitionLength = null; 351 int totalLength = 0; 352 for (int i=0; i < node.eContents().size(); i++) { 353 CompositeNode parseNode = NodeUtil.getNodeAdapter(node.eContents().get(i)).getParserNode(); 354 totalLength += parseNode.serialize().trim().length(); 355 } 356 averageSingleDefinitionLength = (double) totalLength / (double) node.eContents().size(); 350 357 } 351 358 … … 458 465 459 466 lastWasSectionHeading=true; 460 // if (!lastWasSectionHeading || !buf.substring(buf.length()-2).equals("\n\n"))461 // if (!buf.substring(buf.length()-2).equals("\n\n"))462 // buf.append("\n");463 467 464 468 text(node.getSectionHeader()); … … 472 476 473 477 protected void visitAfter(SingleDefinition node) { 478 boolean preventAlternativeBreakShortAlternatives = config.isPreventNewLineAfterAlternativeOnShortAlternatives() && (averageSingleDefinitionLength <= config.getShortAlternativeThreshold()); 474 479 if (!isLastElement()) { 475 480 text(" | "); … … 477 482 if (config.isPreventNewLineAfterAlternativeOnLessThanThreeElements()) { 478 483 DefinitionList definitionList = (DefinitionList) node.eContainer(); 479 if (definitionList.eContents().size() > 2) { 484 485 if ((definitionList.eContents().size() > 2) && (!preventAlternativeBreakShortAlternatives)) { 480 486 newLine(); 481 487 spaces(ruleSpacingStack.peek()); 482 488 } 483 489 } else { 484 newLine(); 485 spaces(ruleSpacingStack.peek()); 490 if (!preventAlternativeBreakShortAlternatives) { 491 newLine(); 492 spaces(ruleSpacingStack.peek()); 493 } 486 494 } 487 495 } -
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/FormatterConfig.java
r29 r30 5 5 private boolean preventNewLineAfterAlternativeOnLessThanThreeElements = true; 6 6 private boolean preventNewLineAfterAlternativeOnShortAlternatives = true; 7 private double shortAlternativeThreshold = 3.0; 7 8 8 9 public boolean isNewLineAfterAlternative() { … … 32 33 } 33 34 35 public double getShortAlternativeThreshold() { 36 return shortAlternativeThreshold; 37 } 38 39 public void setShortAlternativeThreshold(double shortAlternativeThreshold) { 40 this.shortAlternativeThreshold = shortAlternativeThreshold; 41 } 42 34 43 }
Note: See TracChangeset
for help on using the changeset viewer.