public boolean visit()

in ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormattedPrinter.java [346:518]


  public boolean visit(Expression s) throws Exception {
    // traverse Block (first child of root element:
    if (s instanceof Block) {
      return true;
    }
    if (s instanceof ComposedRuleElement) {
      ComposedRuleElement cre = (ComposedRuleElement) s;
      List<Expression> elements = cre.getElements();
      // int length = cre.sourceEnd() - cre.sourceStart();
      if (inLargeRule == 2) {
        inLargeRule = 4;
      }
      if (cre.isAfterConcat()) {
        append(CONCAT_RULES);
      }
      append(PAR_OPEN);
      String sep = "";
      if (cre.isDisjunctive() != null) {
        if (cre.isDisjunctive()) {
          sep = " |";
        } else {
          sep = " &";
        }
      }
      traverseAstNodes(elements, sep);
      append(PAR_CLOSE);
      appendRuleElement(cre);
      if (inLargeRule == 4) {
        inLargeRule = 1;
      }
      return false;
    }
    // special format for RuleElements:
    if (s instanceof RutaRuleElement) {
      RutaRuleElement ruleEl = (RutaRuleElement) s;
      if (inLargeRule == 2) {
        appendNewLine();
      } else if (inLargeRule == 1) {
        inLargeRule = 2;
      }
      if (ruleEl.isAfterConcat()) {
        append(CONCAT_RULES);
      }
      appendRuleElement(ruleEl);
      return false;
    }
    // special format for actions
    if (s instanceof RutaAction) {
      RutaAction a = (RutaAction) s;
      String name = document.get(a.getNameStart(), a.getNameEnd());
      append(name);
      List<? extends ASTNode> childs = a.getChilds();
      if (childs != null && !childs.isEmpty()) {
        boolean addPar = !a.getName().equals(ActionFactory.IMPLICIT);
        if (addPar) {
          append(PAR_OPEN);
        }
        // special format for create
        if (a instanceof RutaStructureAction) {
          if (name.equals("TRIE")) {
            printStructureAction2(a);
          } else {
            printStructureAction(a);
          }
        } else {
          traverseAstNodes(childs);
        }
        // special format for log
        if (a instanceof RutaLogAction && ((RutaLogAction) a).isLogLevelAssigned()) {
          appendSeparator(COMMA);
          RutaLogAction logAction = (RutaLogAction) a;
          append(logAction.getLogLevelStart(), logAction.getLogLevelEnd());
        }
        if (addPar) {
          append(PAR_CLOSE);
        }
      }
      return false;
    }
    // special format for conditions
    if (s instanceof RutaCondition) {
      RutaCondition c = (RutaCondition) s;
      append(document.get(c.getNameStart(), c.getNameEnd()));
      List<? extends ASTNode> childs = c.getChilds();
      // minus is a condition without parameter parantheses:
      boolean addPar = !c.getName().equals(ConditionFactory.IMPLICIT)
              && s.getKind() != RutaConditionConstants.COND_MINUS && childs != null
              && !childs.isEmpty();
      if (addPar) {
        append(PAR_OPEN);
      }
      traverseAstNodes(childs);
      if (addPar) {
        append(PAR_CLOSE);
      }
      return false;
    }
    // special format for boolean number expressions
    if (s instanceof RutaBooleanCompareExpression) {
      RutaBooleanCompareExpression tmbne = (RutaBooleanCompareExpression) s;
      append(PAR_OPEN);
      if (tmbne.getE1() != null) {
        tmbne.getE1().traverse(this);
      }
      append(tmbne.getOperator());
      if (tmbne.getE2() != null) {
        tmbne.getE2().traverse(this);
      }
      append(PAR_CLOSE);
      return false;
    }
    // special format for string expressions
    if (s instanceof RutaStringExpression && ((RutaExpression) s).getExpression() != null) {
      RutaStringExpression tmse = (RutaStringExpression) s;
      List<?> childs = tmse.getExpression().getChilds();
      Object object2 = childs.get(0);
      if (object2 instanceof ASTNode) {
        ASTNode astnode = (ASTNode) object2;
        List<?> childs2 = astnode.getChilds();
        for (Object object : childs2) {
          if (object instanceof RutaExpression) {
            RutaExpression expr = (RutaExpression) object;
            // if (expr.isInParantheses()) {
            // append(PAR_OPEN);
            // append(expr);
            // append(PAR_CLOSE);
            // } else {
            append(expr);
            // }
          } else if (object instanceof StringLiteral) {
            StringLiteral sl = (StringLiteral) object;
            String value = sl.getValue();
            append(value);
          } else if (object instanceof RutaVariableReference) {
            RutaVariableReference vr = (RutaVariableReference) object;
            append(vr.getName());
          }
          if (childs2.indexOf(object) < childs2.size() - 1) {
            append(CONCAT);
          }
        }
      } else {
        append(s);
      }
      return false;
    }
    if (s instanceof RutaListExpression) {
      RutaListExpression le = (RutaListExpression) s;
      append(CURLY_OPEN);
      ASTListNode exprs = le.getExprs();
      traverseAstNodes(exprs.getChilds());
      append(CURLY_CLOSE);
      return false;
    }

    // special format for paranthesed expressions: (expression)
    // if (s instanceof RutaExpression && ((RutaExpression) s).isInParantheses()) {
    // append(PAR_OPEN);
    // append(s);
    // append(PAR_CLOSE);
    // return false;
    // }
    if (s instanceof RutaBinaryArithmeticExpression) {
      RutaBinaryArithmeticExpression ba = (RutaBinaryArithmeticExpression) s;
      String operator = ba.getOperator();
      append(operator);
      append(PAR_OPEN);
      traverseAstNodes(ba.getChilds());
      append(PAR_CLOSE);
    }
    append(s);
    return false;
  }