use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class AbstractTransformer method makeParameterisedType.
public JCExpression makeParameterisedType(Type type, Type generalType, final int flags, JCExpression qualifyingExpression, java.util.List<Reference> qualifyingTypes, int firstQualifyingTypeWithTypeParameters, int index) {
JCExpression baseType;
TypeDeclaration tdecl = type.getDeclaration();
ListBuffer<JCExpression> typeArgs = null;
if (index >= firstQualifyingTypeWithTypeParameters) {
int taFlags = flags;
if (qualifyingTypes != null && index < qualifyingTypes.size() - 1) {
// The qualifying types before the main one should
// have type parameters with proper variance
taFlags &= ~(JT_EXTENDS | JT_SATISFIES);
}
typeArgs = makeTypeArgs(type, taFlags);
}
if (isCeylonCallable(generalType) && (flags & JT_CLASS_NEW) != 0) {
baseType = makeIdent(syms().ceylonAbstractCallableType);
} else if (index == 0) {
// qualified type is static
if (tdecl instanceof Interface && qualifyingTypes != null && qualifyingTypes.size() > 1 && firstQualifyingTypeWithTypeParameters == 0 && (flags & JT_NON_QUALIFIED) == 0) {
baseType = naming.makeCompanionClassName(tdecl);
} else {
baseType = naming.makeDeclarationName(tdecl, jtFlagsToDeclNameOpts(flags));
}
} else {
baseType = naming.makeTypeDeclarationExpression(qualifyingExpression, tdecl, jtFlagsToDeclNameOpts(flags | JT_NON_QUALIFIED | (type.getDeclaration() instanceof Interface ? JT_COMPANION : 0)));
}
if (typeArgs != null && typeArgs.size() > 0) {
qualifyingExpression = make().TypeApply(baseType, typeArgs.toList());
} else {
qualifyingExpression = baseType;
}
return qualifyingExpression;
}
use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class AbstractTransformer method declarationAppearsInInvariantPosition.
private boolean declarationAppearsInInvariantPosition(TypeDeclaration declaration, Type type) {
if (type.isUnion()) {
for (Type pt : type.getCaseTypes()) {
if (declarationAppearsInInvariantPosition(declaration, pt))
return true;
}
return false;
}
if (type.isIntersection()) {
for (Type pt : type.getSatisfiedTypes()) {
if (declarationAppearsInInvariantPosition(declaration, pt))
return true;
}
return false;
}
if (type.isClassOrInterface()) {
TypeDeclaration typeDeclaration = type.getDeclaration();
java.util.List<TypeParameter> typeParameters = typeDeclaration.getTypeParameters();
Map<TypeParameter, Type> typeArguments = type.getTypeArguments();
for (TypeParameter tp : typeParameters) {
Type typeArgument = typeArguments.get(tp);
if (tp.isInvariant() || hasDependentTypeParameters(typeParameters, tp)) {
if (Decl.equal(typeArgument.getDeclaration(), declaration)) {
return true;
}
}
if (declarationAppearsInInvariantPosition(declaration, typeArgument))
return true;
}
}
return false;
}
use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class AbstractTransformer method getTypedReference.
TypedReference getTypedReference(TypedDeclaration decl) {
java.util.List<Type> typeArgs = Collections.<Type>emptyList();
if (decl instanceof Function) {
// For methods create type arguments for any type parameters it might have
Function m = (Function) decl;
if (!m.getTypeParameters().isEmpty()) {
typeArgs = new ArrayList<Type>(m.getTypeParameters().size());
for (TypeParameter p : m.getTypeParameters()) {
Type pt = p.getType();
typeArgs.add(pt);
}
}
}
if (decl.getContainer() instanceof TypeDeclaration) {
TypeDeclaration containerDecl = (TypeDeclaration) decl.getContainer();
return containerDecl.getType().getTypedMember(decl, typeArgs);
}
return decl.appliedTypedReference(null, typeArgs);
}
use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class AbstractTransformer method canUseFastFailTypeTest.
private boolean canUseFastFailTypeTest(Type type) {
if (type.getDeclaration() instanceof ClassOrInterface == false)
return false;
boolean isRaw = type.getDeclaration().isParameterized();
Type qualifyingType = type.getQualifyingType();
if (qualifyingType == null && // ignore qualifying types of static java declarations
(ModelUtil.isCeylonDeclaration(type.getDeclaration()) || !type.getDeclaration().isStatic())) {
Declaration declaration = type.getDeclaration();
boolean local = false;
do {
// getDeclarationContainer will skip some containers we don't want to consider, so it's not good
// for checking locality, rely on isLocal for that.
local |= Decl.isLocal(declaration);
// it may be contained in a function or value, and we want its type
Declaration enclosingDeclaration = getDeclarationContainer(declaration);
if (enclosingDeclaration instanceof TypedDeclaration) {
local = true;
// look up the containers
declaration = enclosingDeclaration;
} else if (enclosingDeclaration instanceof TypeDeclaration) {
// contain type parameters, unless the local is raw
if (enclosingDeclaration.isParameterized() && local && !isRaw)
return false;
// look up the containers
declaration = enclosingDeclaration;
} else {
// that's fucked up
break;
}
// go up every containing typed declaration
} while (declaration != null);
// we can fast-fail!
return true;
} else if (qualifyingType != null) {
// we can only fast-fail if the qualifying type can also be fast-failed
return canUseFastFailTypeTest(qualifyingType);
} else {
// we can fast-fail!
return true;
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration 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;
}
Aggregations