Java Code Examples for org.eclipse.xtext.xbase.typesystem.IResolvedTypes#getExpectedReturnType()
The following examples show how to use
org.eclipse.xtext.xbase.typesystem.IResolvedTypes#getExpectedReturnType() .
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 | 6 votes |
protected LightweightTypeReference getTypeForVariableDeclaration(XExpression expr) { IResolvedTypes resolvedTypes = getResolvedTypes(expr); LightweightTypeReference actualType = resolvedTypes.getActualType(expr); if (actualType.isPrimitiveVoid()) { LightweightTypeReference expectedType = resolvedTypes.getExpectedType(expr); if (expectedType == null) { expectedType = resolvedTypes.getExpectedReturnType(expr); if (expectedType == null) { expectedType = resolvedTypes.getReturnType(expr); } } if (expectedType != null && !expectedType.isPrimitiveVoid()) { actualType = expectedType; } } return actualType; }
Example 2
Source File: SARLCodeMiningProvider.java From sarl with Apache License 2.0 | 6 votes |
/** Replies the type for a variable declaration that is initialized with the given expression. * * @param expr the expression. * @return the variable type. */ protected LightweightTypeReference getTypeForVariableDeclaration(XExpression expr) { final IResolvedTypes resolvedTypes = getResolvedTypes(expr); LightweightTypeReference actualType = resolvedTypes.getActualType(expr); if (actualType.isPrimitiveVoid()) { LightweightTypeReference expectedType = resolvedTypes.getExpectedType(expr); if (expectedType == null) { expectedType = resolvedTypes.getExpectedReturnType(expr); if (expectedType == null) { expectedType = resolvedTypes.getReturnType(expr); } } if (expectedType != null && !expectedType.isPrimitiveVoid()) { actualType = expectedType; } } return actualType; }
Example 3
Source File: XbaseValidator.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Check public void checkReturn(XReturnExpression expr) { XExpression returnedExpression = expr.getExpression(); IResolvedTypes resolvedTypes = typeResolver.resolveTypes(expr); LightweightTypeReference expectedReturnType = resolvedTypes.getExpectedReturnType(expr); if (expectedReturnType == null) { return; } if (expectedReturnType.isPrimitiveVoid()) { if (returnedExpression != null) error("Void functions cannot return a value.", expr, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_RETURN); } else { if (returnedExpression == null) error("The function must return a result of type " + expectedReturnType.getHumanReadableName() + ".", expr, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_RETURN); else { LightweightTypeReference expressionType = getActualType(returnedExpression); if (expressionType.isPrimitiveVoid()) { error("Incompatible types. Expected " + getNameOfTypes(expectedReturnType) + " but was " + canonicalName(expressionType), returnedExpression, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INCOMPATIBLE_TYPES); } } } }
Example 4
Source File: CompoundReentrantTypeResolver.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override public LightweightTypeReference getExpectedReturnType(XExpression expression) { IResolvedTypes delegate = getDelegate(expression); return delegate.getExpectedReturnType(expression); }