@SuppressWarnings("deprecation")
private void setTypeParameters(Scope scope, List<TypeParameter> params, List<TypeParameterMirror> typeParameters, boolean isCeylon) {
// We must first add every type param, before we resolve the bounds, which can
// refer to type params.
for(TypeParameterMirror typeParam : typeParameters){
TypeParameter param = new TypeParameter();
param.setUnit(((Element)scope).getUnit());
param.setContainer(scope);
param.setScope(scope);
DeclarationVisitor.setVisibleScope(param);
param.setDeclaration((Declaration) scope);
// let's not trigger the lazy-loading if we're completing a LazyClass/LazyInterface
if(scope instanceof LazyContainer)
((LazyContainer)scope).addMember(param);
else // must be a method
scope.getMembers().add(param);
param.setName(typeParam.getName());
param.setExtendedType(typeFactory.getAnythingDeclaration().getType());
params.add(param);
}
boolean needsObjectBounds = !isCeylon && scope instanceof Method;
// Now all type params have been set, we can resolve the references parts
Iterator<TypeParameter> paramsIterator = params.iterator();
for(TypeParameterMirror typeParam : typeParameters){
TypeParameter param = paramsIterator.next();
List<TypeMirror> bounds = typeParam.getBounds();
for(TypeMirror bound : bounds){
ProducedType boundType;
// we turn java's default upper bound java.lang.Object into ceylon.language.Object
if(sameType(bound, OBJECT_TYPE)){
// avoid adding java's default upper bound if it's just there with no meaning,
// especially since we do not want it for types
if(bounds.size() == 1)
break;
boundType = getNonPrimitiveType(getLanguageModule(), CEYLON_OBJECT_TYPE, scope, VarianceLocation.INVARIANT);
}else
boundType = getNonPrimitiveType(Decl.getModuleContainer(scope), bound, scope, VarianceLocation.INVARIANT);
param.getSatisfiedTypes().add(boundType);
}
if(needsObjectBounds && param.getSatisfiedTypes().isEmpty()){
ProducedType boundType = getNonPrimitiveType(getLanguageModule(), CEYLON_OBJECT_TYPE, scope, VarianceLocation.INVARIANT);
param.getSatisfiedTypes().add(boundType);
}
}
}