use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class AbstractTransformer method makeRawType.
protected JCExpression makeRawType(final int flags, Type type, Type simpleType) {
JCExpression jt;
TypeDeclaration tdecl = simpleType.getDeclaration();
// - The Ceylon type T results in the Java type T
if (isCeylonCallable(type) && (flags & JT_CLASS_NEW) != 0) {
jt = makeIdent(syms().ceylonAbstractCallableType);
} else if (tdecl instanceof TypeParameter)
jt = makeQuotedIdent(tdecl.getName());
else // don't use underlying type if we want no primitives
if ((flags & (JT_SATISFIES | JT_NO_PRIMITIVES)) != 0 || simpleType.getUnderlyingType() == null) {
jt = naming.makeDeclarationName(tdecl, jtFlagsToDeclNameOpts(flags));
} else
jt = makeQuotedFQIdent(simpleType.getUnderlyingType());
return jt;
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class AbstractTransformer method collectQualifyingTypeArguments.
/**
* Collects all the type parameters and arguments required for an interface that's been pulled up to the
* toplevel, including its containing type and method type parameters.
*/
private void collectQualifyingTypeArguments(java.util.List<TypeParameter> qualifyingTypeParameters, Map<TypeParameter, Type> qualifyingTypeArguments, java.util.List<Reference> qualifyingTypes) {
// make sure we only add type parameters with the same name once, as duplicates are erased from the target interface
// since they cannot be accessed
Set<String> names = new HashSet<String>();
// walk the qualifying types backwards to make sure we only add a TP with the same name once and the outer one wins
for (int i = qualifyingTypes.size() - 1; i >= 0; i--) {
Reference qualifiedType = qualifyingTypes.get(i);
Map<TypeParameter, Type> tas = qualifiedType.getTypeArguments();
java.util.List<TypeParameter> tps = qualifiedType.getDeclaration().getTypeParameters();
// add any type params for this type
if (tps != null) {
int index = 0;
for (TypeParameter tp : tps) {
// add it only once
if (names.add(tp.getName())) {
// start putting all these type parameters at 0 and then in order
// so that outer type params end up before inner type params but
// order is preserved within each type
qualifyingTypeParameters.add(index++, tp);
qualifyingTypeArguments.put(tp, tas.get(tp));
}
}
}
// add any container method TP
Declaration declaration = qualifiedType.getDeclaration();
if (Decl.isLocal(declaration)) {
Scope scope = declaration.getContainer();
// collect every container method until the next type or package
java.util.List<Function> methods = new LinkedList<Function>();
while (scope != null && scope instanceof ClassOrInterface == false && scope instanceof Package == false) {
if (scope instanceof Function) {
methods.add((Function) scope);
}
scope = scope.getContainer();
}
// methods are sorted inner to outer, which is the order we're following here for types
for (Function method : methods) {
java.util.List<TypeParameter> methodTypeParameters = method.getTypeParameters();
if (methodTypeParameters != null) {
int index = 0;
for (TypeParameter tp : methodTypeParameters) {
// add it only once
if (names.add(tp.getName())) {
// start putting all these type parameters at 0 and then in order
// so that outer type params end up before inner type params but
// order is preserved within each type
qualifyingTypeParameters.add(index++, tp);
qualifyingTypeArguments.put(tp, tp.getType());
}
}
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class AbstractTransformer method hasSubstitutedBounds.
boolean hasSubstitutedBounds(Type pt) {
TypeDeclaration declaration = pt.getDeclaration();
java.util.List<TypeParameter> tps = declaration.getTypeParameters();
final Map<TypeParameter, Type> tas = pt.getTypeArguments();
boolean isCallable = isCeylonCallable(pt);
for (TypeParameter tp : tps) {
Type ta = tas.get(tp);
// error recovery
if (ta == null)
continue;
if (!tp.getSatisfiedTypes().isEmpty()) {
for (Type bound : tp.getSatisfiedTypes()) {
bound = bound.substitute(pt);
if (expressionGen().needsCast(ta, bound, false, false, false))
return true;
}
}
if (hasSubstitutedBounds(ta))
return true;
// Callable ignores type parameters after the first
if (isCallable)
break;
}
return false;
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class AbstractTransformer method getTypeArguments.
private java.util.List<Type> getTypeArguments(Function method) {
java.util.List<TypeParameter> typeParameters = method.getTypeParameters();
java.util.List<Type> typeArguments = new ArrayList<Type>(typeParameters.size());
for (TypeParameter tp : typeParameters) typeArguments.add(tp.getType());
return typeArguments;
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class AbstractTransformer method isWideningTypeDecl.
public boolean isWideningTypeDecl(TypedReference typedReference, Type currentType) {
TypedReference refinedTypedReference = getRefinedDeclaration(typedReference, currentType);
if (refinedTypedReference == null)
return false;
/*
* We are widening if the type:
* - is not object
* - is erased to object
* - refines a declaration that is not erased to object
*/
Type declType = typedReference.getType();
Type refinedDeclType = refinedTypedReference.getType();
if (declType == null || refinedDeclType == null)
return false;
if (isWidening(declType, refinedDeclType))
return true;
// make sure we get the instantiated refined decl
if (refinedDeclType.getDeclaration() instanceof TypeParameter && !(declType.getDeclaration() instanceof TypeParameter))
refinedDeclType = nonWideningType(typedReference, refinedTypedReference);
if (isWideningTypeArguments(declType, refinedDeclType, true))
return true;
if (CodegenUtil.hasTypeErased(refinedTypedReference.getDeclaration()) && !willEraseToObject(declType))
return true;
return false;
}
Aggregations