/** * Generates the string representation of the string, assuming that it is going to be used in a place that doesn't * require parenthesis. If this isn't the case consider using the {@link #toString(boolean)} method, passing the * {@code true} as the value of the {@code protect} parameter. */ @Override public String toString() { return toString(false); } }
private Expression transformUnary(UnaryExpression expression) { // Transform the operand: Expression operand = expression.getOperand(); if (operand == null) { throw new IllegalArgumentException("The operand in expression \"" + expression + "\" is null"); } operand = transform(operand); // Compute the type: Operator operator = expression.getOperator(); Type type; switch (operator) { case NOT: type = model.getBooleanType(); break; case SUBTRACT: type = operand.getType(); break; default: throw new IllegalArgumentException( "The operator \"" + operator + "\" in expression \"" + expression + "\" isn't supported" ); } // Return the result: UnaryExpression result = new UnaryExpression(); result.setType(type); result.setOperator(operator); result.setOperand(operand); return result; }
private Expression transformArray(ArrayExpression expression) { // Transform the array: Expression array = expression.getArray(); if (array == null) { throw new IllegalArgumentException("The array in array expression \"" + expression + "\" is null"); } array = transform(array); // Transform the index: Expression index = expression.getIndex(); if (index == null) { throw new IllegalArgumentException("The index in array expression \"" + expression + "\" is null"); } index = transform(index); // Compute the type: Type type = null; Type arrayType = array.getType(); if (arrayType instanceof ListType) { ListType listType = (ListType) arrayType; type = listType.getElementType(); } // Return the result: ArrayExpression result = new ArrayExpression(); result.setType(type); result.setArray(array); result.setIndex(index); return result; }
@Override public String toString(boolean protect) { StringBuilder buffer = new StringBuilder(); if (protect) { buffer.append("("); } buffer.append(left.toString(true)); buffer.append(" "); buffer.append(operator); buffer.append(" "); buffer.append(right.toString(true)); if (protect) { buffer.append(")"); } return buffer.toString(); } }
Type type = target.getType(); if (type instanceof StructType) { StructType struct = (StructType) type;
@Override public String toString(boolean protect) { StringBuilder buffer = new StringBuilder(); if (protect) { buffer.append("("); } if (array != null) { buffer.append(array.toString(true)); } buffer.append("["); if (index != null) { buffer.append(index.toString(false)); } buffer.append("]"); if (protect) { buffer.append(")"); } return buffer.toString(); } }
@Override public String toString(boolean protect) { StringBuilder buffer = new StringBuilder(); if (target != null) { if (protect) { buffer.append("("); } buffer.append(target.toString(true)); buffer.append("."); buffer.append(field); if (protect) { buffer.append(")"); } } else { buffer.append(field); } return buffer.toString(); } }
@Override public String toString(boolean protect) { StringBuilder buffer = new StringBuilder(); if (target != null) { if (protect) { buffer.append("("); } buffer.append(target.toString(true)); buffer.append("."); buffer.append(attribute); if (protect) { buffer.append(")"); } } else { buffer.append(attribute); } return buffer.toString(); } }
@Override public String toString(boolean protect) { StringBuilder buffer = new StringBuilder(); if (target != null) { if (protect) { buffer.append("("); } buffer.append(target.toString(true)); buffer.append("."); buffer.append(link); if (protect) { buffer.append(")"); } } else { buffer.append(link); } return buffer.toString(); } }
@Override public String toString(boolean protect) { StringBuilder buffer = new StringBuilder(); if (protect) { buffer.append("("); } if (operator != null) { buffer.append(operator); if (operator == Operator.NOT) { buffer.append(" "); } } if (operand != null) { buffer.append(operand.toString(true)); } if (protect) { buffer.append(")"); } return buffer.toString(); } }
@Override public String toString(boolean protect) { StringBuilder buffer = new StringBuilder(); if (protect) { buffer.append("("); } if (target != null) { buffer.append(target.toString(true)); buffer.append("."); } if (method != null) { buffer.append(method); } buffer.append("("); boolean first = true; for (Expression parameter : parameters) { if (!first) { buffer.append(", "); } buffer.append(parameter.toString(false)); first = false; } buffer.append(")"); if (protect) { buffer.append(")"); } return buffer.toString(); } }