Package com.puppetlabs.xtext.dommodel.formatter

Examples of com.puppetlabs.xtext.dommodel.formatter.DelegatingLayoutContext


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


    // Step 1, must format up to the first case expression to know the correct indentation of the case
    // expression. (At point of entry to this method, the whitespace between a preceding statement and the case
    // expression has not yet been processed, and thus, no WS, break, indent etc. has taken place.
    //
    DelegatingLayoutContext dlc = new DelegatingLayoutContext(context);
    MeasuredTextFlow continuedFlow = new MeasuredTextFlow((MeasuredTextFlow) flow);

    int currentMaxWidth = flow.getPreferredMaxWidth();
    int availableWidth = 0; // set when first case is seen

    IBreakAndAlignAdvice advice = adviceProvider.get();
    final boolean doCompaction = advice.compactCasesWhenPossible();
    final boolean doAlignment = advice.isAlignCases();

    // used to collect the widths of each case's width of its values
    List<Integer> widths = Lists.newArrayList();
    // int maxLastLine = 0;
    boolean firstCaseSeen = false;
    List<IDomNode> colonNodes = Lists.newArrayList();
    IntegerCluster clusters = new IntegerCluster(20);
    boolean allCompactable = true; // until proven wrong
    for(IDomNode n : node.getChildren()) {
      if(n.getGrammarElement() == caseRuleCall) {
        if(!firstCaseSeen) {
          // finish measurement of the position the case will appear at
          //
          continuedFlow.appendBreak();
          continuedFlow.getIndentation();
          availableWidth = currentMaxWidth - (continuedFlow.getIndentation() + 1) *
              continuedFlow.getIndentSize();
        }
        // 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;
View Full Code Here

    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(
          statements, caseStatementFlow, caseStatementContext, new SkipInitialWhitespacePredicate(),
          alwaysFalse);
View Full Code Here

    boolean containsAppend = false;

    // while siblings are assignments, starting with the current one
    for(IDomNode aeNode = node; aeNode != null && includeInSequence(aeNode); aeNode = aeNode.getNextSibling()) {
      DelegatingLayoutContext innerContext = new DelegatingLayoutContext(context, availableWidth);
      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()) {
View Full Code Here

    // Step 1, must format up to the first selector entry expression to know the correct indentation of the selector entry
    // expression. (At point of entry to this method, the whitespace between a preceding statement and the selector
    // expression has not yet been processed, and thus, no WS, break, indent etc. has taken place.
    //
    DelegatingLayoutContext dlc = new DelegatingLayoutContext(context);
    MeasuredTextFlow continuedFlow = new MeasuredTextFlow((MeasuredTextFlow) flow);

    int currentMaxWidth = flow.getPreferredMaxWidth();
    int availableWidth = 0; // set when first case is seen

    // IBreakAndAlignAdvice advice = adviceProvider.get(); // TODO: Advice? this formatting ?
    final boolean doAlignment = true; // advice.isAlignCases();

    // used to collect the widths of each case's width of its values
    List<Integer> widths = Lists.newArrayList();
    // int maxLastLine = 0;
    boolean firstSelectoEntrySeen = false;
    List<IDomNode> fatCommaNodes = Lists.newArrayList();
    IntegerCluster clusters = new IntegerCluster(SELECTOR_EXPRESSION_CLUSTER_SIZE);
    for(IDomNode n : node.getChildren()) {
      if(n.getGrammarElement() instanceof RuleCall &&
          ((RuleCall) n.getGrammarElement()).getRule() == selectorEntryRule) {
        if(!firstSelectoEntrySeen) {
          // finish measurement of the position the selectorEntry will appear at
          //
          continuedFlow.appendBreak();
          continuedFlow.getIndentation();
          availableWidth = currentMaxWidth - (continuedFlow.getIndentation() + 1) *
              continuedFlow.getIndentSize();
        }
        // 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);
View Full Code Here

        break;
    }
    if(compactResource && styles.contains(ResourceStyle.COMPACTABLE)) {
      // must check if rendering would overflow
      node.getStyleClassifiers().addAll(styles);
      DelegatingLayoutContext dlc = new DelegatingLayoutContext(context);
      MeasuredTextFlow continuedFlow = new MeasuredTextFlow((MeasuredTextFlow) flow);
      int heightBefore = continuedFlow.getHeight();
      feeder.sequence(node.getChildren(), continuedFlow, dlc, new FirstLeafWithTextAndTheRest(), untilTheEnd);
      if(continuedFlow.getHeight() - heightBefore > 2) {
        node.getStyleClassifiers().remove(ResourceStyle.COMPACTABLE);
View Full Code Here

TOP

Related Classes of com.puppetlabs.xtext.dommodel.formatter.DelegatingLayoutContext

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.