Package ru.snake.spritepacker.writer.expression

Source Code of ru.snake.spritepacker.writer.expression.ConstantExpression

package ru.snake.spritepacker.writer.expression;

import ru.snake.spritepacker.writer.expression.value.Value;

public class ConstantExpression implements Expression {

  private final Value value;

  public ConstantExpression() {
    this.value = new Value();
  }

  public ConstantExpression(String value) {
    this.value = new Value(value);
  }

  public Value getValue() {
    return value;
  }

  public void visit(ExpressionVisitor visitor) {
    visitor.visitConstant(this);
  }

  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder();

    if (value == null) {
      builder.append("[CONST]");
    } else if (value.isInteger()) {
      builder.append(value.getString());
    } else {
      builder.append('"');
      builder.append(value.getString());
      builder.append('"');
    }

    return builder.toString();
  }

}
TOP

Related Classes of ru.snake.spritepacker.writer.expression.ConstantExpression

TOP
Copyright © 2018 www.massapi.com. 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.