Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fab2d842b027805a0fd4b53f21847558c433a69e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*******************************************************************************
 * Copyright (c) 2000, 2011 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;

public abstract class NumberLiteral extends Literal {

	char[] source;

	public NumberLiteral(char[] token, int s, int e) {
		this(s,e) ;
		this.source = token ;
	}

	public NumberLiteral(int s, int e) {
		super (s,e) ;
	}

	@Override
	public boolean isValidJavaStatement(){
		return false ;
	}

	@Override
	public char[] source(){
		return this.source;
	}
	protected static char[] removePrefixZerosAndUnderscores(char[] token, boolean isLong) {
		int max = token.length;
		int start = 0;
		int end = max - 1;
		if (isLong) {
			end--; // remove the 'L' or 'l'
		}
		if (max > 1 && token[0] == '0') {
			if (max > 2 && (token[1] == 'x' || token[1] == 'X')) {
				start = 2;
			} else if (max > 2 && (token[1] == 'b' || token[1] == 'B')) {
				start = 2;
			} else {
				start = 1;
			}
		}
		boolean modified = false;
		boolean ignore = true;
		loop: for (int i = start; i < max; i++) {
			char currentChar = token[i];
			switch(currentChar) {
				case '0' :
					// this is a prefix '0'
					if (ignore && !modified && (i < end)) {
						modified = true;
					}
					break;
				case '_' :
					modified = true;
					break loop;
				default :
					ignore = false;
			}
		}
		if (!modified) {
			return token;
		}
		ignore = true;
		StringBuffer buffer = new StringBuffer();
		buffer.append(token, 0, start);
		loop: for (int i = start; i < max; i++) {
			char currentChar = token[i];
			switch(currentChar) {
				case '0' :
					if (ignore && (i < end)) {
						// this is a prefix '0'
						continue loop;
					}
					break;
				case '_' :
					continue loop;
				default:
					ignore = false;
			}
			buffer.append(currentChar);
		}
		return buffer.toString().toCharArray();
	}
}

Back to the top