Ejemplo n.º 1
0
 private void assignAlignmentAndWidths(
     Map<IDomNode, Integer> operatorNodes, IntegerCluster cluster) {
   for (Entry<IDomNode, Integer> entry : operatorNodes.entrySet()) {
     int w = entry.getValue();
     entry
         .getKey()
         .getStyles()
         .add(
             StyleSet.withStyles(
                 styles.align(Alignment.right), styles.width(2 + cluster.clusterMax(w) - w)));
   }
 }
Ejemplo n.º 2
0
  @Override
  protected void markup(
      IDomNode node,
      final boolean breakAndAlign,
      final int clusterWidth,
      ITextFlow flow,
      ILayoutContext context) {

    Iterator<IDomNode> itor = node.treeIterator();
    Map<IDomNode, Integer> operatorNodes = Maps.newHashMap();
    IntegerCluster cluster = new IntegerCluster(clusterWidth);

    final LiteralHashElements access = grammarAccess.getLiteralHashAccess();
    final HashEntryElements hashAccess = grammarAccess.getHashEntryAccess();
    int previousKeyWidth = 0;
    while (itor.hasNext()) {
      IDomNode n = itor.next();
      EObject ge = n.getGrammarElement();
      if (ge == access.getLeftCurlyBracketKeyword_1()) {
        IDomNode nextLeaf = DomModelUtils.nextWhitespace(n);
        if (DomModelUtils.isWhitespace(nextLeaf) && breakAndAlign)
          nextLeaf.getStyles().add(StyleSet.withStyles(styles.oneLineBreak()));
      } else if (breakAndAlign) {
        if (ge == access.getCommaKeyword_2_1_0()) {
          IDomNode nextLeaf = DomModelUtils.nextWhitespace(n);
          if (DomModelUtils.isWhitespace(nextLeaf))
            nextLeaf.getStyles().add(StyleSet.withStyles(styles.oneLineBreak()));
        } else if (ge == hashAccess.getKeyLiteralNameOrStringParserRuleCall_0_0()) {
          DelegatingLayoutContext keyContext = new DelegatingLayoutContext(context);
          TextFlow keyFlow = new TextFlow(keyContext);
          ArrayList<IDomNode> children = Lists.newArrayList(n.getChildren());
          for (Iterator<IDomNode> subitor = children.iterator(); subitor.hasNext(); ) {
            IDomNode x = subitor.next();
            NodeType t = x.getNodeType();
            if (t == NodeType.ACTION || t == NodeType.WHITESPACE) {
              subitor.remove();
              continue;
            }
            break; // first non whitespace or action
          }
          feeder.sequence(children, keyFlow, context);
          previousKeyWidth = keyFlow.getWidthOfLastLine();
          cluster.add(previousKeyWidth);
          System.out.println("node= [" + keyFlow.getText() + "] width = " + previousKeyWidth);
        } else if (ge == hashAccess.getEqualsSignGreaterThanSignKeyword_1()) {
          operatorNodes.put(n, previousKeyWidth);
        }
      }
    }

    if (breakAndAlign) assignAlignmentAndWidths(operatorNodes, cluster);
  }