/** * Allows to refuse a certain type parameter to be substituted. * @param typeParameter the type parameter that should be substituted. * @return <code>false</code> if the parameter may be substituted. <code>true</code> if it should be preserved. */ protected boolean isResolvedTypeParameter(JvmTypeParameter typeParameter) { return isResolvedTypeParameter(getContextType(), typeParameter); }
protected TypeParameterSubstitutor<?> getSubstitutor() { if (getContextType().getType() != getDeclaration().getDeclaringType()) { if (isRawTypeInheritance()) { return new RawTypeSubstitutor(getContextType().getOwner()); } } Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping = getContextTypeParameterMapping(); TypeParameterSubstitutor<?> result = new TypeParameterByConstraintSubstitutor(mapping, getContextType().getOwner()) { @Override protected boolean isDeclaredTypeParameter(JvmTypeParameter typeParameter) { if (super.isDeclaredTypeParameter(typeParameter) || isResolvedTypeParameter(typeParameter) || getTypeParameterMapping().containsKey(typeParameter)) return true; return false; } @Override /* @Nullable */ protected LightweightMergedBoundTypeArgument getBoundTypeArgument(JvmTypeParameter type, ConstraintVisitingInfo info) { LightweightMergedBoundTypeArgument result = super.getBoundTypeArgument(type, info); if (result != null && result.getTypeReference().getType() == type) { return null; } return result; } }; return result; }
@Override public LightweightTypeReference getResolvedDeclarator() { JvmFeature declaration = getDeclaration(); JvmDeclaredType declarator = declaration.getDeclaringType(); return getContextType().getSuperType(declarator); }
protected Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> computeContextTypeParameterMapping() { if (getDeclaration().isStatic() && !(getDeclaration() instanceof JvmConstructor)) { return Collections.emptyMap(); } return new DeclaratorTypeArgumentCollector().getTypeParameterMapping(getContextType()); }
protected boolean isRawTypeInheritance() { List<LightweightTypeReference> superTypes = getContextType().getAllSuperTypes(); JvmDeclaredType declaringType = getDeclaration().getDeclaringType(); for(LightweightTypeReference superType: superTypes) { if (superType.getType() == declaringType && superType.isRawType()) { return true; } } return false; } }
protected LightweightTypeReference getResolvedReference(/* @Nullable */ JvmTypeReference unresolved) { ITypeReferenceOwner owner = getContextType().getOwner(); if (unresolved == null) { return owner.newReferenceToObject(); } LightweightTypeReference unresolvedLightweight = owner.toLightweightTypeReference(unresolved); if (unresolvedLightweight.isPrimitive() || unresolvedLightweight.isPrimitiveVoid()) return unresolvedLightweight; TypeParameterSubstitutor<?> substitutor = getSubstitutor(); LightweightTypeReference result = substitutor.substitute(unresolvedLightweight); return result; }