Package com.puppetlabs.xtext.dommodel

Examples of com.puppetlabs.xtext.dommodel.IDomNode


    // if this is the root
    if(getParent() == null) {
      // recalculate offsets starting with 0
      setOffset(0);
      // find and mark first and last token
      IDomNode first = DomModelUtils.firstTokenWithText(this);
      IDomNode last = DomModelUtils.lastTokenWithText(this);
      if(first != null && first instanceof AbstractDomNode)
        ((AbstractDomNode) first).setClassifiers(true, NodeClassifier.FIRST_TOKEN);
      if(last != null && last instanceof AbstractDomNode)
        ((AbstractDomNode) last).setClassifiers(true, NodeClassifier.LAST_TOKEN);
    }
View Full Code Here


      return currentIterator.hasNext();
    }

    @Override
    public IDomNode next() {
      IDomNode current = currentIterator.next();
      if(!current.isLeaf()) {
        // come back to currentIterator later if there are more
        if(currentIterator.hasNext())
          stack.add(currentIterator);
        currentIterator = current.getChildren().iterator();
      }
      return current;
    }
View Full Code Here

      getRootNode().doLayout();
    return offset;
  }

  private BaseDomNode getParentAsBaseDomNode() {
    IDomNode p = getParent();
    if(p == null)
      return null;
    if(p instanceof BaseDomNode == false)
      throw new IllegalStateException("A BaseDomNode must be parented by a BaseDomNode");
    return (BaseDomNode) p;
View Full Code Here

    sequence(nodes, output, context, Predicates.<IDomNode> alwaysTrue(), Predicates.<IDomNode> alwaysFalse());
  }

  public IDomNode sequence(Collection<IDomNode> nodes, ITextFlow output, ILayoutContext context,
      Predicate<IDomNode> include, Predicate<IDomNode> until) {
    IDomNode last = null;
    for(IDomNode n : nodes) {
      if(until.apply(n))
        return n;
      last = sequence(n, output, context, include, until);
    }
View Full Code Here

    final ILayoutManager layout = styleSet.getStyleValue(LayoutManagerStyle.class, node, defaultLayout);

    layout.beforeComposite(styleSet, node, output, context);
    // if layout of composite by layout manager returns true, children are already processed
    IDomNode last = null;
    if(!layout.format(styleSet, node, output, context))
      for(IDomNode n : node.getChildren()) {
        if(until.apply(n))
          return n;
        last = sequence(n, output, context, include, until);
View Full Code Here

    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
View Full Code Here

        // used to measure output of formatted case values
        // adjust its width to available width (and do not mark items consumed in the given context)
        DelegatingLayoutContext innerContext = new DelegatingLayoutContext(context, availableWidth);
        TextFlow measuredFlow = new TextFlow(innerContext);
        // visit all nodes in case until the colon is hit, and format the output to the measured flow
        IDomNode colonNode = feeder.sequence(n, measuredFlow, innerContext, caseColonPredicate);
        if(doCompaction && !n.getStyleClassifiers().contains(StatementStyle.COMPACTABLE))
          allCompactable = false;

        colonNodes.add(colonNode);
View Full Code Here

  private boolean compactable(List<IDomNode> colonNodes, List<Integer> remainingWidths, ILayoutContext context) {
    // must measure each, stop if not all fits, otherwise prevent compaction
    final Predicate<IDomNode> alwaysFalse = Predicates.<IDomNode> alwaysFalse();
    for(int i = 0; i < colonNodes.size(); i++) {
      IDomNode p = colonNodes.get(i).getParent();
      IDomNode statements = DomModelUtils.nodeForGrammarElement(
        p, grammarAccess.getCaseAccess().getStatementsExpressionListParserRuleCall_4_0());
      DelegatingLayoutContext caseStatementContext = new DelegatingLayoutContext(context, remainingWidths.get(i));
      TextFlow caseStatementFlow = new TextFlow(caseStatementContext);
      if(statements != null)
        feeder.sequence(
View Full Code Here

  private void markupCompact(List<IDomNode> colonNodes, List<Integer> remainingWidths, ILayoutContext context) {

    if(compactable(colonNodes, remainingWidths, context))
      // prevent whitespace after '{' and before '}' to break
      for(int i = 0; i < colonNodes.size(); i++) {
        IDomNode p = colonNodes.get(i).getParent();
        for(IDomNode n : p.getChildren()) {
          if(n.getGrammarElement() == grammarAccess.getCaseAccess().getLeftCurlyBracketKeyword_3()) {
            IDomNode ws = DomModelUtils.nextWhitespace(n);
            if(ws != null)
              ws.getStyles().add(StyleSet.withStyles(styles.oneSpace(), styles.noLineBreak()));
          }
          else if(n.getGrammarElement() == grammarAccess.getCaseAccess().getRightCurlyBracketKeyword_5()) {
            IDomNode ws = DomModelUtils.previousWhitespace(n);
            if(ws != null)
              ws.getStyles().add(StyleSet.withStyles(styles.oneSpace(), styles.noLineBreak()));
          }
        }
      }
  }
View Full Code Here

    // compute available width for remainder if all cases are compactable
    List<Integer> remainingWidths = doCompaction
        ? Lists.<Integer> newArrayList()
        : null;
    for(int i = 0; i < colonNodes.size(); i++) {
      IDomNode c = colonNodes.get(i);
      int w = widths.get(i);
      int mw = doAlignment
          ? clusters.clusterMax(w)
          : w;
      if(doAlignment)
        c.getStyles().add(StyleSet.withStyles(styles.align(Alignment.right), //
          styles.width(1 + mw - w)));
      if(doCompaction)
        remainingWidths.add(availableWidth - mw - 6); // 6 = ": { " +" }"
    }
    return remainingWidths;
View Full Code Here

TOP

Related Classes of com.puppetlabs.xtext.dommodel.IDomNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.