protected void enhanceCompoundReference(List<LightweightTypeReference> references, CompoundTypeReference result, ResourceSet resourceSet) { if (references.isEmpty()) { throw new IllegalStateException("References may not be empty"); } for(LightweightTypeReference component: references) { result.addComponent(component.accept(this, resourceSet)); } }
@Override protected void doVisitTypeReference(LightweightTypeReference reference) { result.addComponent(reference.copyInto(owner)); } };
protected LightweightTypeReference wrapInCompoundTypeIfNecessary( List<LightweightTypeReference> referencesWithSameDistance) { if (referencesWithSameDistance.size() == 1) { return referencesWithSameDistance.get(0); } else if (referencesWithSameDistance.size() > 1) { CompoundTypeReference result = owner.newCompoundTypeReference(false); for(LightweightTypeReference reference: referencesWithSameDistance) { result.addComponent(reference); } return result; } return null; }
@Override protected LightweightTypeReference doCopyInto(ITypeReferenceOwner owner) { CompoundTypeReference result = owner.newCompoundTypeReference(synonym); if (components != null && !components.isEmpty()) { for(LightweightTypeReference typeArgument: components) { result.addComponent(typeArgument.copyInto(owner)); } } return result; }
@Override protected void doVisitMultiTypeReference(CompoundTypeReference reference) { List<LightweightTypeReference> components = reference.getMultiTypeComponents(); for(LightweightTypeReference component: components) { result.addComponent(component.copyInto(owner)); } } @Override
protected LightweightTypeReference doVisitCompoundReference(JvmCompoundTypeReference reference, boolean synonym) { CompoundTypeReference result = owner.newCompoundTypeReference(synonym); for(JvmTypeReference component: reference.getReferences()) { result.addComponent(visit(component)); } return result; }
@Override public LightweightTypeReference getUpperBoundSubstitute() { if (isUnbounded()) { return getOwner().newReferenceToObject(); } List<LightweightTypeReference> upperBounds = getUpperBounds(); if (upperBounds.size() == 1) { LightweightTypeReference result = upperBounds.get(0); return result; } CompoundTypeReference result = getOwner().newCompoundTypeReference(false); for(LightweightTypeReference upperBound: upperBounds) { result.addComponent(upperBound); } return result; }
@Override protected boolean accept(LightweightTypeReference synonymType, int flags) { List<JvmType> rawTypes = synonymType.getRawTypes(); ConformanceFlags.sanityCheck(flags); SynonymTypeBucket bucket = new SynonymTypeBucket(id++, rawTypes, resolvedFeaturesProvider, flags); CompoundTypeReference compoundTypeReference = synonymType.getOwner().newCompoundTypeReference(true); compoundTypeReference.addComponent(featureDeclarator); compoundTypeReference.addComponent(synonymType); wrapper.set(createReceiverFeatureScope(featureCall, receiver, compoundTypeReference, receiverFeature, implicit, validStaticScope, bucket, wrapper.get(), session)); return true; }
protected LightweightTypeReference getAndEnhanceIterableOrArrayFromComponent(LightweightTypeReference parameterType, JvmGenericType iterableType, final CompoundTypeReference compoundResult) { if (parameterType.isUnknown()) { compoundResult.addComponent(parameterType); return parameterType; if (parameterType.isPrimitive()) { iterableOrArray = owner.newArrayTypeReference(parameterType); compoundResult.addComponent(iterableOrArray); addAsArrayComponentAndIterable = parameterType.getWrapperTypeIfPrimitive(); } else if (parameterType.isAny()) { wildcard.addUpperBound(addAsArrayComponentAndIterable); reference.addTypeArgument(wildcard); compoundResult.addComponent(reference); if (iterableOrArray == null) { iterableOrArray = reference; LightweightTypeReference potentialPrimitive = addAsArrayComponentAndIterable.getPrimitiveIfWrapperType(); if (potentialPrimitive != addAsArrayComponentAndIterable) { compoundResult.addComponent(owner.newArrayTypeReference(potentialPrimitive)); compoundResult.addComponent(owner.newArrayTypeReference(addAsArrayComponentAndIterable)); } else if (iterableOrArray == null) { // no JRE on the CP if (addAsArrayComponentAndIterable != null) { iterableOrArray = owner.newArrayTypeReference(addAsArrayComponentAndIterable); compoundResult.addComponent(iterableOrArray); } else { compoundResult.addComponent(parameterType); return parameterType;
CompoundTypeReference result = owner.newCompoundTypeReference(false); for(LightweightTypeReference upperBound: upperBounds) { result.addComponent(upperBound);
@Override protected LocalTypeSubstitutor.SubstitutionResult doVisitCompoundTypeReference(CompoundTypeReference reference, VarianceInfo varianceInfo) { CompoundTypeReference result = owner.newCompoundTypeReference(reference.isSynonym()); boolean didSubstitute = false; for(LightweightTypeReference component: reference.getMultiTypeComponents()) { SubstitutionResult visited = visitTypeArgument(component, varianceInfo); result.addComponent(visited.typeReference); didSubstitute = didSubstitute || visited.didSubstitute; } return new SubstitutionResult(result, didSubstitute); }
protected LightweightTypeReference getRawTypeFromConstraints(ITypeReferenceOwner owner, JvmTypeParameter typeParameter, ResourceSet resourceSet) { if (visited.add(typeParameter)) { List<JvmTypeConstraint> constraints = typeParameter.getConstraints(); if (!constraints.isEmpty()) { if (constraints.size() > 1) { CompoundTypeReference result = owner.newCompoundTypeReference(false); for(JvmTypeConstraint constraint: constraints) { if (constraint instanceof JvmUpperBound) { JvmTypeReference typeReference = constraint.getTypeReference(); if (typeReference != null) result.addComponent(owner.toLightweightTypeReference(typeReference).accept(this, resourceSet)); } } return result; } else { JvmTypeReference typeReference = constraints.get(0).getTypeReference(); if (typeReference != null) { LightweightTypeReference result = owner.toLightweightTypeReference(typeReference).accept(this, resourceSet); return result; } } } } return createObjectReference(owner, resourceSet); }
@Override public LightweightTypeReference getRawTypeReference() { if (isAllRawType()) { return this; } CompoundTypeReference result = getOwner().newCompoundTypeReference(isSynonym()); for(LightweightTypeReference component: expose(components)) { result.addComponent(component.getRawTypeReference()); } return result; }
@Override protected LightweightTypeReference doVisitCompoundTypeReference(CompoundTypeReference reference, Visiting visiting) { if (reference.isResolved() && reference.isOwnedBy(getOwner())) return reference; CompoundTypeReference result = getOwner().newCompoundTypeReference(reference.isSynonym()); for(LightweightTypeReference component: reference.getMultiTypeComponents()) { result.addComponent(visitTypeArgument(component, visiting)); } return result; }
} else { CompoundTypeReference bothExpectations = state.getReferenceOwner().newCompoundTypeReference(true); bothExpectations.addComponent(componentType); bothExpectations.addComponent(expectation); state.refineExpectedType(value, bothExpectations);