1 11 12 package org.eclipse.jdt.core.dom; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.jdt.core.compiler.InvalidInputException; 18 import org.eclipse.jdt.internal.compiler.parser.Scanner; 19 import org.eclipse.jdt.internal.compiler.parser.TerminalTokens; 20 21 26 public class NumberLiteral extends Expression { 27 28 32 public static final SimplePropertyDescriptor TOKEN_PROPERTY = 33 new SimplePropertyDescriptor(NumberLiteral.class, "token", String .class, MANDATORY); 35 40 private static final List PROPERTY_DESCRIPTORS; 41 42 static { 43 List propertyList = new ArrayList (2); 44 createPropertyList(NumberLiteral.class, propertyList); 45 addProperty(TOKEN_PROPERTY, propertyList); 46 PROPERTY_DESCRIPTORS = reapPropertyList(propertyList); 47 } 48 49 60 public static List propertyDescriptors(int apiLevel) { 61 return PROPERTY_DESCRIPTORS; 62 } 63 64 67 private String tokenValue = "0"; 69 78 NumberLiteral(AST ast) { 79 super(ast); 80 } 81 82 85 final List internalStructuralPropertiesForType(int apiLevel) { 86 return propertyDescriptors(apiLevel); 87 } 88 89 92 final Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, Object value) { 93 if (property == TOKEN_PROPERTY) { 94 if (get) { 95 return getToken(); 96 } else { 97 setToken((String ) value); 98 return null; 99 } 100 } 101 return super.internalGetSetObjectProperty(property, get, value); 103 } 104 105 108 final int getNodeType0() { 109 return NUMBER_LITERAL; 110 } 111 112 115 ASTNode clone0(AST target) { 116 NumberLiteral result = new NumberLiteral(target); 117 result.setSourceRange(this.getStartPosition(), this.getLength()); 118 result.setToken(getToken()); 119 return result; 120 } 121 122 125 final boolean subtreeMatch0(ASTMatcher matcher, Object other) { 126 return matcher.match(this, other); 128 } 129 130 133 void accept0(ASTVisitor visitor) { 134 visitor.visit(this); 135 visitor.endVisit(this); 136 } 137 138 144 public String getToken() { 145 return this.tokenValue; 146 } 147 148 155 public void setToken(String token) { 156 if (token == null || token.length() == 0) { 158 throw new IllegalArgumentException (); 159 } 160 Scanner scanner = this.ast.scanner; 161 char[] source = token.toCharArray(); 162 scanner.setSource(source); 163 scanner.resetTo(0, source.length); 164 scanner.tokenizeComments = false; 165 scanner.tokenizeWhiteSpace = false; 166 try { 167 int tokenType = scanner.getNextToken(); 168 switch(tokenType) { 169 case TerminalTokens.TokenNameDoubleLiteral: 170 case TerminalTokens.TokenNameIntegerLiteral: 171 case TerminalTokens.TokenNameFloatingPointLiteral: 172 case TerminalTokens.TokenNameLongLiteral: 173 break; 174 case TerminalTokens.TokenNameMINUS : 175 tokenType = scanner.getNextToken(); 176 switch(tokenType) { 177 case TerminalTokens.TokenNameDoubleLiteral: 178 case TerminalTokens.TokenNameIntegerLiteral: 179 case TerminalTokens.TokenNameFloatingPointLiteral: 180 case TerminalTokens.TokenNameLongLiteral: 181 break; 182 default: 183 throw new IllegalArgumentException ("Invalid number literal : >" + token + "<"); } 185 break; 186 default: 187 throw new IllegalArgumentException ("Invalid number literal : >" + token + "<"); } 189 } catch(InvalidInputException e) { 190 throw new IllegalArgumentException (); 191 } finally { 192 scanner.tokenizeComments = true; 193 scanner.tokenizeWhiteSpace = true; 194 } 195 preValueChange(TOKEN_PROPERTY); 196 this.tokenValue = token; 197 postValueChange(TOKEN_PROPERTY); 198 } 199 200 203 void internalSetToken(String token) { 204 preValueChange(TOKEN_PROPERTY); 205 this.tokenValue = token; 206 postValueChange(TOKEN_PROPERTY); 207 } 208 211 int memSize() { 212 int size = BASE_NODE_SIZE + 1 * 4 + stringSize(tokenValue); 213 return size; 214 } 215 216 219 int treeSize() { 220 return memSize(); 221 } 222 } 223 | Popular Tags |