blob: c3db1d4bb3c3bcaa13af3a6e4739ecadd47d7ea6 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2001 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Corporation - initial API and implementation
******************************************************************************/
package org.eclipse.jdt.core.dom;
/**
* Number literal nodes.
*
* @since 2.0
*/
public class NumberLiteral extends Expression {
/**
* The token string; defaults to the integer literal "0".
*/
private String tokenValue = "0";//$NON-NLS-1$
/**
* Creates a new unparented number literal node owned by the given AST.
* By default, the number literal is the token "<code>0</code>".
* <p>
* N.B. This constructor is package-private.
* </p>
*
* @param ast the AST that is to own this node
*/
NumberLiteral(AST ast) {
super(ast);
}
/* (omit javadoc for this method)
* Method declared on ASTNode.
*/
ASTNode clone(AST target) {
NumberLiteral result = new NumberLiteral(target);
result.setToken(getToken());
return result;
}
/* (omit javadoc for this method)
* Method declared on ASTNode.
*/
boolean equalSubtrees(Object other) {
if (!(other instanceof NumberLiteral)) {
return false;
}
NumberLiteral o = (NumberLiteral) other;
return ASTNode.equals(getToken(), o.getToken());
}
/* (omit javadoc for this method)
* Method declared on ASTNode.
*/
void accept0(ASTVisitor visitor) {
boolean visitChildren = visitor.visit(this);
visitor.endVisit(this);
}
/**
* Returns the token of this number literal node. The value is the sequence
* of characters that would appear in the source program.
*
* @return the numeric literal token
*/
public String getToken() {
return tokenValue;
}
/**
* Sets the token of this number literal node. The value is the sequence
* of characters that would appear in the source program.
*
* @param token the numeric literal token
* @exception $precondition-violation:invalid-argument$
*/
public void setToken(String token) {
if (token == null || token.length() == 0) {
throw new IllegalArgumentException();
}
modifying();
// FIXME - check the token more thoroughly
// ideally, scan it to ensure that it is legal
this.tokenValue = token;
}
/* (omit javadoc for this method)
* Method declared on ASTNode.
*/
int memSize() {
int size = BASE_NODE_SIZE + 1 * 4;
if (tokenValue != null) {
size += HEADERS + 2 * 4 + HEADERS + 2 * tokenValue.length();
}
return size;
}
/* (omit javadoc for this method)
* Method declared on ASTNode.
*/
int treeSize() {
return memSize();
}
}