@Override public boolean isWildcard() { if (resolvedTo != null) return resolvedTo.isWildcard(); return false; }
@Override public boolean isWildCard() { return this.getDelegate().isWildcard(); }
public ArrayTypeReference(ITypeReferenceOwner owner, LightweightTypeReference component) { super(owner); this.component = Preconditions.checkNotNull(component, "component"); // TODO decide about the following constraint which prevents (Number & Serializable)[] // if (!(component.getType() instanceof JvmComponentType)) { // throw new IllegalArgumentException("Cannot create array reference from non-component type " + component.getIdentifier()); // } if (component.isAny()) { throw new IllegalArgumentException("component is invalid: type <any> is not allowed"); } if (component.isWildcard()) { throw new IllegalArgumentException("component is invalid: " + component); } if (!component.isOwnedBy(owner)) { throw new IllegalArgumentException("component is not valid in current context"); } }
/** * Implements fall-back strategy. If the expected type of a collection literal does not match the actual type, but the expected element * types would match the actual element type, the collection literal will be successfully typed according to the expectation. */ protected boolean matchesExpectation(LightweightTypeReference elementType, LightweightTypeReference expectation) { return expectation != null && expectation.isResolved() && !expectation.isWildcard() && expectation.isAssignableFrom(elementType); }
@Override protected Boolean doVisitParameterizedTypeReference(ParameterizedTypeReference reference) { for(LightweightTypeReference argument: reference.getTypeArguments()) { if (argument.isWildcard()) { if (!((WildcardTypeReference)argument).isUnbounded()) { return Boolean.TRUE; } } else { return Boolean.TRUE; } } return Boolean.FALSE; }
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); }
protected void ensureNotPrimitiveNorWildcard(JvmTypeReference typeRef) { LightweightTypeReference reference = toLightweightTypeReference(typeRef); if (reference.isPrimitive()) { error("Primitives cannot be used as type arguments.", typeRef, null, INVALID_USE_OF_TYPE); } if (reference.isWildcard()) { error("Wildcard types are not allowed in this context", typeRef, null, INSIGNIFICANT_INDEX, INVALID_USE_OF_WILDCARD); } }
@Override protected ITreeAppendable appendTypeArguments(XAbstractFeatureCall call, ITreeAppendable original) { if (!call.getTypeArguments().isEmpty()) { return super.appendTypeArguments(call, original); } ILocationData completeLocationData = getLocationWithTypeArguments(call); ITreeAppendable completeFeatureCallAppendable = completeLocationData != null ? original.trace(completeLocationData) : original; IResolvedTypes resolvedTypes = batchTypeResolver.resolveTypes(call); List<LightweightTypeReference> typeArguments = resolvedTypes.getActualTypeArguments(call); if (!typeArguments.isEmpty()) { for(LightweightTypeReference typeArgument: typeArguments) { if (typeArgument.isWildcard()) { return completeFeatureCallAppendable; } } completeFeatureCallAppendable.append("<"); for (int i = 0; i < typeArguments.size(); i++) { if (i != 0) { completeFeatureCallAppendable.append(", "); } completeFeatureCallAppendable.append(typeArguments.get(i)); } completeFeatureCallAppendable.append(">"); } return completeFeatureCallAppendable; }
@Override /* @Nullable */ protected LightweightMergedBoundTypeArgument getBoundTypeArgument(JvmTypeParameter typeParameter, ConstraintVisitingInfo info) { LightweightMergedBoundTypeArgument result = super.getBoundTypeArgument(typeParameter, info); if (result != null) { LightweightTypeReference typeReference = result.getTypeReference(); if (result.getVariance() == VarianceInfo.INVARIANT) { if (typeReference.isWildcard() && typeReference.getLowerBoundSubstitute().isAny() && typeReference.getUpperBoundSubstitute().isType(Object.class)) { // assume unbound wildcard - use the constraints of the respective type parameter if (!typeParameter.getConstraints().isEmpty()) { JvmTypeConstraint constraint = typeParameter.getConstraints().get(0); if (constraint instanceof JvmUpperBound) { LightweightTypeReference reference = getOwner().toLightweightTypeReference(constraint.getTypeReference()); return new LightweightMergedBoundTypeArgument(reference, VarianceInfo.OUT); } } } } if (declaratorParameterMapping.containsKey(typeParameter) && typeReference.isWildcard()) { wasCapturedWildcard = true; } } return result; }
hasTypeArguments = !typeArguments.isEmpty(); for(LightweightTypeReference typeArgument: typeArguments) { if (typeArgument.isWildcard()) { if (typeArgument.isWildcard()) {
if (inferredHints.size() == 1 && !varianceHints.isEmpty()) { LightweightBoundTypeArgument hint = inferredHints.get(0); if ((hint.getDeclaredVariance() == VarianceInfo.IN && hint.getActualVariance() == VarianceInfo.INVARIANT) && !hint.getTypeReference().isWildcard()) {
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 typeArgument = typeArguments.get(i); if (typeArgument != null) { if (typeArgument.isWildcard()) { containedUnresolved = true; } else {
@Override protected LightweightTypeReference doVisitWildcardTypeReference(WildcardTypeReference reference, Set<JvmTypeParameter> visiting) { if (reference.isResolved() && reference.isOwnedBy(getOwner())) return reference; WildcardTypeReference result = getOwner().newWildcardTypeReference(); LightweightTypeReference lowerBound = reference.getLowerBound(); if (lowerBound != null) { LightweightTypeReference visited = visitTypeArgument(lowerBound, visiting, true); if (visited.isWildcard()) { LightweightTypeReference substitute = visited.getInvariantBoundSubstitute(); result.setLowerBound(substitute); } else { result.setLowerBound(visited); } } for(LightweightTypeReference upperBound: reference.getUpperBounds()) { LightweightTypeReference visitedArgument = visitTypeArgument(upperBound, visiting); LightweightTypeReference upperBoundSubstitute = visitedArgument.getUpperBoundSubstitute(); result.addUpperBound(upperBoundSubstitute); } if (result.getUpperBounds().isEmpty()) { throw new IllegalStateException("UpperBounds may not be empty"); } return result; } };
UnboundTypeReference existingReference = (UnboundTypeReference) existingTypeReference; if (!isResolved(existingReference.getHandle())) { if (!boundTypeReference.isWildcard()) { existingReference.acceptHint(boundTypeReference, BoundTypeArgumentSource.INFERRED, boundTypeArgument, VarianceInfo.OUT, VarianceInfo.OUT); if (boundTypeReference.isWildcard()) { if (existingTypeArgument.getActualVariance() == VarianceInfo.INVARIANT && existingTypeArgument.getDeclaredVariance() == VarianceInfo.OUT) { existingReference.acceptHint(boundTypeReference.getInvariantBoundSubstitute(),
if (lowerBound != null) { LightweightTypeReference visited = visitTypeArgument(lowerBound, visiting, true); if (visited.isWildcard()) { LightweightTypeReference lowerBoundSubstitute = visited.getLowerBoundSubstitute(); if (lowerBoundSubstitute.isAny()) {