use of com.redhat.ceylon.model.typechecker.model.ClassOrInterface in project ceylon-compiler by ceylon.
the class ExpressionTransformer method lostTypeParameterInInheritance.
private boolean lostTypeParameterInInheritance(Type exprType, Type commonType) {
if (exprType.getDeclaration() instanceof ClassOrInterface == false || commonType.getDeclaration() instanceof ClassOrInterface == false)
return false;
ClassOrInterface exprDecl = (ClassOrInterface) exprType.getDeclaration();
ClassOrInterface commonDecl = (ClassOrInterface) commonType.getDeclaration();
// do not search interfaces if the common declaration is a class, because interfaces cannot be subtypes of a class
boolean searchInterfaces = commonDecl instanceof Interface;
return lostTypeParameterInInheritance(exprDecl, commonDecl, searchInterfaces, false);
}
use of com.redhat.ceylon.model.typechecker.model.ClassOrInterface in project ceylon-compiler by ceylon.
the class ExpressionTransformer method addThisOrObjectQualifierIfRequired.
/**
* We may need to force a qualified this prefix (direct or outer) in the following cases:
*
* - Required because of mixin inheritance with different type arguments (the same is already
* done for qualified references, but not for direct references)
* - The compiler generates anonymous local classes for things like
* Callables and Comprehensions. When referring to a member foo
* within one of those things we need a qualified {@code this}
* to ensure we're accessing the outer instances member, not
* a member of the anonymous local class that happens to have the same name.
*/
private JCExpression addThisOrObjectQualifierIfRequired(JCExpression qualExpr, Tree.StaticMemberOrTypeExpression expr, Declaration decl) {
if (qualExpr == null && // statics are not members that can be inherited
!decl.isStaticallyImportable() && !Decl.isConstructor(decl) && decl.isMember() && // and have a name mapping)
expr.getTarget().getDeclaration() == decl && !Decl.isLocalToInitializer(decl) && !isWithinSuperInvocation()) {
// First check whether the expression is captured from an enclosing scope
TypeDeclaration outer = null;
// get the ClassOrInterface container of the declaration
Scope stop = Decl.getClassOrInterfaceContainer(decl, false);
if (stop instanceof TypeDeclaration) {
// reified scope
Scope scope = expr.getScope();
while (!(scope instanceof Package)) {
if (scope.equals(stop)) {
outer = (TypeDeclaration) stop;
break;
}
scope = scope.getContainer();
}
}
// If not it might be inherited...
if (outer == null) {
outer = expr.getScope().getInheritingDeclaration(decl);
}
if (outer != null) {
Type targetType = expr.getTarget().getQualifyingType();
Type declarationContainerType = ((TypeDeclaration) outer).getType();
// check if we need a variance cast
VarianceCastResult varianceCastResult = getVarianceCastResult(targetType, declarationContainerType);
// if we are within a comprehension body, or if we need a variance cast
if (isWithinSyntheticClassBody() || varianceCastResult != null) {
if (decl.isShared() && outer instanceof Interface) {
// always prefer qualified
qualExpr = makeQualifiedDollarThis(declarationContainerType);
} else {
// Class or companion class,
qualExpr = naming.makeQualifiedThis(makeJavaType(((TypeDeclaration) outer).getType(), JT_RAW | (outer instanceof Interface ? JT_COMPANION : 0)));
}
// add the variance cast if required
if (varianceCastResult != null) {
qualExpr = applyVarianceCasts(qualExpr, targetType, varianceCastResult, 0);
}
}
} else if (decl.isClassMember() && ((Class) decl.getContainer()).isAnonymous() && ((Class) decl.getContainer()).isToplevel()) {
Class container = (Class) decl.getContainer();
Value value = (Value) ((Package) container.getContainer()).getMember(container.getName(), null, false);
qualExpr = make().Apply(null, naming.makeName(value, Naming.NA_FQ | Naming.NA_WRAPPER | Naming.NA_MEMBER), List.<JCExpression>nil());
} else if (decl.isMember() && !expr.getStaticMethodReference()) {
throw new BugException(expr, decl.getQualifiedNameString() + " was unexpectedly a member");
}
}
return qualExpr;
}
Aggregations