Java Code Examples for org.eclipse.jdt.core.compiler.CharOperation#remove()

The following examples show how to use org.eclipse.jdt.core.compiler.CharOperation#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FloatLiteral.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void computeConstant() {
	Float computedValue;
	boolean containsUnderscores = CharOperation.indexOf('_', this.source) > 0;
	if (containsUnderscores) {
		// remove all underscores from source
		this.source = CharOperation.remove(this.source, '_');
	}
	try {
		computedValue = Float.valueOf(String.valueOf(this.source));
	} catch (NumberFormatException e) {
		// hex floating point literal
		// being rejected by 1.4 libraries where Float.valueOf(...) doesn't handle hex decimal floats
		try {
			float v = FloatUtil.valueOfHexFloatLiteral(this.source);
			if (v == Float.POSITIVE_INFINITY) {
				// error: the number is too large to represent
				return;
			}
			if (Float.isNaN(v)) {
				// error: the number is too small to represent
				return;
			}
			this.value = v;
			this.constant = FloatConstant.fromValue(v);
		} catch (NumberFormatException e1) {
			// if the computation of the constant fails
		}
		return;
	}
	final float floatValue = computedValue.floatValue();
	if (floatValue > Float.MAX_VALUE) {
		// error: the number is too large to represent
		return;
	}
	if (floatValue < Float.MIN_VALUE) {
		// see 1F6IGUU
		// a true 0 only has '0' and '.' in mantissa
		// 1.0e-5000d is non-zero, but underflows to 0
		boolean isHexaDecimal = false;
		label : for (int i = 0; i < this.source.length; i++) { //it is welled formated so just test against '0' and potential . D d
			switch (this.source[i]) {
				case '0' :
				case '.' :
					break;
				case 'x' :
				case 'X' :
					isHexaDecimal = true;
					break;
				case 'e' :
				case 'E' :
				case 'f' :
				case 'F' :
				case 'd' :
				case 'D' :
					if (isHexaDecimal) {
						return;
					}
					// starting the exponent - mantissa is all zero
					// no exponent - mantissa is all zero
					break label;
				case 'p' :
				case 'P' :
					break label;
				default :
					// error: the number is too small to represent
					return;
			}
		}
	}
	this.value = floatValue;
	this.constant = FloatConstant.fromValue(this.value);
}
 
Example 2
Source File: DoubleLiteral.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void computeConstant() {
	Double computedValue;
	boolean containsUnderscores = CharOperation.indexOf('_', this.source) > 0;
	if (containsUnderscores) {
		// remove all underscores from source
		this.source = CharOperation.remove(this.source, '_');
	}
	try {
		computedValue = Double.valueOf(String.valueOf(this.source));
	} catch (NumberFormatException e) {
		// hex floating point literal
		// being rejected by 1.4 libraries where Double.valueOf(...) doesn't handle hex decimal floats
		try {
			double v = FloatUtil.valueOfHexDoubleLiteral(this.source);
			if (v == Double.POSITIVE_INFINITY) {
				// error: the number is too large to represent
				return;
			}
			if (Double.isNaN(v)) {
				// error: the number is too small to represent
				return;
			}
			this.value = v;
			this.constant = DoubleConstant.fromValue(v);
		} catch (NumberFormatException e1) {
			// if the computation of the constant fails
		}
		return;
	}
	final double doubleValue = computedValue.doubleValue();
	if (doubleValue > Double.MAX_VALUE) {
		// error: the number is too large to represent
		return;
	}
	if (doubleValue < Double.MIN_VALUE) {
		// see 1F6IGUU
		// a true 0 only has '0' and '.' in mantissa
		// 1.0e-5000d is non-zero, but underflows to 0
		boolean isHexaDecimal = false;
		label : for (int i = 0; i < this.source.length; i++) { //it is welled formated so just test against '0' and potential . D d
			switch (this.source[i]) {
				case '0' :
				case '.' :
					break;
				case 'x' :
				case 'X' :
					isHexaDecimal = true;
					break;
				case 'e' :
				case 'E' :
				case 'f' :
				case 'F' :
				case 'd' :
				case 'D' :
					if (isHexaDecimal) {
						return;
					}
					// starting the exponent - mantissa is all zero
					// no exponent - mantissa is all zero
					break label;
				case 'p' :
				case 'P' :
					break label;
				default :
					// error: the number is too small to represent
					return;
			}
		}
	}
	this.value = doubleValue;
	this.constant = DoubleConstant.fromValue(this.value);
}
 
Example 3
Source File: Signature.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Removes any capture information from the given type or method signature
 * and returns the resulting signature.
 * Returns the type or method signature itself if no capture information is
 * present.
 * <p>
 * For example (using equivalent string-based method):
 * <pre>
 * <code>
 * removeCapture("LTest&lt;!+Ljava.lang.Throwable;&gt;;")
 * will return: "LTest&lt;+Ljava.lang.Throwable;&gt;;"
 * </code>
 * </pre>
 * </p>
 *
 * @param methodOrTypeSignature the signature which may have been captured
 * @return a new signature without capture information or the signature itself
 * 	if no specific capture information is present
 * @exception NullPointerException if <code>methodOrTypeSignature</code> is null
 *
 * @since 3.1
 */
public static char[] removeCapture(char[] methodOrTypeSignature) {
	return CharOperation.remove(methodOrTypeSignature, C_CAPTURE);
}