Package com.puppetlabs.xtext.dommodel

Examples of com.puppetlabs.xtext.dommodel.IDomNode


      TextFlow measuredFlow = new TextFlow(innerContext);

      // iterate to format the LHS expression and measure, and find the = sign (which gets padded)
      Iterator<IDomNode> itor = aeNode.treeIterator();
      while(itor.hasNext()) {
        IDomNode n = itor.next();
        // forward until assignment expression =, or +=
        if(!(n.getGrammarElement() == theAssignmentExpression || n.getGrammarElement() == theAppendExpression))
          continue;

        // Measure assignment expression
        feeder.sequence(n, measuredFlow, innerContext, new FirstLeafWithTextAndTheRest(), untilTheEnd);

        // forward to = or += sign
        while(itor.hasNext()) {
          n = itor.next();
          if(n.getGrammarElement() == theEqualSign || n.getGrammarElement() == thePlusEqualSign)
            break;
        }
        if(n.getGrammarElement() == thePlusEqualSign)
          containsAppend = true;

        if(!itor.hasNext())
          break; // WAT, nothing after the '=', give up on this assignment, try to align the others

        // If assignment node already has a width, it was processed by a preceding assignment
        // and we were done a long time ago...
        //
        WidthStyle widthStyle = n.getStyles().getStyle(WidthStyle.class, n);
        if(widthStyle != null)
          return false;

        equalSignNodes.add(n);
View Full Code Here


    // assign widths and alignment to the fat comma nodes
    int opW = containsAppend
        ? 2
        : 1;
    for(int i = 0; i < equalSignNodes.size(); i++) {
      IDomNode c = equalSignNodes.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(opW + mw - w)));
    }
  }
View Full Code Here

        // used to measure output of formatted selector entry 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 fatCommaNode = feeder.sequence(n, measuredFlow, innerContext, caseFatCommaPredicate);

        fatCommaNodes.add(fatCommaNode);

        // collect the width of the last selector entry's values
        int lastLineWidth = measuredFlow.getWidthOfLastLine();
View Full Code Here

   */
  private void markupWidths(List<IDomNode> fatCommaNodes, List<Integer> widths, int availableWidth,
      IntegerCluster clusters, boolean doAlignment) {
    // assign widths and alignment to the fat comma nodes
    for(int i = 0; i < fatCommaNodes.size(); i++) {
      IDomNode c = fatCommaNodes.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(2 + mw - w)));
    }
  }
View Full Code Here

  protected void changeInlineStyle(IDomNode node, boolean set) {
    List<IDomNode> nodes = node.getChildren();
    Iterator<IDomNode> itor = nodes.iterator();
    while(itor.hasNext()) {
      IDomNode n = itor.next();
      IDomNode firstToken = firstSignificantNode(n);
      if(firstToken == null) {
        continue;
      }
      Set<Object> styleClassifiers = firstToken.getStyleClassifiers();
      if(set)
        styleClassifiers.add(StatementStyle.INLINE);
      else
        styleClassifiers.remove(StatementStyle.INLINE);
    }
View Full Code Here

   *
   * @param node
   * @return
   */
  protected IDomNode firstSignificantNode(IDomNode node) {
    IDomNode firstToken = DomModelUtils.firstTokenWithText(node);
    EObject o = node.getSemanticObject();
    if(o == null)
      return firstToken;
    List<INode> docNodes = documentationAssociator.getDocumentation(o);

    if(docNodes != null && docNodes.size() > 0) {
      INode firstDoc = docNodes.get(0);
      Iterator<IDomNode> itor = node.treeIterator();
      while(itor.hasNext()) {
        IDomNode n = itor.next();
        if(n.getNode() == firstDoc) {
          firstToken = n;
          break;
        }
        if(n == firstToken)
          break; // stop looking
View Full Code Here

    boolean first = true;
    Iterator<IDomNode> itor = nodes.iterator();
    int statementCount = 0;
    int blockCount = 0;
    while(itor.hasNext()) {
      IDomNode n = itor.next();
      if(n.getGrammarElement() == grammarElement) {
        IDomNode firstToken = firstSignificantNode(n);
        // IDomNode firstToken = DomModelUtils.firstTokenWithText(n);
        EObject semantic = n.getSemanticObject();
        if(first) {
          // first in body
          firstToken.getStyleClassifiers().add(StatementStyle.FIRST);
          first = false;
        }
        if(semantic instanceof SeparatorExpression)
          continue; // skip marking this
        // mark all (except func args) as being a STATEMENT
        firstToken.getStyleClassifiers().add(StatementStyle.STATEMENT);
        statementCount++;
        if(isBlockStatement(semantic)) {
          firstToken.getStyleClassifiers().add(StatementStyle.BLOCK);
          blockCount++;
        }
        else if(semantic instanceof LiteralNameOrReference) {
          // this is an unparenthesized function call
          firstToken.getStyleClassifiers().add(StatementStyle.UNPARENTHESIZED_FUNCTION);
          // skip the optional single argument that follows
          if(itor.hasNext()) {
            n = itor.next();
          }
        }
View Full Code Here

    }

    final String lineSeparator = context.getLineSeparatorInformation().getLineSeparator();
    final int indentSize = context.getIndentationInformation().getIndentString().length();
    boolean allIsWell = false;
    IDomNode next = dom;
    int linePos = DomModelUtils.posOnLine(next, lineSeparator);
    do {
      allIsWell = false;
      next = next.getNextSibling();
      if(next != null && DomModelUtils.isWhitespace(next) && intersect(next, context).isContained()) {
        String t = next.getText();
        if(t.contains("\n")) {
          allIsWell = false;
        }
        else {
          if(Math.abs(t.length() - linePos) < indentSize) {
            IDomNode next2 = next.getNextSibling();
            if(next2 != null && isCompatibleComment(next2, commentConfiguration)) {
              result.add(next);
              result.add(next2);
              next = next2;
              allIsWell = true;
View Full Code Here

    IntegerCluster cluster = new IntegerCluster(clusterMax);
    // int max = 0;
    Iterator<IDomNode> iterator = dom.treeIterator();
    List<IDomNode> affected = Lists.newArrayList();
    while(iterator.hasNext()) {
      IDomNode node = iterator.next();
      if(node.getGrammarElement() == grammarElement) {
        // node = DomModelUtils.firstTokenWithText(node);
        if(node.getText() == null)
          continue;
        int length = node.getText().length();
        cluster.add(length);
        //
        // max = Math.max(max, node.getText() == null
        // ? 0
        // : node.getText().length());
        affected.add(node);
      }
    }
    for(IDomNode node : affected)
      node.getStyles().add(StyleSet.withStyles(//
        new StyleFactory.WidthStyle(cluster.clusterMax(node.getText().length())), //
        new StyleFactory.AlignmentStyle(alignment)));
  }
View Full Code Here

      // output a conforming number of line breaks
      // possibly accept a comment as a linebreak if this whitespace did not already contain
      // a break
      int emittedLinebreaks = 0;
      if(existingLinebreaks == 0 && linebreaks.isCommentEndingWithBreakAcceptable()) {
        IDomNode n = DomModelUtils.nextLeaf(node);
        if(n != null && n.getNodeType() == NodeType.COMMENT &&
            n.getStyleClassifiers().contains(NodeClassifier.LINESEPARATOR_TERMINATED)) {
          // comment breaks the line
          output.appendSpaces(1); // separate the comment with a space

          // format the comment with layout manager given by rules (or this layout by default)
          final StyleSet styleSet = context.getCSS().collectStyles(n);
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.