Java Code Examples for org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationState#computeTypes()
The following examples show how to use
org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationState#computeTypes() .
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: TypeComputationStateTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public void computeTypes(XExpression expression, ITypeComputationState state) { try { assertTrue("state is instanceof ExpressionTypeComputationState", (state instanceof ExpressionTypeComputationState)); LightweightTypeReference expectedType = getFirst(state.getExpectations(), null).getExpectedType(); if (expression instanceof XNullLiteral) { ExpressionTypeComputationState casted = ((ExpressionTypeComputationState) state); ResolvedTypes resolution = reflectExtensions.get(casted, "resolvedTypes"); ResolvedTypes parentResolution = reflectExtensions .get(reflectExtensions.<ExpressionTypeComputationState> get(casted, "parent"), "resolvedTypes"); assertNull(parentResolution.getActualType(((XExpression) ((XNullLiteral) expression).eContainer()))); state.acceptActualType(expectedType); assertNull(parentResolution.getActualType(expression)); assertEquals(expectedType.getIdentifier(), resolution.getActualType(expression).getIdentifier()); assertNull(parentResolution.getActualType(((XExpression) ((XNullLiteral) expression).eContainer()))); } else { assertTrue((expression instanceof XBlockExpression)); XNullLiteral nullLiteral = ((XNullLiteral) getFirst(expression.eContents(), null)); state.computeTypes(nullLiteral); ResolvedTypes res = reflectExtensions.get(state, "resolvedTypes"); assertEquals(expectedType.getIdentifier(), res.getActualType(nullLiteral).getIdentifier()); } } catch (IllegalAccessException | SecurityException | NoSuchFieldException | IllegalArgumentException e) { throw Exceptions.sneakyThrow(e); } }
Example 2
Source File: XtendTypeComputer.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void _computeTypes(RichStringForLoop object, ITypeComputationState state) { LightweightTypeReference charSequence = getRawTypeForName(CharSequence.class, state); ITypeComputationState eachState = state.withExpectation(charSequence); JvmFormalParameter parameter = object.getDeclaredParam(); if (parameter != null) { LightweightTypeReference parameterType = computeForLoopParameterType(object, state); eachState = eachState.assignType(parameter, parameterType); } eachState.computeTypes(object.getEachExpression()); state.withNonVoidExpectation().computeTypes(object.getBefore()); state.withNonVoidExpectation().computeTypes(object.getSeparator()); state.withNonVoidExpectation().computeTypes(object.getAfter()); LightweightTypeReference primitiveVoid = getPrimitiveVoid(state); state.acceptActualType(primitiveVoid); state.acceptActualType(charSequence); }
Example 3
Source File: XtendTypeComputer.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void _computeTypes(RichStringIf object, ITypeComputationState state) { LightweightTypeReference charSequence = getRawTypeForName(CharSequence.class, state); LightweightTypeReference booleanType = getRawTypeForName(Boolean.TYPE, state); ITypeComputationState conditionExpectation = state.withExpectation(booleanType); XExpression condition = object.getIf(); conditionExpectation.computeTypes(condition); XExpression thenExpression = object.getThen(); ITypeComputationState thenState = reassignCheckedType(condition, thenExpression, state); thenState.withExpectation(charSequence).computeTypes(thenExpression); for(RichStringElseIf elseIf: object.getElseIfs()) { state.withExpectation(booleanType).computeTypes(elseIf.getIf()); ITypeComputationState elseState = reassignCheckedType(elseIf.getIf(), elseIf.getThen(), state); elseState.withExpectation(charSequence).computeTypes(elseIf.getThen()); } state.withExpectation(charSequence).computeTypes(object.getElse()); state.acceptActualType(charSequence); }
Example 4
Source File: XtendTypeComputer.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void _computeTypes(AnonymousClass anonymousClass, ITypeComputationState state) { JvmGenericType type = associations.getInferredType(anonymousClass); if (type != null) { // should never be null but the associations don't promise anything LocalVariableCapturer.captureLocalVariables(type, state); } state.computeTypes(anonymousClass.getConstructorCall()); }
Example 5
Source File: SARLTypeComputer.java From sarl with Apache License 2.0 | 4 votes |
/** Compute the type of a casted expression. * * @param cast the expression. * @param state the state of the type resolver. */ @SuppressWarnings("checkstyle:nestedifdepth") protected void _computeTypes(SarlCastedExpression cast, ITypeComputationState state) { if (state instanceof AbstractTypeComputationState) { final JvmTypeReference type = cast.getType(); if (type != null) { state.withNonVoidExpectation().computeTypes(cast.getTarget()); // Set the linked feature try { final AbstractTypeComputationState computationState = (AbstractTypeComputationState) state; final CastedExpressionTypeComputationState astate = new CastedExpressionTypeComputationState( cast, computationState, this.castOperationValidator); astate.resetFeature(cast); if (astate.isCastOperatorLinkingEnabled(cast)) { final List<? extends ILinkingCandidate> candidates = astate.getLinkingCandidates(cast); if (!candidates.isEmpty()) { final ILinkingCandidate best = getBestCandidate(candidates); if (best != null) { best.applyToModel(computationState.getResolvedTypes()); } } } } catch (Throwable exception) { final Throwable cause = Throwables.getRootCause(exception); state.addDiagnostic(new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.INTERNAL_ERROR, cause.getLocalizedMessage(), cast, null, -1, null)); } state.acceptActualType(state.getReferenceOwner().toLightweightTypeReference(type)); } else { state.computeTypes(cast.getTarget()); } } else { super._computeTypes(cast, state); } }
Example 6
Source File: AbstractLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 2 votes |
/** * @param argument the expression that should be processed. * @param declaredType the declared (expected) type for the given expression. * @param argumentState the to-be-used state to compute the actual type of the argument. It is already configured with the expectation. */ protected void resolveArgumentType(XExpression argument, /* @Nullable */ LightweightTypeReference declaredType, ITypeComputationState argumentState) { argumentState.computeTypes(argument); }