use of com.redhat.ceylon.model.typechecker.model.Type in project ceylon-compiler by ceylon.
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;
}
use of com.redhat.ceylon.model.typechecker.model.Type in project ceylon-compiler by ceylon.
the class Util method getSuperInterfaces.
public static List<TypeDeclaration> getSuperInterfaces(TypeDeclaration decl) {
Set<TypeDeclaration> superInterfaces = new HashSet<TypeDeclaration>();
for (Type satisfiedType : decl.getSatisfiedTypes()) {
superInterfaces.add(satisfiedType.getDeclaration());
superInterfaces.addAll(getSuperInterfaces(satisfiedType.getDeclaration()));
}
List<TypeDeclaration> list = new ArrayList<TypeDeclaration>();
list.addAll(superInterfaces);
removeDuplicates(list);
return list;
}
use of com.redhat.ceylon.model.typechecker.model.Type in project ceylon-compiler by ceylon.
the class AbstractTransformer method collectRefinedMembers.
private void collectRefinedMembers(Type currentType, String name, java.util.List<Type> signature, boolean ellipsis, java.util.Set<TypeDeclaration> visited, Set<TypedDeclaration> ret, boolean ignoreFirst) {
TypeDeclaration decl = currentType.getDeclaration();
if (visited.contains(decl)) {
return;
} else {
visited.add(decl);
Type et = currentType.getExtendedType();
if (et != null) {
collectRefinedMembers(et, name, signature, ellipsis, visited, ret, false);
}
for (Type st : currentType.getSatisfiedTypes()) {
collectRefinedMembers(st, name, signature, ellipsis, visited, ret, false);
}
// we're collecting refined members, not the refining one
if (!ignoreFirst) {
TypedDeclaration found = (TypedDeclaration) decl.getDirectMember(name, signature, ellipsis);
if (found instanceof Function) {
// do not trust getDirectMember because if you ask it for [Integer,String] and it has [Integer,E] it does not
// know that E=String and will not make it match, and will just return any member when there is overloading,
// including one with signature [String] when you asked for [Integer,String]
java.util.List<Type> typedSignature = getTypedSignature(currentType, found);
if (typedSignature != null && hasMatchingSignature(signature, typedSignature))
ret.add(found);
}
}
}
}
use of com.redhat.ceylon.model.typechecker.model.Type in project ceylon-compiler by ceylon.
the class AbstractTransformer method makeJavaTypeAnnotations.
List<JCTree.JCAnnotation> makeJavaTypeAnnotations(TypedDeclaration decl, boolean handleFunctionalParameter) {
if (decl == null || decl.getType() == null)
return List.nil();
Type type;
if (decl instanceof Function && ((Function) decl).isParameter() && handleFunctionalParameter) {
type = getTypeForFunctionalParameter((Function) decl);
} else if (decl instanceof Functional && Decl.isMpl((Functional) decl)) {
type = getReturnTypeOfCallable(decl.appliedTypedReference(null, Collections.<Type>emptyList()).getFullType());
} else {
type = decl.getType();
}
boolean declaredVoid = decl instanceof Function && Strategy.useBoxedVoid((Function) decl) && Decl.isUnboxedVoid(decl);
return makeJavaTypeAnnotations(type, declaredVoid, CodegenUtil.hasTypeErased(decl), CodegenUtil.hasUntrustedType(decl), needsJavaTypeAnnotations(decl));
}
use of com.redhat.ceylon.model.typechecker.model.Type in project ceylon-compiler by ceylon.
the class AbstractTransformer method makeJavaType.
/**
* This function is used solely for method return types and parameters
*/
JCExpression makeJavaType(TypedDeclaration typeDecl, Type type, int flags) {
if (typeDecl instanceof Function && ((Function) typeDecl).isParameter()) {
Function p = (Function) typeDecl;
Type pt = type;
for (int ii = 1; ii < p.getParameterLists().size(); ii++) {
pt = typeFact().getCallableType(pt);
}
return makeJavaType(typeFact().getCallableType(pt), flags);
} else {
boolean usePrimitives = CodegenUtil.isUnBoxed(typeDecl);
return makeJavaType(type, flags | (usePrimitives ? 0 : AbstractTransformer.JT_NO_PRIMITIVES));
}
}
Aggregations