org.eclipse.xtext.xbase.typesystem.references.LightweightMergedBoundTypeArgument Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.typesystem.references.LightweightMergedBoundTypeArgument.
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: ElementOrComponentTypeComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public LightweightTypeReference doVisitParameterizedTypeReference(ParameterizedTypeReference reference) { DeclaratorTypeArgumentCollector typeArgumentCollector = new ConstraintAwareTypeArgumentCollector(owner); Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> typeParameterMapping = typeArgumentCollector.getTypeParameterMapping(reference); TypeParameterSubstitutor<?> substitutor = new UnboundTypeParameterPreservingSubstitutor(typeParameterMapping, owner); JvmGenericType iterable = (JvmGenericType) owner.getServices().getTypeReferences().findDeclaredType(Iterable.class, owner.getContextResourceSet()); if (iterable == null) { return owner.newReferenceToObject(); } LightweightTypeReference substituteMe = owner.newParameterizedTypeReference(iterable.getTypeParameters().get(0)); LightweightTypeReference substitutedArgument = substitutor.substitute(substituteMe).getUpperBoundSubstitute(); if (substitutedArgument.getType() instanceof JvmTypeParameter && !(owner.getDeclaredTypeParameters().contains(substitutedArgument.getType()))) { return substitutedArgument.getRawTypeReference(); } return substitutedArgument; }
Example #2
Source File: ResolvedOperationInHierarchy.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override protected TypeParameterSubstitutor<?> getSubstitutor() { if (isRawTypeInheritance()) { return new RawTypeSubstitutor(getContextType().getOwner()); } TypeParameterSubstitutor<?> result = super.getSubstitutor(); List<JvmTypeParameter> typeParameters = getTypeParameters(); if (!typeParameters.isEmpty()) { List<JvmTypeParameter> resolvedTypeParameters = getResolvedTypeParameters(); int max = Math.min(typeParameters.size(), resolvedTypeParameters.size()); ITypeReferenceOwner owner = getContextType().getOwner(); Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> additionalMapping = Maps.newHashMapWithExpectedSize(max); for(int i = 0; i < max; i++) { LightweightTypeReference localReference = owner.newParameterizedTypeReference(resolvedTypeParameters.get(i)); additionalMapping.put(typeParameters.get(i), new LightweightMergedBoundTypeArgument(localReference, VarianceInfo.INVARIANT)); } result.enhanceMapping(additionalMapping); } return result; }
Example #3
Source File: InstanceFeatureDescription.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected InstanceFeatureDescription( QualifiedName qualifiedName, JvmFeature feature, XExpression receiver, LightweightTypeReference receiverType, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> receiverTypeParameterMapping, int receiverConformanceFlags, int bucketId, boolean visible) { super(qualifiedName, feature, bucketId, visible); if (feature.isStatic()) { throw new IllegalArgumentException(String.valueOf(feature)); } if (receiverConformanceFlags == ConformanceFlags.NONE) { throw new IllegalArgumentException(String.valueOf(receiverConformanceFlags)); } this.receiver = receiver; this.receiverType = receiverType; this.receiverTypeParameterMapping = receiverTypeParameterMapping; this.receiverConformanceFlags = receiverConformanceFlags; }
Example #4
Source File: UnboundTypeReferences.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public static JvmTypeParameter findMappedParameter(JvmTypeParameter parameter, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping, Collection<JvmTypeParameter> visited) { for(Map.Entry<JvmTypeParameter, LightweightMergedBoundTypeArgument> entry: mapping.entrySet()) { LightweightTypeReference reference = entry.getValue().getTypeReference(); JvmType type = null; if (reference instanceof UnboundTypeReference) { type = ((UnboundTypeReference) reference).getTypeParameter(); } else { type = reference.getType(); } if (parameter == type) { if (visited.add(entry.getKey())) return entry.getKey(); return null; } } return null; }
Example #5
Source File: ActualTypeArgumentMergeTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public Pair<Map<JvmTypeParameter, List<LightweightBoundTypeArgument>>, LightweightMergedBoundTypeArgument> merge(final Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> mapping, final String typeParamName) { final Set<JvmTypeParameter> allKeys = mapping.keySet(); for (final JvmTypeParameter key : allKeys) { String _simpleName = key.getSimpleName(); boolean _equals = Objects.equal(_simpleName, typeParamName); if (_equals) { final List<LightweightBoundTypeArgument> mappingData = mapping.get(key); LightweightMergedBoundTypeArgument _merge = this.merger.merge(mappingData, this.getOwner()); return Pair.<Map<JvmTypeParameter, List<LightweightBoundTypeArgument>>, LightweightMergedBoundTypeArgument>of(mapping, _merge); } } StringConcatenation _builder = new StringConcatenation(); _builder.append("No mapping for "); _builder.append(typeParamName); _builder.append(" in "); final Function1<JvmTypeParameter, String> _function = (JvmTypeParameter it) -> { return it.getSimpleName(); }; Iterable<String> _map = IterableExtensions.<JvmTypeParameter, String>map(mapping.keySet(), _function); _builder.append(_map); Assert.fail(_builder.toString()); return null; }
Example #6
Source File: DeferredTypeParameterHintCollectorTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public void hasNoHintsFor(final Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping, final String typeParamName) { final Set<JvmTypeParameter> allKeys = mapping.keySet(); for (final JvmTypeParameter key : allKeys) { String _simpleName = key.getSimpleName(); boolean _equals = Objects.equal(_simpleName, typeParamName); if (_equals) { LightweightTypeReference _typeReference = mapping.get(key).getTypeReference(); final UnboundTypeReference unbound = ((UnboundTypeReference) _typeReference); boolean _isEmpty = unbound.getAllHints().isEmpty(); boolean _not = (!_isEmpty); if (_not) { StringConcatenation _builder = new StringConcatenation(); _builder.append("Unexpected mapping for "); _builder.append(typeParamName); _builder.append(" in "); final Function1<JvmTypeParameter, String> _function = (JvmTypeParameter it) -> { return it.getSimpleName(); }; Iterable<String> _map = IterableExtensions.<JvmTypeParameter, String>map(mapping.keySet(), _function); _builder.append(_map); Assert.fail(_builder.toString()); } } } }
Example #7
Source File: InstanceExtensionDescription.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected InstanceExtensionDescription( QualifiedName qualifiedName, JvmFeature feature, XExpression receiver, LightweightTypeReference receiverType, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> typeParameterMapping, int receiverConformanceFlags, XExpression firstArgument, LightweightTypeReference firstArgumentType, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> firstArgumentTypeParameterMapping, int firstArgumentConformanceFlags, int bucketId, boolean visible, boolean validStaticState) { super(qualifiedName, feature, EcoreUtil.copy(receiver), receiverType, typeParameterMapping, receiverConformanceFlags, bucketId, visible); this.firstArgument = firstArgument; this.firstArgumentType = firstArgumentType; this.firstArgumentTypeParameterMapping = firstArgumentTypeParameterMapping; this.firstArgumentConformanceFlags = firstArgumentConformanceFlags; this.validStaticState = validStaticState; }
Example #8
Source File: AbstractLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public List<LightweightTypeReference> getTypeArguments() { if (typeArguments == null) { List<JvmTypeParameter> typeParameters = getDeclaredTypeParameters(); if (typeParameters.isEmpty() || getTypeParameterMapping().isEmpty()) { typeArguments = Collections.emptyList(); } else { List<LightweightTypeReference> result = Lists.newArrayListWithCapacity(typeParameters.size()); for(JvmTypeParameter parameter: typeParameters) { LightweightMergedBoundTypeArgument typeArgument = getTypeParameterMapping().get(parameter); result.add(typeArgument.getTypeReference()); } typeArguments = result; } } return typeArguments; }
Example #9
Source File: UnboundTypeParameterPreservingSubstitutor.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override /* @Nullable */ protected LightweightTypeReference getBoundTypeArgument(ParameterizedTypeReference reference, JvmTypeParameter type, Set<JvmTypeParameter> visiting) { LightweightMergedBoundTypeArgument boundTypeArgument = getTypeParameterMapping().get(type); if (boundTypeArgument != null) { LightweightTypeReference boundReference = boundTypeArgument.getTypeReference(); if (boundReference != null && reference != boundReference) { if (boundReference instanceof UnboundTypeReference) return boundReference.copyInto(getOwner()); JvmType boundType = boundReference.getType(); if (boundType != type) { if (visiting.add(type)) { try { LightweightTypeReference result = boundReference.accept(this, visiting); return result; } finally { visiting.remove(type); } } else { return reference; } } } } return null; }
Example #10
Source File: TypeParameterByConstraintSubstitutor.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override /* @Nullable */ protected LightweightTypeReference getUnmappedSubstitute(ParameterizedTypeReference reference, JvmTypeParameter type, ConstraintVisitingInfo visiting) { if (!ignoreDeclaredTypeParameters) { if (isDeclaredTypeParameter(type)) { return reference; } } ConstraintAwareTypeArgumentCollector collector = new ConstraintAwareTypeArgumentCollector(getOwner()); LightweightTraversalData data = new LightweightTraversalData(); data.getTypeParameterMapping().putAll(getTypeParameterMapping()); reference.accept(collector, data); LightweightMergedBoundTypeArgument boundTypeArgument = data.getTypeParameterMapping().get(type); if (boundTypeArgument != null && boundTypeArgument.getTypeReference() != reference) { return boundTypeArgument.getTypeReference().accept(this, visiting); } if (boundTypeArgument != null) return boundTypeArgument.getTypeReference(); return null; }
Example #11
Source File: RawTypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected int isConformantMergeResult(LightweightMergedBoundTypeArgument mergeResult, LightweightTypeReference right, int flags) { LightweightTypeReference mergeResultReference = mergeResult.getTypeReference(); if (right.isWildcard() && mergeResultReference.isWildcard()) { if (right.getLowerBoundSubstitute().isAny()) { LightweightTypeReference lowerBoundMergeResult = mergeResultReference.getLowerBoundSubstitute(); if (!lowerBoundMergeResult.isAny()) { mergeResultReference = lowerBoundMergeResult; } } else { flags = flags | AS_TYPE_ARGUMENT; } } else if (mergeResultReference.isWildcard()) { flags = flags | AS_TYPE_ARGUMENT; } return isConformant(mergeResultReference, right, flags); }
Example #12
Source File: InstanceFeatureDescriptionWithImplicitReceiver.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected InstanceFeatureDescriptionWithImplicitReceiver( QualifiedName qualifiedName, JvmFeature feature, XExpression receiver, LightweightTypeReference receiverType, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> typeParameterMapping, int receiverConformanceFlags, int bucketId, boolean visible, boolean validStaticState) { super(qualifiedName, feature, EcoreUtil.copy(receiver), receiverType, typeParameterMapping, receiverConformanceFlags, bucketId, visible); this.validStaticState = validStaticState; }
Example #13
Source File: DynamicExtensionsScope.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected BucketedEObjectDescription createReceiverDescription(QualifiedName name, JvmFeature feature, XExpression receiver, LightweightTypeReference receiverType, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> receiverTypeParameterMapping, ExpressionBucket bucket, boolean validStaticState) { return new InstanceFeatureDescriptionWithImplicitReceiver( name, feature, receiver, receiverType, receiverTypeParameterMapping, ConformanceFlags.CHECKED_SUCCESS, bucket.getId(), getSession().isVisible(feature), validStaticState); }
Example #14
Source File: FeatureLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected void initializeMapping(JvmTypeParameter typeParameter, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> result) { ITypeReferenceOwner owner = getState().getReferenceOwner(); if (typeParameter.getDeclarator() instanceof JvmType && owner.getDeclaredTypeParameters().contains(typeParameter)) { LightweightTypeReference typeReference = owner.newParameterizedTypeReference(typeParameter); result.put(typeParameter, new LightweightMergedBoundTypeArgument(typeReference, VarianceInfo.INVARIANT)); } else { super.initializeMapping(typeParameter, result); } }
Example #15
Source File: FeatureLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> getDeclaratorParameterMapping() { if (isStatic()) { if (getFeature() instanceof JvmConstructor) // this() or super() return description.getImplicitReceiverTypeParameterMapping(); return super.getDeclaratorParameterMapping(); } if (getImplicitReceiver() != null) return description.getImplicitReceiverTypeParameterMapping(); return description.getSyntacticReceiverTypeParameterMapping(); }
Example #16
Source File: AbstractPendingLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * Returns the mapping of type parameters to their bound arguments. * * @see #initializeTypeParameterMapping() */ @Override protected Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> getTypeParameterMapping() { if (typeParameterMapping == null) { typeParameterMapping = initializeTypeParameterMapping(); } return typeParameterMapping; }
Example #17
Source File: DynamicExtensionsScope.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void getAllLocalElements(ExpressionBucket bucket, List<IEObjectDescription> result) { Map<XExpression, LightweightTypeReference> extensionProviders = bucket.getExtensionProviders(); for (Map.Entry<XExpression, LightweightTypeReference> extensionProvider : extensionProviders.entrySet()) { LightweightTypeReference extensionType = extensionProvider.getValue(); Set<JvmFeature> allFeatures = getAllFeatures(extensionType, bucket.getResolvedFeaturesProvider()); if (!allFeatures.isEmpty()) { Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> receiverTypeParameterMapping = new DeclaratorTypeArgumentCollector().getTypeParameterMapping(extensionType); for (JvmFeature feature : allFeatures) { if (!feature.isStatic()) { addDescriptions(feature, extensionProvider.getKey(), extensionType, receiverTypeParameterMapping, bucket, result); } } } } }
Example #18
Source File: ConstructorLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected boolean isBoundTypeArgumentSkipped(JvmTypeParameter type, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping, ITypeReferenceOwner owner) { if (super.isBoundTypeArgumentSkipped(type, mapping, owner)) { if (getConstructor().getDeclaringType() != type.getDeclarator()) { return true; } } return false; }
Example #19
Source File: DynamicExtensionsScope.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected BucketedEObjectDescription createExtensionDescription(QualifiedName name, JvmFeature feature, XExpression receiver, LightweightTypeReference receiverType, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> receiverTypeParameterMapping, ExpressionBucket bucket, boolean validStaticState) { if (helper == null || !helper.isPossibleExtension(feature)) { return null; } return doCreateExtensionDescription(name, feature, receiver, receiverType, receiverTypeParameterMapping, bucket, validStaticState); }
Example #20
Source File: DeferredTypeParameterHintCollectorTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> in(final String typeParameters, final String expectedType, final String actualType) { final JvmOperation operation = this.operation(typeParameters, expectedType, actualType); ITypeReferenceOwner _owner = this.getOwner(); final DeferredTypeParameterHintCollector collector = new DeferredTypeParameterHintCollector(_owner); final DefaultReentrantTypeResolver resolver = this.resolverProvider.get(); resolver.initializeFrom(EcoreUtil.getRootContainer(operation)); ITypeReferenceOwner _owner_1 = this.getOwner(); PublicResolvedTypes _publicResolvedTypes = new PublicResolvedTypes(resolver); final MockTypeParameterSubstitutor substitutor = new MockTypeParameterSubstitutor(_owner_1, _publicResolvedTypes); final LightweightTypeReference hasUnbounds = substitutor.substitute(this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType())); final LightweightTypeReference isActual = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>last(operation.getParameters()).getParameterType()); collector.processPairedReferences(hasUnbounds, isActual); return substitutor.getTypeParameterMapping(); }
Example #21
Source File: AbstractLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> initializeTypeParameterMapping() { Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> typeParameterMapping; state.acceptCandidate(expression, this); List<JvmTypeParameter> declaredTypeParameters = getDeclaredTypeParameters(); if (declaredTypeParameters.isEmpty()) { typeParameterMapping = Collections.emptyMap(); } else { typeParameterMapping = initializeTypeParameterMapping(declaredTypeParameters); } return typeParameterMapping; }
Example #22
Source File: RecomputingReentrantTypeResolver.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public void doAssertEqualLinkingData(final ILinkingCandidate left, final ILinkingCandidate right) { try { this.assertEqualReferences("typeArguments", left.getTypeArguments(), right.getTypeArguments()); this.assertEqualReferences("syntacticTypeArguments", this.<List<LightweightTypeReference>>invokeAndCast(left, "getSyntacticTypeArguments"), this.<List<LightweightTypeReference>>invokeAndCast(right, "getSyntacticTypeArguments")); Assert.assertEquals("arguments", this._reflectExtensions.invoke(left, "getArguments"), this._reflectExtensions.invoke(right, "getArguments")); Assert.assertEquals("declaredTypeParameters", this._reflectExtensions.invoke(left, "getDeclaredTypeParameters"), this._reflectExtensions.invoke(right, "getDeclaredTypeParameters")); this.assertEqualMapping("typeParameterMapping", this.<Map<JvmTypeParameter, LightweightMergedBoundTypeArgument>>invokeAndCast(left, "getTypeParameterMapping"), this.<Map<JvmTypeParameter, LightweightMergedBoundTypeArgument>>invokeAndCast(right, "getTypeParameterMapping")); this.assertEqualMapping("declaratorParameterMapping", this.<Map<JvmTypeParameter, LightweightMergedBoundTypeArgument>>invokeAndCast(left, "getDeclaratorParameterMapping"), this.<Map<JvmTypeParameter, LightweightMergedBoundTypeArgument>>invokeAndCast(right, "getDeclaratorParameterMapping")); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #23
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 #24
Source File: SuperConstructorDescription.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public SuperConstructorDescription( QualifiedName qualifiedName, JvmConstructor constructor, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> typeParameterMapping, int bucketId, boolean visible) { super(qualifiedName, constructor, bucketId, visible); this.typeParameterMapping = typeParameterMapping; }
Example #25
Source File: ConstructorDelegateScope.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> getReceiverTypeParameterMapping() { if (receiverTypeParameterMapping == null) { receiverTypeParameterMapping = Collections.emptyMap(); if (contextType != null) { receiverTypeParameterMapping = new DeclaratorTypeArgumentCollector().getTypeParameterMapping(contextType); } } return receiverTypeParameterMapping; }
Example #26
Source File: TypeParameterSubstitutor.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected LightweightTypeReference getBoundTypeArgument(ParameterizedTypeReference reference, JvmTypeParameter type, Visiting visiting) { LightweightMergedBoundTypeArgument boundTypeArgument = typeParameterMapping.get(type); if (boundTypeArgument != null) { LightweightTypeReference boundReference = boundTypeArgument.getTypeReference(); if (boundReference != null && reference != boundReference && boundReference.getType() != type) { return boundReference.accept(this, visiting); } } return null; }
Example #27
Source File: ActualTypeArgumentMergeTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> to(final Pair<Map<JvmTypeParameter, List<LightweightBoundTypeArgument>>, LightweightMergedBoundTypeArgument> merged, final String type, final VarianceInfo variance) { Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> _xblockexpression = null; { if ((type == null)) { Assert.assertNull(merged.getValue()); } else { Assert.assertEquals(type, merged.getValue().getTypeReference().toString()); Assert.assertEquals(variance, merged.getValue().getVariance()); } _xblockexpression = merged.getKey(); } return _xblockexpression; }
Example #28
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 #29
Source File: AbstractTypeReferencePairWalker.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void doVisitMatchingTypeParameters(ParameterizedTypeReference reference, ParameterizedTypeReference declaration) { Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> actualMapping = getTypeParameterMapping(reference); TypeParameterSubstitutor<?> actualSubstitutor = createTypeParameterSubstitutor(actualMapping); Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> declaredMapping = getTypeParameterMapping(declaration); TypeParameterSubstitutor<?> declaredSubstitutor = createTypeParameterSubstitutor(declaredMapping); Set<JvmTypeParameter> actualBoundParameters = actualMapping.keySet(); Set<JvmTypeParameter> visited = Sets.newHashSet(); outer: for (JvmTypeParameter actualBoundParameter : actualBoundParameters) { if (visited.add(actualBoundParameter)) { LightweightMergedBoundTypeArgument declaredBoundArgument = declaredMapping.get(actualBoundParameter); while(declaredBoundArgument == null && actualBoundParameter != null) { actualBoundParameter = findMappedParameter(actualBoundParameter, actualMapping, visited); if (actualBoundParameter == null) continue outer; declaredBoundArgument = declaredMapping.get(actualBoundParameter); } if (declaredBoundArgument != null) { LightweightTypeReference declaredTypeReference = declaredBoundArgument.getTypeReference(); JvmType declaredType = declaredTypeReference.getType(); if (declaredType instanceof JvmTypeParameter) { JvmTypeParameter declaredTypeParameter = (JvmTypeParameter) declaredType; if (!shouldProcessInContextOf(declaredTypeParameter, actualBoundParameters, visited)) continue; declaredTypeReference = declaredSubstitutor.substitute(declaredTypeReference); } LightweightTypeReference actual = actualSubstitutor.substitute(actualMapping.get(actualBoundParameter).getTypeReference()); if (!actual.isResolved() || !declaredTypeReference.isResolved() || !Strings.equal(actual.getIdentifier(), declaredTypeReference.getIdentifier())) { if (reference.getType() != actual.getType() || declaredTypeReference.getType() != declaration.getType() || !reference.getIdentifier().equals(actual.getIdentifier()) || !declaredTypeReference.getIdentifier().equals(declaration.getIdentifier())) { outerVisit(declaredTypeReference, actual, declaration, VarianceInfo.INVARIANT, VarianceInfo.INVARIANT); } } } } } }
Example #30
Source File: BoundTypeArgumentMergerTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public void to(final LightweightMergedBoundTypeArgument merged, final String type, final VarianceInfo variance) { if ((type == null)) { Assert.assertNull(merged); } else { Assert.assertEquals(type, merged.getTypeReference().getSimpleName()); Assert.assertEquals(variance, merged.getVariance()); } }