/** * Determines if this type reference denotes the same or a supertype of * the given {@code reference}. */ public boolean isAssignableFrom(LightweightTypeReference reference) { return isAssignableFrom(reference, TypeConformanceComputationArgument.DEFAULT); }
@Override protected boolean accept(LightweightTypeReference synonym, int flags) { if (declaringTypeReference.isAssignableFrom(synonym, rawConformanceCheck)) { expectedReceiverTypeWrapper.set(synonym); return false; } return true; } });
public LightweightTypeReference getMostSpecialType(List<LightweightTypeReference> candidates) { LightweightTypeReference type; type = candidates.get(0).getLowerBoundSubstitute(); for(int i = 1; i < candidates.size(); i++) { LightweightTypeReference candidate = candidates.get(i).getLowerBoundSubstitute(); if (type.isAssignableFrom(candidate)) { type = candidate; } else if (!candidate.isAssignableFrom(type)) return null; } return type; }
protected boolean memberOfTypeHierarchy(LightweightTypeReference type, LightweightTypeReference potentialMember) { return potentialMember.isAssignableFrom(type, new TypeConformanceComputationArgument(false, false, false, true, false, false)); }
/** * Determines if this type reference denotes the same type or a subtype of * the given {@code type}. */ public boolean isSubtypeOf(JvmType type) { if (type == null) { throw new IllegalArgumentException("type may not be null"); } // TODO interfaces don't inherit from non-interfaces, primitives, arrays, object // A final type does not have any subtypes // check for type == this.type LightweightTypeReference other = owner.toPlainTypeReference(type); boolean result = other.isAssignableFrom(this); return result; }
/** * Determines if this type reference denotes the same type or a supertype of * the given {@code type}. */ public boolean isAssignableFrom(JvmType type) { if (type == null) { throw new IllegalArgumentException("type may not be null"); } ParameterizedTypeReference other = getOwner().newParameterizedTypeReference(type); boolean result = isAssignableFrom(other); return result; }
/** * 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); }
public boolean isConformant(final EObject context, final JvmTypeReference expected, final JvmTypeReference actual) { boolean _xblockexpression = false; { final LightweightTypeReference actualType = this.toLightweightTypeReference(actual, context); final LightweightTypeReference expectedType = this.toLightweightTypeReference(expected, context); _xblockexpression = expectedType.isAssignableFrom(actualType); } return _xblockexpression; }
/** * Determines if this type reference denotes the same type or a supertype of * the given {@code clazz}. */ public boolean isAssignableFrom(Class<?> clazz) { if (isType(clazz)) { return true; } JvmType type = findType(clazz); if (type == null) { return false; } return isAssignableFrom(type); }
protected int compareDeclaredTypes(LightweightTypeReference left, LightweightTypeReference right, boolean leftResolved, boolean rightResolved) { int rightToLeftConformance = left.internalIsAssignableFrom(right, TypeConformanceComputationArgument.DEFAULT); if ((rightToLeftConformance & ConformanceFlags.SUCCESS) != 0) { if (!right.isAssignableFrom(left) && (!leftResolved || !rightResolved || ((rightToLeftConformance & ConformanceFlags.RAW_TYPE_CONVERSION) == 0))) { return 1; } } else { int leftToRightConformance = right.internalIsAssignableFrom(left, TypeConformanceComputationArgument.DEFAULT); if ((leftToRightConformance & ConformanceFlags.SUCCESS) != 0 && (!leftResolved || !rightResolved || ((leftToRightConformance & ConformanceFlags.RAW_TYPE_CONVERSION) == 0))) { return -1; } } return 0; }
@Override public boolean isAssignableFrom(final TypeReference typeReference) { boolean _xblockexpression = false; { boolean _isInferred = typeReference.isInferred(); if (_isInferred) { throw new UnsupportedOperationException("Cannot check assignability with an inferred type reference."); } _xblockexpression = this.getDelegate().isAssignableFrom(((TypeReferenceImpl) typeReference).getDelegate()); } return _xblockexpression; }
public boolean isAssignableFrom(final JvmTypeReference target, final JvmTypeReference source, final TypeConformanceComputationArgument argument) { if (((target == null) || (source == null))) { throw new RuntimeException("For testing assignment source and target types must not be null"); } if ((this.typeReferenceOwner == null)) { StandardTypeReferenceOwner _standardTypeReferenceOwner = new StandardTypeReferenceOwner(this.services, this.resourceSet); this.typeReferenceOwner = _standardTypeReferenceOwner; } final LightweightTypeReference lleft = this.typeReferenceOwner.toLightweightTypeReference(target); LightweightTypeReference lright = this.typeReferenceOwner.toLightweightTypeReference(source); final boolean assignable = lleft.isAssignableFrom(lright, argument); return assignable; }
@Override protected boolean accept(LightweightTypeReference synonym, int hints) { if (declaringTypeReference.isAssignableFrom(synonym, rawConformanceCheck)) { receiverTypeParameterMapping.set(new DeclaratorTypeArgumentCollector().getTypeParameterMapping(synonym)); return false; } return true; } });
@Override protected LightweightTypeReference deferredBindTypeArgument(ITypeExpectation expectation, LightweightTypeReference type) { LightweightTypeReference result = super.deferredBindTypeArgument(expectation, type); LightweightTypeReference expectedType = expectation.getExpectedType(); if (expectedType != null && getConstructorCall().getTypeArguments().isEmpty() && !result.isRawType() && !getDeclaredTypeParameters().isEmpty()) { if (!expectedType.isAssignableFrom(result, TypeConformanceComputationArgument.DEFAULT)) { LightweightTypeReference rawFeatureType = result.getRawTypeReference(); if (expectedType.isAssignableFrom(rawFeatureType)) { result = rawFeatureType; getTypeParameterMapping().clear(); } } } return result; }
/** * Returns true if the existing hints would allow to resolve to the given reference. */ public boolean canResolveTo(LightweightTypeReference reference) { if (internalIsResolved()) return reference.isAssignableFrom(resolvedTo, new TypeConformanceComputationArgument(false, true, true, true, false, false /* TODO do we need to support synonmys here? */)); List<LightweightBoundTypeArgument> hints = getAllHints(); if (!hints.isEmpty() && hasSignificantHints(hints)) { return canResolveTo(reference, hints); } return false; }
@Override public void exec(ITreeAppendable appendable) { TypeConformanceComputationArgument rawNoSynonyms = new TypeConformanceComputationArgument(true, false, true, true, false, false); if (caseParamType.isAssignableFrom(dispatchParamType, rawNoSynonyms) && !dispatchParamType.isPrimitive()) { appendable.append(name).append(" != null"); } else { appendable.append(name).append(" instanceof "); JvmType type = caseParamType.getWrapperTypeIfPrimitive().getType(); if (type == null) { throw new IllegalStateException(String.valueOf(caseParamType)); } appendable.append(type); } } });
/** * Check the type of the first parameter against the argument type rather * than the {@link #rawArgumentType}. Should not be used during linking * since we need proper error messages there for type mismatches. */ protected boolean isMatchingFirstParameterDeepCheck(JvmOperation feature) { if (isMatchingFirstParameter(feature)) { if (isResolvedReceiverType()) { LightweightTypeReference parameterType = argumentType.getOwner().toLightweightTypeReference(feature.getParameters().get(0).getParameterType()); if (isResolvedOrKnownTypeParam(parameterType) && !parameterType.isAssignableFrom(argumentType)) { return false; } } return true; } return false; }
@Override protected void addHint(UnboundTypeReference typeParameter, LightweightTypeReference reference) { LightweightTypeReference wrapped = reference.getWrapperTypeIfPrimitive(); typeParameter.acceptHint(wrapped, BoundTypeArgumentSource.RESOLVED, getOrigin(), getExpectedVariance(), getActualVariance()); LightweightTypeReference typeParameterReference = reference.getOwner().newParameterizedTypeReference(typeParameter.getTypeParameter()); if (validParameterTypes && !typeParameterReference.getRawTypeReference().isAssignableFrom(reference)) { validParameterTypes = false; } } }.processPairedReferences(operationParameterType, closureParameterType);
protected boolean isConflictingDefaultImplementation(AbstractResolvedOperation overriding, AbstractResolvedOperation overridden) { JvmOperation ridingDecl = overriding.getDeclaration(); JvmOperation riddenDecl = overridden.getDeclaration(); if (isInterface(ridingDecl.getDeclaringType()) && isInterface(riddenDecl.getDeclaringType()) && (!ridingDecl.isAbstract() || !riddenDecl.isAbstract())) { LightweightTypeReference ridingTypeRef = overriding.getResolvedDeclarator(); LightweightTypeReference riddenTypeRef = overridden.getResolvedDeclarator(); return !riddenTypeRef.isAssignableFrom(ridingTypeRef); } return false; }
/** * Same as {@link LightweightTypeReference#isSubtypeOf(Class)} but does not accept synonym types as subtypes. */ protected boolean isSubtypeButNotSynonym(LightweightTypeReference expectation, Class<?> clazz) { if (expectation.isType(clazz)) { return true; } ITypeReferenceOwner owner = expectation.getOwner(); JvmType declaredType = owner.getServices().getTypeReferences().findDeclaredType(clazz, owner.getContextResourceSet()); if (declaredType == null) { return false; } LightweightTypeReference superType = owner.newParameterizedTypeReference(declaredType); // don't allow synonyms, e.g. Iterable is not considered to be a supertype of Functions.Function0 boolean result = superType.isAssignableFrom(expectation.getRawTypeReference(), new TypeConformanceComputationArgument(false, false, true, true, false, false)); return result; }