Java Code Examples for org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationState#acceptActualType()
The following examples show how to use
org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationState#acceptActualType() .
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: ScriptTypeComputer.java From openhab-core with Eclipse Public License 2.0 | 6 votes |
protected void _computeTypes(final QuantityLiteral assignment, ITypeComputationState state) { LightweightTypeReference qt = null; for (ITypeExpectation exp : state.getExpectations()) { if (exp.getExpectedType() == null) { continue; } if (exp.getExpectedType().isType(Number.class)) { qt = getRawTypeForName(Number.class, state); } if (exp.getExpectedType().isType(State.class)) { qt = getRawTypeForName(Number.class, state); } if (exp.getExpectedType().isType(Command.class)) { qt = getRawTypeForName(Number.class, state); } } if (qt == null) { qt = getRawTypeForName(QuantityType.class, state); } state.acceptActualType(qt); }
Example 5
Source File: ScriptTypeComputer.java From smarthome with Eclipse Public License 2.0 | 6 votes |
protected void _computeTypes(final QuantityLiteral assignment, ITypeComputationState state) { LightweightTypeReference qt = null; for (ITypeExpectation exp : state.getExpectations()) { if (exp.getExpectedType() == null) { continue; } if (exp.getExpectedType().isType(Number.class)) { qt = getRawTypeForName(Number.class, state); } if (exp.getExpectedType().isType(State.class)) { qt = getRawTypeForName(Number.class, state); } if (exp.getExpectedType().isType(Command.class)) { qt = getRawTypeForName(Number.class, state); } } if (qt == null) { qt = getRawTypeForName(QuantityType.class, state); } state.acceptActualType(qt); }
Example 6
Source File: XtendTypeComputer.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
protected void _computeTypes(RichStringLiteral object, ITypeComputationState state) { LightweightTypeReference type = getRawTypeForName(CharSequence.class, state); state.acceptActualType(type); }
Example 7
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 8
Source File: SARLTypeComputer.java From sarl with Apache License 2.0 | 2 votes |
/** Compute the type of a break expression. * * @param object the expression. * @param state the state of the type resolver. */ protected void _computeTypes(SarlBreakExpression object, ITypeComputationState state) { final LightweightTypeReference primitiveVoid = getPrimitiveVoid(state); state.acceptActualType(primitiveVoid); }
Example 9
Source File: SARLTypeComputer.java From sarl with Apache License 2.0 | 2 votes |
/** Compute the type of a break expression. * * @param object the expression. * @param state the state of the type resolver. * @since 0.7 */ protected void _computeTypes(SarlContinueExpression object, ITypeComputationState state) { final LightweightTypeReference primitiveVoid = getPrimitiveVoid(state); state.acceptActualType(primitiveVoid); }