Newer
Older
AlgebraicDataflowArchitectureModel / AlgebraicDataflowArchitectureModel / src / code / ast / NumberLiteral.java
package code.ast;

/**
 * Represents a numeric literal expression in the AST.
 *
 * @author s-yamagiwa
 */
public class NumberLiteral extends Expression {
	/**
	 * Represents the raw string value of a numeric token in the source code.
	 * This variable stores the literal text that defines a numeric value, including
	 * any prefixes, suffixes, or delimiters used in the representation of the number.
	 */
	private String tokenValue;
	
	/**
	 * Constructs a new NumberLiteral instance with the specified token value.
	 *
	 * @param tokenValue - The literal text representing the numeric value in the source code.
	 */
	public NumberLiteral(String tokenValue) {
		setTokenValue(tokenValue);
	}
	
	/**
	 * Retrieves the raw string value of the numeric token in the source code.
	 *
	 * @return The raw string value of the numeric token.
	 */
	public String getTokenValue() {
		return tokenValue;
	}
	
	/**
	 * Sets the raw string value of the numeric token in the source code.
	 *
	 * @param tokenValue - The raw string value of the numeric token.
	 * @throws IllegalArgumentException if the specified token value is null, empty, or invalid number representation in Java source code.
	 */
	public void setTokenValue(String tokenValue) {
		if (tokenValue == null) {
			throw new IllegalArgumentException("Token value must not be null.");
		}
		
		int length = tokenValue.length();
		if (length == 0) {
			throw new IllegalArgumentException("Token value must not be empty.");
		}
		
		// TODO: 0 check
		// TODO: Binary number
		// TODO: Octal number
		
		if (NumberUtil.isHexNumber(tokenValue)) {
			this.tokenValue = tokenValue;
		}
	}
	
	@Override
	public String toString() {
		return tokenValue;
	}
}