Java Code Examples for org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument#getSource()
The following examples show how to use
org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument#getSource() .
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: RawTypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
private boolean isConstrainedRecursiveHintCheck(List<LightweightBoundTypeArgument> leftHints, LightweightTypeReference right) { boolean hasConstraints = false; for(LightweightBoundTypeArgument leftHint: leftHints) { if (leftHint.getSource() == BoundTypeArgumentSource.CONSTRAINT) { hasConstraints = true; } if (leftHint.getSource() == BoundTypeArgumentSource.INFERRED_LATER && leftHint.getActualVariance() == VarianceInfo.INVARIANT) { if (!hasConstraints) { return false; } LightweightTypeReference leftHintReference = leftHint.getTypeReference(); if (leftHintReference.getUniqueIdentifier().equals(right.getUniqueIdentifier())) { return true; } } } return false; }
Example 2
Source File: ResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public void reassignType(JvmIdentifiableElement identifiable, /* @Nullable */ LightweightTypeReference reference) { if (reference != null) { LightweightTypeReference actualType = getActualType(identifiable); if (actualType != null) { if (actualType.getKind() == LightweightTypeReference.KIND_UNBOUND_TYPE_REFERENCE && !((UnboundTypeReference) actualType).internalIsResolved()) { UnboundTypeReference casted = (UnboundTypeReference) actualType; List<LightweightBoundTypeArgument> hints = getHints(casted.getHandle()); boolean canAddHint = true; for(int i = 0; i < hints.size() && canAddHint; i++) { LightweightBoundTypeArgument hint = hints.get(i); if (hint.getTypeReference() == null || (hint.getSource() != BoundTypeArgumentSource.EXPECTATION && hint.getSource() != BoundTypeArgumentSource.INFERRED_CONSTRAINT)) { canAddHint = false; } } if (canAddHint) { casted.acceptHint(reference, BoundTypeArgumentSource.EXPECTATION, identifiable, VarianceInfo.OUT, VarianceInfo.OUT); } ensureReassignedTypesMapExists().put(identifiable, reference); } else if (!reference.isAssignableFrom(actualType)) { if (actualType.isAssignableFrom(reference)) { ensureReassignedTypesMapExists().put(identifiable, reference); } else { CompoundTypeReference multiType = toMultiType(actualType, reference); ensureReassignedTypesMapExists().put(identifiable, multiType); } } } else { ensureReassignedTypesMapExists().put(identifiable, reference); } } else { if (reassignedTypes != null) reassignedTypes.remove(identifiable); } }
Example 3
Source File: ResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void addNonRecursiveHints(LightweightBoundTypeArgument original, List<LightweightBoundTypeArgument> hints, Set<Object> seenHandles, List<LightweightBoundTypeArgument> result) { for(LightweightBoundTypeArgument hint: hints) { LightweightTypeReference reference = hint.getTypeReference(); if (reference instanceof UnboundTypeReference) { addNonRecursiveHints(original, (UnboundTypeReference)reference, seenHandles, result); } else { if (original.getDeclaredVariance() == VarianceInfo.IN && hint.getTypeReference() instanceof WildcardTypeReference) { LightweightTypeReference upperBound = hint.getTypeReference().getUpperBoundSubstitute(); if (upperBound instanceof UnboundTypeReference) { addNonRecursiveHints(original, (UnboundTypeReference)upperBound, seenHandles, result); } else { LightweightBoundTypeArgument delegateHint = new LightweightBoundTypeArgument( upperBound, original.getSource(), hint.getOrigin(), hint.getDeclaredVariance(), original.getActualVariance()); result.add(delegateHint); } } else { if (!result.isEmpty()) { if (original.getDeclaredVariance() == VarianceInfo.OUT && original.getActualVariance() == VarianceInfo.INVARIANT) { if (hint.getDeclaredVariance() == VarianceInfo.OUT && hint.getActualVariance() == VarianceInfo.INVARIANT) { continue; } } if (!result.contains(hint)) result.add(hint); } else { result.add(hint); } } } } }
Example 4
Source File: TypeArgumentFromComputedTypeCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public static void resolveAgainstActualType(final LightweightTypeReference declaredType, LightweightTypeReference actualType, Collection<JvmTypeParameter> typeParameters, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> typeParameterMapping, BoundTypeArgumentSource source, ITypeReferenceOwner owner) { if (declaredType.isRawType() || actualType.isRawType()) return; TypeArgumentFromComputedTypeCollector implementation = new TypeArgumentFromComputedTypeCollector(typeParameters, source, owner); implementation.populateTypeParameterMapping(declaredType, actualType); Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> parameterMapping = implementation.rawGetTypeParameterMapping(); for(Map.Entry<JvmTypeParameter, List<LightweightBoundTypeArgument>> entry: parameterMapping.entrySet()) { LightweightMergedBoundTypeArgument boundTypeArgument = typeParameterMapping.get(entry.getKey()); if (boundTypeArgument != null ) { List<LightweightBoundTypeArgument> computedBoundTypeArguments = entry.getValue(); for(LightweightBoundTypeArgument computedBoundTypeArgument: computedBoundTypeArguments) { if (computedBoundTypeArgument.getSource() == BoundTypeArgumentSource.RESOLVED) { VarianceInfo varianceInfo = computedBoundTypeArgument.getDeclaredVariance().mergeDeclaredWithActual(computedBoundTypeArgument.getActualVariance()); typeParameterMapping.put(entry.getKey(), new LightweightMergedBoundTypeArgument(computedBoundTypeArgument.getTypeReference(), varianceInfo)); } else if (boundTypeArgument.getTypeReference() instanceof UnboundTypeReference) { UnboundTypeReference typeReference = (UnboundTypeReference) boundTypeArgument.getTypeReference(); if (!typeReference.internalIsResolved()) { if (!(computedBoundTypeArgument.getTypeReference() instanceof UnboundTypeReference) || ((UnboundTypeReference) computedBoundTypeArgument.getTypeReference()).getHandle() != typeReference.getHandle()) typeReference.acceptHint(computedBoundTypeArgument); } } } } } }
Example 5
Source File: RawTypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected int isConformantToConstraints( final UnboundTypeReference left, final LightweightTypeReference right, List<LightweightBoundTypeArgument> leftHints, int flags) { int result = flags; for(LightweightBoundTypeArgument leftHint: leftHints) { if (leftHint.getSource() == BoundTypeArgumentSource.CONSTRAINT) { final LightweightTypeReference leftHintReference = leftHint.getTypeReference(); if (!leftHintReference.getUniqueIdentifier().equals(right.getUniqueIdentifier())) { final LightweightMergedBoundTypeArgument rightTypeArgument = new LightweightMergedBoundTypeArgument(right.getWrapperTypeIfPrimitive(), VarianceInfo.INVARIANT); final UnboundTypeParameterPreservingSubstitutor unboundSubstitutor = new UnboundTypeParameterPreservingSubstitutor( Collections.singletonMap(left.getTypeParameter(), rightTypeArgument), right.getOwner()) { @Override public LightweightTypeReference doVisitUnboundTypeReference(UnboundTypeReference reference, Set<JvmTypeParameter> visiting) { if (reference.getHandle() == left.getHandle()) { if (right.getKind() == KIND_UNBOUND_TYPE_REFERENCE) { UnboundTypeReference rightUnbound = (UnboundTypeReference) right; List<LightweightBoundTypeArgument> rightHints = rightUnbound.getAllHints(); for(LightweightBoundTypeArgument rightHint: rightHints) { LightweightTypeReference rightHintReference = rightHint.getTypeReference(); if (rightHintReference != null && leftHintReference.getUniqueIdentifier().equals(rightHintReference.getUniqueIdentifier())) { return super.doVisitUnboundTypeReference(reference, visiting); } } } return rightTypeArgument.getTypeReference(); } return super.doVisitUnboundTypeReference(reference, visiting); } }; LightweightTypeReference constraintReference = unboundSubstitutor.substitute(leftHintReference); int constraintResult = doIsConformant(constraintReference, right, flags); if ((constraintResult & SUCCESS) == 0) { return flags; } result |= constraintResult; } } } return result | SUCCESS; }
Example 6
Source File: StackedResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected void mergeTypeParametersIntoParent(ResolvedTypes parent) { for(UnboundTypeReference unbound: basicGetTypeParameters().values()) { LightweightTypeReference resolvedTo = unbound.getResolvedTo(); if (resolvedTo == null) { List<JvmTypeParameter> typeParameters = basicGetDeclardTypeParameters(); if (typeParameters != null && typeParameters.contains(unbound.getTypeParameter())) { unbound.tryResolve(); if (!unbound.internalIsResolved()) { if (unbound.getExpression() instanceof XConstructorCall) { unbound.resolve(); // resolve against constraints } else { unbound.acceptHint(unbound.getOwner().newParameterizedTypeReference(unbound.getTypeParameter()), BoundTypeArgumentSource.RESOLVED, unbound, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT); } } } else { LightweightTypeReference reference = unbound.copyInto(parent.getReferenceOwner()); if (reference instanceof UnboundTypeReference) { parent.acceptUnboundTypeReference(unbound.getHandle(), (UnboundTypeReference) reference); } } } } Map<Object, List<LightweightBoundTypeArgument>> typeParameterHints = basicGetTypeParameterHints(); for(Map.Entry<Object, List<LightweightBoundTypeArgument>> hint: typeParameterHints.entrySet()) { if (!parent.isResolved(hint.getKey())) { List<LightweightBoundTypeArgument> boundTypeArguments = hint.getValue(); for(LightweightBoundTypeArgument boundTypeArgument: boundTypeArguments) { if (boundTypeArgument.getOrigin() instanceof VarianceInfo) { parent.acceptHint(hint.getKey(), boundTypeArgument); } else { LightweightBoundTypeArgument copy = new LightweightBoundTypeArgument( boundTypeArgument.getTypeReference().copyInto(parent.getReferenceOwner()), boundTypeArgument.getSource(), boundTypeArgument.getOrigin(), boundTypeArgument.getDeclaredVariance(), boundTypeArgument.getActualVariance()); parent.acceptHint(hint.getKey(), copy); } } } } }
Example 7
Source File: ResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
public void acceptHint(Object handle, LightweightBoundTypeArgument boundTypeArgument) { if (boundTypeArgument.getSource() == BoundTypeArgumentSource.RESOLVED) { if (resolvedTypeParameters == null) { resolvedTypeParameters = new SharedKeysAwareSet<Object>(shared.allResolvedTypeParameters); } if (resolvedTypeParameters.add(handle)) { if (boundTypeArgument.getDeclaredVariance().mergeDeclaredWithActual(boundTypeArgument.getActualVariance()) == VarianceInfo.INVARIANT) { resolveDependentTypeArguments(handle, boundTypeArgument); } LightweightBoundTypeArgument boundWithoutRecursion = removeRecursiveTypeArguments(handle, boundTypeArgument); ensureTypeParameterHintsMapExists().put(handle, Collections.singletonList(boundWithoutRecursion)); } } else { if (!isResolved(handle)) { if (boundTypeArgument.getTypeReference() instanceof UnboundTypeReference && boundTypeArgument.getSource() != BoundTypeArgumentSource.CONSTRAINT) { UnboundTypeReference other = (UnboundTypeReference) boundTypeArgument.getTypeReference(); Object otherHandle = other.getHandle(); if (ensureTypeParameterHintsMapExists().containsKey(handle)) { // don't add fully redundant hints List<LightweightBoundTypeArgument> existingValues = ensureTypeParameterHintsMapExists().get(handle); for(LightweightBoundTypeArgument existingValue: existingValues) { if (existingValue.getTypeReference() instanceof UnboundTypeReference) { if (((UnboundTypeReference) existingValue.getTypeReference()).getHandle() == otherHandle) { if (existingValue.getActualVariance() == boundTypeArgument.getActualVariance() && existingValue.getDeclaredVariance() == boundTypeArgument.getDeclaredVariance() && existingValue.getSource() == boundTypeArgument.getSource()) { return; } } } } } UnboundTypeReference currentUnbound = getUnboundTypeReference(handle); Maps2.putIntoListMap(otherHandle, copyBoundTypeArgument(currentUnbound, boundTypeArgument), ensureTypeParameterHintsMapExists()); } Maps2.putIntoListMap(handle, boundTypeArgument, ensureTypeParameterHintsMapExists()); } else { throw new IllegalStateException("Cannot add hints if the reference was already resolved"); } } }
Example 8
Source File: ResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected LightweightBoundTypeArgument copyBoundTypeArgument(LightweightTypeReference typeReference, LightweightBoundTypeArgument boundTypeArgument) { return new LightweightBoundTypeArgument(typeReference, boundTypeArgument.getSource(), boundTypeArgument.getOrigin(), boundTypeArgument.getDeclaredVariance(), boundTypeArgument.getActualVariance()); }
Example 9
Source File: ExpectationTypeParameterHintCollector.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override public void doVisitUnboundTypeReference(UnboundTypeReference reference, ParameterizedTypeReference declaration) { boolean constraintSeen = false; boolean constraintsMatch = true; boolean othersSeen = false; boolean declarationMatches = getExpectedVariance() != VarianceInfo.OUT; if (reference.getTypeParameter() != declaration.getType()) { List<LightweightBoundTypeArgument> hints = reference.getAllHints(); for(int i = 0; i < hints.size(); i++) { LightweightBoundTypeArgument hint = hints.get(i); if (hint.getSource() == BoundTypeArgumentSource.CONSTRAINT) { constraintSeen = true; outerVisit(hint.getTypeReference(), declaration, hint.getSource(), hint.getDeclaredVariance(), hint.getActualVariance()); if (constraintsMatch && !hint.getTypeReference().isAssignableFrom(declaration)) { constraintsMatch = false; } } else { othersSeen = true; // we don't break the list traversal here since we want to do the paired outerVisit for all constraints if (declarationMatches) { if (hint.getActualVariance() == VarianceInfo.OUT && hint.getDeclaredVariance() == VarianceInfo.OUT && (hint.getSource() == BoundTypeArgumentSource.INFERRED || hint.getSource() == BoundTypeArgumentSource.INFERRED_EXPECTATION || hint.getSource() == BoundTypeArgumentSource.INFERRED_LATER)) { if (!declaration.isAssignableFrom(hint.getTypeReference())) { declarationMatches = false; } } else { declarationMatches = false; } } } } } else { if (getOwner().getDeclaredTypeParameters().contains(reference.getTypeParameter())) { reference.acceptHint(declaration, BoundTypeArgumentSource.RESOLVED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT); return; } } if (constraintSeen && constraintsMatch && !othersSeen) { reference.acceptHint(declaration, BoundTypeArgumentSource.RESOLVED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT); } else if (!constraintSeen && !reference.internalIsResolved() && declaration.isResolved() && !getOwner().isResolved(reference.getHandle()) && reference.canResolveTo(declaration)) { reference.acceptHint(declaration, BoundTypeArgumentSource.RESOLVED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT); } else if (othersSeen && declarationMatches) { reference.acceptHint(declaration, BoundTypeArgumentSource.INFERRED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT); } else { reference.tryResolve(); if (reference.internalIsResolved()) { outerVisit(reference, declaration); } else { addHint(reference, declaration); } } }
Example 10
Source File: ExpectationTypeParameterHintCollector.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override public void doVisitUnboundTypeReference(UnboundTypeReference reference, ArrayTypeReference declaration) { boolean constraintSeen = false; boolean constraintsMatch = true; boolean othersSeen = false; boolean declarationMatches = getExpectedVariance() != VarianceInfo.OUT; List<LightweightBoundTypeArgument> hints = reference.getAllHints(); for(int i = 0; i < hints.size(); i++) { LightweightBoundTypeArgument hint = hints.get(i); if (hint.getSource() == BoundTypeArgumentSource.CONSTRAINT) { constraintSeen = true; outerVisit(hint.getTypeReference(), declaration, hint.getSource(), hint.getDeclaredVariance(), hint.getActualVariance()); if (constraintsMatch && !hint.getTypeReference().isAssignableFrom(declaration)) { constraintsMatch = false; } } else { othersSeen = true; // we don't break the list traversal here since we want to do the paired outerVisit for all constraints if (declarationMatches) { if (hint.getActualVariance() == VarianceInfo.OUT && hint.getDeclaredVariance() == VarianceInfo.OUT && (hint.getSource() == BoundTypeArgumentSource.INFERRED || hint.getSource() == BoundTypeArgumentSource.INFERRED_LATER || hint.getSource() == BoundTypeArgumentSource.INFERRED_EXPECTATION)) { if (!declaration.isAssignableFrom(hint.getTypeReference())) { declarationMatches = false; } } else { declarationMatches = false; } } } } if (constraintSeen && constraintsMatch && !othersSeen) { reference.acceptHint(declaration, BoundTypeArgumentSource.RESOLVED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT); } else if (!constraintSeen && !reference.internalIsResolved() && declaration.isResolved() && !getOwner().isResolved(reference.getHandle()) && reference.canResolveTo(declaration)) { reference.acceptHint(declaration, BoundTypeArgumentSource.RESOLVED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT); } else if (othersSeen && declarationMatches) { reference.acceptHint(declaration, BoundTypeArgumentSource.INFERRED, this, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT); } else { reference.tryResolve(); if (reference.internalIsResolved()) { outerVisit(reference, declaration); } else { addHint(reference, declaration); } } }