Java Code Examples for org.eclipse.xtext.xbase.XTypeLiteral#getType()

The following examples show how to use org.eclipse.xtext.xbase.XTypeLiteral#getType() . 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: XbaseTypeComputer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void _computeTypes(XTypeLiteral object, ITypeComputationState state) {
	JvmType type = object.getType();
	if (type == null) {
		return;
	}
	checkTypeParameterNotAllowedAsLiteral(object, type, state);
	ITypeReferenceOwner owner = state.getReferenceOwner();
	LightweightTypeReference clazz = owner.newParameterizedTypeReference(type);
	for (int i = 0; i < object.getArrayDimensions().size(); i++) {
		clazz = owner.newArrayTypeReference(clazz);
	}
	if (object.getArrayDimensions().isEmpty()) {
		if (clazz.isPrimitiveVoid()) {
			clazz = state.getReferenceOwner().newReferenceTo(Void.class);
		} else {
			clazz = clazz.getWrapperTypeIfPrimitive();
		}
	}
	LightweightTypeReference result = owner.newReferenceTo(Class.class);
	if (result instanceof ParameterizedTypeReference) {
		ParameterizedTypeReference parameterizedTypeReference = (ParameterizedTypeReference) result;
		parameterizedTypeReference.addTypeArgument(clazz);
	}
	state.acceptActualType(result);
}
 
Example 2
Source File: ResolvedFeaturesTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public ResolvedFeatures toResolvedOperations(final Class<?> type) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("typeof(");
    String _canonicalName = type.getCanonicalName();
    _builder.append(_canonicalName);
    _builder.append(")");
    XExpression _expression = this.expression(_builder);
    final XTypeLiteral typeLiteral = ((XTypeLiteral) _expression);
    JvmType _type = typeLiteral.getType();
    final ResolvedFeatures result = this.overrideHelper.getResolvedFeatures(((JvmDeclaredType) _type));
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 3
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkDeprecated(XTypeLiteral expression) {
	if (!isIgnored(DEPRECATED_MEMBER_REFERENCE)) {
		JvmType jvmType = expression.getType();
		checkDeprecated(
				jvmType,
				expression,
				XbasePackage.Literals.XTYPE_LITERAL__TYPE);
	}
}
 
Example 4
Source File: XbaseInterpreter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param context unused in this context but required for dispatching
 * @param indicator unused in this context but required for dispatching
 */
protected Object _doEvaluate(XTypeLiteral literal, IEvaluationContext context, CancelIndicator indicator) {
	if (literal.getType() == null || literal.getType().eIsProxy()) {
		List<INode> nodesForFeature = NodeModelUtils.findNodesForFeature(literal,
				XbasePackage.Literals.XTYPE_LITERAL__TYPE);
		// TODO cleanup
		if (nodesForFeature.isEmpty())
			throw new EvaluationException(new ClassNotFoundException());
		throw new EvaluationException(new ClassNotFoundException(nodesForFeature.get(0).getText()));
	}
	JvmType type = literal.getType();
	Object result = translateJvmTypeToResult(type, literal.getArrayDimensions().size());
	return result;
}
 
Example 5
Source File: UIStringsTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testReferenceToString_0() throws Exception {
	XExpression expr = expression("typeof(foo.String)", true);
	assertTrue(expr instanceof XTypeLiteral);
	XTypeLiteral operator = (XTypeLiteral) expr;
	JvmType type = operator.getType();
	JvmTypeReference reference = this.typeReferences.createTypeRef(type);
	assertEquals("String", this.uiStrings.referenceToString(reference, "the-default-value"));
}
 
Example 6
Source File: UIStringsTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testReferenceToString_1() throws Exception {
	XExpression expr = expression("typeof(String)", true);
	assertTrue(expr instanceof XTypeLiteral);
	XTypeLiteral operator = (XTypeLiteral) expr;
	JvmType type = operator.getType();
	JvmTypeReference reference = this.typeReferences.createTypeRef(type);
	assertEquals("String", this.uiStrings.referenceToString(reference, "the-default-value"));
}
 
Example 7
Source File: ShouldExtensions.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Ensure that the given type literal is equal to the given type.
 *
 * @param actual the type literal to test.
 * @param expected the name of the expected type.
 * @return the validation status
 */
public static boolean shouldBe(XTypeLiteral actual, Object expected) {
	if (actual == null) {
		return false;
	}
	final String fqn;
	if (expected instanceof Class) {
		fqn = ((Class<?>) expected).getName();
	} else {
		fqn = expected.toString();
	}
	return actual.getType() != null
			&& Objects.equals(fqn, actual.getType().getQualifiedName());
}