org.eclipse.xtext.xbase.typesystem.computation.ITypeExpectation Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.typesystem.computation.ITypeExpectation.
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: 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 #2
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 #3
Source File: TypeLiteralLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public TypeLiteralLinkingCandidate( XAbstractFeatureCall featureCall, IIdentifiableElementDescription description, ITypeExpectation expectation, final ExpressionTypeComputationState state) { super(featureCall, description, expectation, state, new TypeLiteralLinkingCandidateResolver(featureCall) { @Override protected IFeatureLinkingCandidate getLinkingCandidate(XExpression target) { return state.getResolvedTypes().getLinkingCandidate((XAbstractFeatureCall) target); } }); if (featureCall.isExplicitOperationCallOrBuilderSyntax()) { throw new IllegalArgumentException("Cannot be a type literal: " + String.valueOf(featureCall)); } this.helper = new TypeLiteralHelper(state); }
Example #4
Source File: AbstractPendingLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected AbstractPendingLinkingCandidate( Expression expression, IIdentifiableElementDescription description, ITypeExpectation expectation, ExpressionTypeComputationState state, PendingLinkingCandidateResolver<Expression> pendingLinkingCandidateResolver) { super(expression, expectation, state); this.description = description; this.pendingLinkingCandidateResolver = pendingLinkingCandidateResolver; }
Example #5
Source File: AbstractExpectationTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public void recordExpectation(final XExpression expression, final ITypeComputationState state) { List<? extends ITypeExpectation> _expectations = state.getExpectations(); Iterables.<ITypeExpectation>addAll(this.finalExpectations, _expectations); final Function1<ITypeExpectation, String> _function = (ITypeExpectation it) -> { LightweightTypeReference _expectedType = it.getExpectedType(); String _simpleName = null; if (_expectedType!=null) { _simpleName=_expectedType.getSimpleName(); } return _simpleName; }; List<String> _map = ListExtensions.map(state.getExpectations(), _function); Iterables.<String>addAll(this.expectations, _map); this.expressions.add(expression); }
Example #6
Source File: AbstractExpectationTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public AbstractExpectationTest notVoid() { Assert.assertTrue(this.pendingAssert); this.pendingAssert = false; Assert.assertEquals(1, this.finalExpectations.size()); final ITypeExpectation expectation = IterableExtensions.<ITypeExpectation>head(this.finalExpectations); Assert.assertFalse(expectation.isNoTypeExpectation()); Assert.assertFalse(expectation.isVoidTypeAllowed()); Assert.assertNull(expectation.getExpectedType()); return this; }
Example #7
Source File: AbstractExpectationTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public AbstractExpectationTest nothing() { Assert.assertTrue(this.pendingAssert); this.pendingAssert = false; Assert.assertEquals(1, this.finalExpectations.size()); final ITypeExpectation expectation = IterableExtensions.<ITypeExpectation>head(this.finalExpectations); Assert.assertTrue(expectation.isNoTypeExpectation()); Assert.assertTrue(expectation.isVoidTypeAllowed()); Assert.assertNull(expectation.getExpectedType()); return this; }
Example #8
Source File: ResolvedFeature.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public ResolvedFeature( XAbstractFeatureCall featureCall, JvmIdentifiableElement feature, FeatureLinkHelper helper, ITypeExpectation expectation, ExpressionTypeComputationState state) { super(featureCall, feature, expectation, state); this.helper = helper; }
Example #9
Source File: ResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void refineExpectedType(XExpression receiver, ITypeExpectation refinedExpectation) { Collection<TypeData> typeData = ensureExpressionTypesMapExists().get(receiver); List<TypeData> replaced = Lists.newArrayListWithCapacity(typeData.size()); for(TypeData existing: typeData) { TypeData newTypeData = new TypeData(receiver, refinedExpectation, existing.getActualType(), existing.getConformanceFlags(), existing.isReturnType()); replaced.add(newTypeData); } ensureExpressionTypesMapExists().put(receiver, replaced); }
Example #10
Source File: ResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected int getConformanceFlags(TypeData typeData, boolean recompute) { int flags = typeData.getConformanceFlags(); if (recompute) { if ((flags & ConformanceFlags.SEALED) != 0) { ConformanceFlags.sanityCheck(flags); return flags; } flags &= ~(ConformanceFlags.INCOMPATIBLE | ConformanceFlags.SUCCESS); flags |= ConformanceFlags.UNCHECKED; } if ((flags & ConformanceFlags.UNCHECKED) != 0) { LightweightTypeReference actualType = typeData.getActualType(); ITypeExpectation expectation = typeData.getExpectation(); LightweightTypeReference expectedType = expectation.getExpectedType(); if (expectedType != null) { int conformanceResult = expectedType.getUpperBoundSubstitute().internalIsAssignableFrom( actualType, TypeConformanceComputationArgument.DEFAULT); flags |= conformanceResult | ConformanceFlags.CHECKED; flags &= ~ConformanceFlags.UNCHECKED; } else { flags &= ~ConformanceFlags.UNCHECKED; flags |= ConformanceFlags.CHECKED_SUCCESS; } } ConformanceFlags.sanityCheck(flags); typeData.setConformanceFlags(flags); return flags; }
Example #11
Source File: ResolvedConstructor.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public ResolvedConstructor( XConstructorCall constructorCall, JvmConstructor constructor, ITypeExpectation expectation, ExpressionTypeComputationState state) { super(constructorCall, constructor, expectation, state); }
Example #12
Source File: CompoundTypeComputationState.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public List<? extends ITypeExpectation> getExpectations() { List<ITypeExpectation> result = Lists.newArrayList(); for (int i = 0; i < components.length; i++) { result.addAll(components[i].getExpectations()); } return result; }
Example #13
Source File: AbstractPendingLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected AbstractPendingLinkingCandidate( Expression expression, IIdentifiableElementDescription description, ITypeExpectation expectation, ExpressionTypeComputationState state) { this(expression, description, expectation, state, new PendingLinkingCandidateResolver<Expression>(expression)); }
Example #14
Source File: FeatureLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public FeatureLinkingCandidate( XAbstractFeatureCall featureCall, IIdentifiableElementDescription description, ITypeExpectation expectation, ExpressionTypeComputationState state) { super(featureCall, description, expectation, state); }
Example #15
Source File: AbstractResolvedReference.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected AbstractResolvedReference( Expression expression, JvmIdentifiableElement resolvedElement, ITypeExpectation expectation, ExpressionTypeComputationState state) { super(expression, expectation, state); this.resolvedElement = resolvedElement; this.typeParameterMapping = initializeTypeParameterMapping(); }
Example #16
Source File: AbstractTypeComputationState.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public void acceptActualType(LightweightTypeReference type, int flags) { if ((flags & ConformanceFlags.CHECKED) == 0) flags |= ConformanceFlags.UNCHECKED; List<? extends ITypeExpectation> expectations = (flags & ConformanceFlags.EXPLICIT_VOID_RETURN) != 0 ? getReturnExpectations() : getExpectations(); for(ITypeExpectation expectation: expectations) { expectation.acceptActualType(type, flags); } }
Example #17
Source File: AbstractTypeComputationState.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected ITypeExpectation getSingleExpectation(ITypeComputationState state) { List<? extends ITypeExpectation> result = state.getExpectations(); if (result.size() != 1) { throw new IllegalStateException(); } return result.get(0); }
Example #18
Source File: ConstructorLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public ConstructorLinkingCandidate( XConstructorCall constructorCall, IIdentifiableElementDescription description, ITypeExpectation expectation, ExpressionTypeComputationState state) { super(constructorCall, description, expectation, state); }
Example #19
Source File: ConstructorLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected LightweightTypeReference deferredBindTypeArgument(ITypeExpectation expectation, LightweightTypeReference type) { LightweightTypeReference result = super.deferredBindTypeArgument(expectation, type); LightweightTypeReference expectedType = expectation.getExpectedType(); if (expectedType != null && getConstructorCall().getTypeArguments().isEmpty() && !result.isRawType() && !getDeclaredTypeParameters().isEmpty()) { if (!expectedType.isAssignableFrom(result, TypeConformanceComputationArgument.DEFAULT)) { LightweightTypeReference rawFeatureType = result.getRawTypeReference(); if (expectedType.isAssignableFrom(rawFeatureType)) { result = rawFeatureType; getTypeParameterMapping().clear(); } } } return result; }
Example #20
Source File: TypeData.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public TypeData( XExpression expression, ITypeExpectation expectation, LightweightTypeReference type, int flags, boolean returnType) { ConformanceFlags.sanityCheck(flags); this.expression = expression; this.expectation = expectation; this.type = type; this.flags = flags; this.returnType = returnType; }
Example #21
Source File: StackedResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected void refineExpectedType(XExpression receiver, ITypeExpectation refinedExpectation) { Collection<TypeData> typeData = basicGetExpressionTypes().get(receiver); if (typeData == null) { getParent().refineExpectedType(receiver, refinedExpectation); } else { super.refineExpectedType(receiver, refinedExpectation); } }
Example #22
Source File: ResolvedTypeLiteral.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected ResolvedTypeLiteral( XAbstractFeatureCall featureCall, JvmIdentifiableElement resolvedElement, ITypeExpectation expectation, ExpressionTypeComputationState state) { super(featureCall, resolvedElement, expectation, state); this.helper = new TypeLiteralHelper(state); }
Example #23
Source File: RootTypeExpectation.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override public ITypeExpectation copyInto(ITypeReferenceOwner referenceOwner) { return new RootTypeExpectation(reference.copyInto(referenceOwner), getState()); }
Example #24
Source File: TypeData.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
public ITypeExpectation getExpectation() { return expectation; }
Example #25
Source File: ResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
private void enhanceMergeData(List<TypeData> values, MergeData mergeData) { for (int i = 0, size = values.size(); i < size; i++) { TypeData value = values.get(i); LightweightTypeReference reference = value.getActualType().getUpperBoundSubstitute(); int flags = value.getConformanceFlags(); if (reference.isPrimitiveVoid()) { if ((flags & ConformanceFlags.EXPLICIT_VOID_RETURN) != 0) { mergeData.references.clear(); mergeData.references.add(reference); mergeData.mergedFlags = flags; mergeData.expectation = value.getExpectation(); mergeData.voidSeen = false; return; } mergeData.voidSeen = true; } else { mergeData.references.add(reference); } mergeData.allNoImplicitReturn = mergeData.allNoImplicitReturn && (flags & ConformanceFlags.NO_IMPLICIT_RETURN) != 0; mergeData.allThrownException = mergeData.allThrownException && (flags & ConformanceFlags.THROWN_EXCEPTION) != 0; if (!reference.isUnknown()) { mergeData.mergedFlags |= flags; } if (mergeData.expectation == null) { mergeData.expectation = value.getExpectation(); } else if (mergeData.expectation.getExpectedType() == null) { ITypeExpectation knownExpectation = value.getExpectation(); if (knownExpectation.getExpectedType() != null) { mergeData.expectation = knownExpectation; } } } if (mergeData.mergedFlags == ConformanceFlags.MERGED) { mergeData.mergedFlags |= ConformanceFlags.CHECKED_SUCCESS; } if (!mergeData.allNoImplicitReturn) { mergeData.mergedFlags &= ~ConformanceFlags.NO_IMPLICIT_RETURN; } if (!mergeData.allThrownException) { mergeData.mergedFlags &= ~ConformanceFlags.THROWN_EXCEPTION; } if ((mergeData.mergedFlags & (ConformanceFlags.CHECKED | ConformanceFlags.UNCHECKED)) == (ConformanceFlags.CHECKED | ConformanceFlags.UNCHECKED)) { mergeData.mergedFlags &= ~(ConformanceFlags.CHECKED | ConformanceFlags.CHECK_RESULTS); } if ((mergeData.mergedFlags & ConformanceFlags.UNCHECKED) != 0) { mergeData.mergedFlags &= ~ConformanceFlags.SEALED; } }
Example #26
Source File: NoExpectation.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override public ITypeExpectation copyInto(ITypeReferenceOwner referenceOwner) { return this; }
Example #27
Source File: AbstractExpectationTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
public void clearData() { this.resolvedTypes = null; this.expectations = CollectionLiterals.<String>newArrayList(); this.finalExpectations = CollectionLiterals.<ITypeExpectation>newArrayList(); this.expressions = CollectionLiterals.<XExpression>newArrayList(); }
Example #28
Source File: ForwardingTypeComputationState.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override public List<? extends ITypeExpectation> getExpectations() { return delegate.getExpectations(); }
Example #29
Source File: AbstractLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected AbstractLinkingCandidate(Expression expression, ITypeExpectation expectation, ExpressionTypeComputationState state) { this.expression = expression; this.expectation = expectation; this.state = state; }
Example #30
Source File: AbstractTypeComputationState.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override public void acceptActualType(LightweightTypeReference type) { for(ITypeExpectation expectation: getExpectations()) { expectation.acceptActualType(type, ConformanceFlags.UNCHECKED); } }