Java Code Examples for org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument#getTypeReference()
The following examples show how to use
org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument#getTypeReference() .
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: CollectionLiteralsTypeComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected boolean isExpectedType(LightweightTypeReference expectation, Class<?> clazz) { if (expectation != null) { if (expectation.isResolved() && isSubtypeButNotSynonym(expectation, clazz)) { return true; } if (expectation instanceof UnboundTypeReference) { if (expectation.getOwner().newParameterizedTypeReference(((UnboundTypeReference) expectation).getTypeParameter()).isSubtypeOf(clazz)) { return true; } List<LightweightBoundTypeArgument> hints = ((UnboundTypeReference) expectation).getAllHints(); for(LightweightBoundTypeArgument hint: hints) { LightweightTypeReference hintReference = hint.getTypeReference(); if (hintReference != null && isSubtypeButNotSynonym(hintReference, clazz)) { return true; } } } else if (expectation instanceof ParameterizedTypeReference) { return isSubtypeButNotSynonym(expectation, clazz); } } return false; }
Example 3
Source File: ResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public List<LightweightBoundTypeArgument> getAllHints(Object handle) { List<LightweightBoundTypeArgument> actualHints = getHints(handle); int i = 0; while(i < actualHints.size()) { LightweightBoundTypeArgument hint = actualHints.get(i); if (hint.getTypeReference() instanceof UnboundTypeReference) { break; } i++; } if (i >= actualHints.size()) return actualHints; List<LightweightBoundTypeArgument> transitivity = Lists.newArrayList(); Set<Object> seenHandles = Sets.newHashSet(handle); transitivity.addAll(actualHints.subList(0, i)); List<LightweightBoundTypeArgument> allRemaining = actualHints.subList(i, actualHints.size()); addNonRecursiveHints(allRemaining, seenHandles, transitivity); return transitivity; }
Example 4
Source File: ValidatingExpressionAwareResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public List<LightweightBoundTypeArgument> getAllHints(Object handle) { List<LightweightBoundTypeArgument> result = super.getAllHints(handle); for (LightweightBoundTypeArgument it : result) { if (it.getTypeReference() != null && !it.getTypeReference().isOwnedBy(getReferenceOwner())) { throw new IllegalArgumentException("hint is not owned by this resolved types"); } } return result; }
Example 5
Source File: ValidatingExpressionAwareResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public void acceptHint(Object handle, LightweightBoundTypeArgument boundTypeArgument) { if (boundTypeArgument.getTypeReference() != null && !boundTypeArgument.getTypeReference().isOwnedBy(getReferenceOwner())) { throw new IllegalArgumentException("reference is not owned by this resolved types"); } super.acceptHint(handle, boundTypeArgument); }
Example 6
Source File: ValidatingRootResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public List<LightweightBoundTypeArgument> getAllHints(Object handle) { List<LightweightBoundTypeArgument> result = super.getAllHints(handle); for (LightweightBoundTypeArgument it : result) { if (it.getTypeReference() != null && !it.getTypeReference().isOwnedBy(getReferenceOwner())) { throw new IllegalArgumentException("hint is not owned by this resolved types"); } } return result; }
Example 7
Source File: ValidatingRootResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected List<LightweightBoundTypeArgument> getHints(Object handle) { List<LightweightBoundTypeArgument> result = super.getHints(handle); for (LightweightBoundTypeArgument it : result) { if (it.getTypeReference() != null && !it.getTypeReference().isOwnedBy(getReferenceOwner())) { throw new IllegalArgumentException("reference is not owned by this resolved types"); } } return result; }
Example 8
Source File: ValidatingRootResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public void acceptHint(Object handle, LightweightBoundTypeArgument boundTypeArgument) { if (boundTypeArgument.getTypeReference() != null && !boundTypeArgument.getTypeReference().isOwnedBy(getReferenceOwner())) { throw new IllegalArgumentException("reference is not owned by this resolved types"); } super.acceptHint(handle, boundTypeArgument); }
Example 9
Source File: ValidatingStackedResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public List<LightweightBoundTypeArgument> getAllHints(Object handle) { List<LightweightBoundTypeArgument> result = super.getAllHints(handle); for (LightweightBoundTypeArgument it : result) { if (it.getTypeReference() != null && !it.getTypeReference().isOwnedBy(getReferenceOwner())) { throw new IllegalArgumentException("hint is not owned by this resolved types"); } } return result; }
Example 10
Source File: ValidatingReassigningResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected List<LightweightBoundTypeArgument> getHints(Object handle) { List<LightweightBoundTypeArgument> result = super.getHints(handle); for (LightweightBoundTypeArgument it : result) { if (it.getTypeReference() != null && !it.getTypeReference().isOwnedBy(getReferenceOwner())) { throw new IllegalArgumentException("reference is not owned by this resolved types"); } } return result; }
Example 11
Source File: ValidatingReassigningResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public void acceptHint(Object handle, LightweightBoundTypeArgument boundTypeArgument) { if (boundTypeArgument.getTypeReference() != null && !boundTypeArgument.getTypeReference().isOwnedBy(getReferenceOwner())) { throw new IllegalArgumentException("reference is not owned by this resolved types"); } super.acceptHint(handle, boundTypeArgument); }
Example 12
Source File: FeatureScopes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected boolean isUnknownReceiverType(LightweightTypeReference receiverType) { if (receiverType.isUnknown()) { return true; } if (receiverType instanceof UnboundTypeReference) { List<LightweightBoundTypeArgument> hints = ((UnboundTypeReference) receiverType).getAllHints(); for(LightweightBoundTypeArgument hint: hints) { LightweightTypeReference typeReference = hint.getTypeReference(); if (typeReference != null && typeReference.isUnknown()) return true; } } return false; }
Example 13
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 14
Source File: BoundTypeArgumentMerger.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public boolean isPossibleMergeResult(List<LightweightBoundTypeArgument> allArguments, LightweightTypeReference candidate) { if (allArguments.isEmpty()) return false; if (allArguments.size() == 1 && !candidate.isWildcard()) { LightweightBoundTypeArgument singleArgument = allArguments.get(0); if (VarianceInfo.OUT.equals(singleArgument.getActualVariance()) && singleArgument.getActualVariance().equals(singleArgument.getDeclaredVariance())) { LightweightTypeReference singleReference = singleArgument.getTypeReference(); if (singleReference.isResolved()) return candidate.isAssignableFrom(singleReference, TypeConformanceComputationArgument.DEFAULT); } } LightweightMergedBoundTypeArgument merged = merge(allArguments, candidate.getOwner()); if (merged == null) return false; VarianceInfo variance = merged.getVariance(); LightweightTypeReference type = merged.getTypeReference(); if (variance == null || type == null) { return false; } switch(variance) { case INVARIANT: { int result = candidate.internalIsAssignableFrom(type, new TypeConformanceComputationArgument(false, true, true, true, false, false)); if ((result & ConformanceFlags.SUCCESS) != 0 && (result & ConformanceFlags.RAW_TYPE_CONVERSION) == 0) { return true; } return false; } case OUT: return type.isAssignableFrom(candidate, TypeConformanceComputationArgument.DEFAULT); case IN: return candidate.isAssignableFrom(type, TypeConformanceComputationArgument.DEFAULT); default: throw new IllegalStateException("Unknown variance info: " + variance); } }
Example 15
Source File: BoundTypeArgumentMerger.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected LightweightMergedBoundTypeArgument getSingleArgumentAsMergedArgument(LightweightBoundTypeArgument argument) { LightweightTypeReference typeReference = argument.getTypeReference(); VarianceInfo varianceInfo = argument.getDeclaredVariance().mergeDeclaredWithActual(argument.getActualVariance()); if (argument.getDeclaredVariance() == VarianceInfo.IN && varianceInfo == VarianceInfo.INVARIANT) { if (typeReference.getKind() == LightweightTypeReference.KIND_WILDCARD_TYPE_REFERENCE) { typeReference = typeReference.getInvariantBoundSubstitute(); } } return new LightweightMergedBoundTypeArgument(typeReference, varianceInfo); }
Example 16
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 17
Source File: ResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void addNonRecursiveHints(List<LightweightBoundTypeArgument> hints, Set<Object> seenHandles, List<LightweightBoundTypeArgument> result) { for(LightweightBoundTypeArgument hint: hints) { LightweightTypeReference reference = hint.getTypeReference(); if (reference instanceof UnboundTypeReference) { addNonRecursiveHints(hint, (UnboundTypeReference)reference, seenHandles, result); } else { if (!result.contains(hint)) result.add(hint); } } }
Example 18
Source File: ValidatingStackedResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public void acceptHint(Object handle, LightweightBoundTypeArgument boundTypeArgument) { if (boundTypeArgument.getTypeReference() != null && !boundTypeArgument.getTypeReference().isOwnedBy(getReferenceOwner())) { throw new IllegalArgumentException("reference is not owned by this resolved types"); } super.acceptHint(handle, boundTypeArgument); }
Example 19
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 20
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; }