org.eclipse.xtext.common.types.util.Primitives Java Examples

The following examples show how to use org.eclipse.xtext.common.types.util.Primitives. 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: AbstractXbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected String getDefaultValueLiteral(XExpression expr) {
	LightweightTypeReference type = getTypeForVariableDeclaration(expr);
	if (type.isPrimitive()) {
		if (type.getPrimitiveKind() == Primitives.Primitive.Boolean) {
			return "false";
		} else {
			return "(" + type.getSimpleName() + ") 0";
		}
	}
	return "null";
}
 
Example #2
Source File: LightweightTypeReference.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Primitives.Primitive getPrimitiveKind() {
	return null;
}
 
Example #3
Source File: LightweightTypeReference.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Primitives.Primitive getPrimitiveKindIfWrapperType() {
	return null;
}
 
Example #4
Source File: CommonTypeComputationServices.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Primitives getPrimitives() {
	return primitives;
}
 
Example #5
Source File: CommonTypeComputationServices.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public void setPrimitives(Primitives primitives) {
	this.primitives = primitives;
}
 
Example #6
Source File: XbaseInterpreter.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected Object castToPrimitiveType(Object castMe, Primitives.Primitive kind) {
	if (com.google.common.primitives.Primitives.isWrapperType(castMe.getClass())) {
		if (kind == Primitives.Primitive.Boolean) {
			if (castMe instanceof Boolean) {
				return castMe;
			}
		} else if (kind == Primitives.Primitive.Char) {
			if (castMe instanceof Character) {
				return ((Character) castMe).charValue();
			} else if (castMe instanceof Byte) {
				return (char) ((Byte) castMe).byteValue();
			} else if (castMe instanceof Short) {
				return (char) ((Short) castMe).shortValue();
			} else if (castMe instanceof Long) {
				return (char) ((Long) castMe).longValue();
			} else if (castMe instanceof Integer) {
				return (char) ((Integer) castMe).intValue();
			} else if (castMe instanceof Float) {
				return (char) ((Float) castMe).floatValue();
			} else if (castMe instanceof Double) {
				return (char) ((Double) castMe).doubleValue();
			}
		} else if (castMe instanceof Number) {
			Number number = (Number) castMe;
			switch(kind) {
				case Byte:
					return number.byteValue();
				case Short:
					return number.shortValue();
				case Long: 
					return number.longValue();
				case Int:
					return number.intValue();
				case Float:
					return number.floatValue();
				case Double:
					return number.doubleValue();
				default:
					throw new IllegalStateException("Unexpected cast type 'void'");
			}
		} else if (castMe instanceof Character) {
			char c = ((Character) castMe).charValue();
			switch(kind) {
				case Byte:
					return (byte) c;
				case Short:
					return (short) c;
				case Long: 
					return (long) c;
				case Int:
					return (int) c;
				case Float:
					return (float) c;
				case Double:
					return (double) c;
				default:
					throw new IllegalStateException("Unexpected cast type 'void'");
			}
		}
	}
	throw new EvaluationException(new ClassCastException(castMe.getClass().getName() + "!=" + kind.name().toLowerCase()));
}
 
Example #7
Source File: ArithmeticExtensionsTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected Primitives getPrimitives() {
	return primitives;
}
 
Example #8
Source File: AbstractBuilder.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Replies the primitive type tools.
 *
 * @return the primitive type tools.
 */
@Pure
protected Primitives getPrimitiveTypes() {
	return this.primitives;
}