use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class ClassTransformer method addAtMembers.
private void addAtMembers(ClassDefinitionBuilder classBuilder, ClassOrInterface model, Tree.ClassOrInterface def) {
List<JCExpression> members = List.nil();
for (Declaration member : model.getMembers()) {
if (member instanceof ClassOrInterface == false && member instanceof TypeAlias == false) {
continue;
}
TypeDeclaration innerType = (TypeDeclaration) member;
Tree.Declaration innerTypeTree = findInnerType(def, innerType.getName());
if (innerTypeTree != null) {
TransformationPlan plan = errors().hasDeclarationAndMarkBrokenness(innerTypeTree);
if (plan instanceof Drop) {
continue;
}
}
if (innerType.isAlias() && innerTypeTree != null && Decl.isAncestorLocal(innerTypeTree))
// for the same reason we do not generate aliases in transform(ClassOrInterface def) let's not list them
continue;
JCAnnotation atMember;
// interfaces are moved to toplevel so they can lose visibility of member types if they are local
if (Decl.isLocal(model) && model instanceof Interface)
atMember = makeAtMember(innerType.getName());
else
atMember = makeAtMember(innerType.getType());
members = members.prepend(atMember);
}
classBuilder.annotations(makeAtMembers(members));
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class ClassTransformer method transformClassAlias.
private void transformClassAlias(final Tree.ClassDeclaration def, ClassDefinitionBuilder classBuilder) {
ClassAlias model = (ClassAlias) def.getDeclarationModel();
Type aliasedClass = model.getExtendedType();
TypeDeclaration classOrCtor = def.getClassSpecifier().getType().getDeclarationModel();
while (classOrCtor instanceof ClassAlias) {
classOrCtor = ((ClassAlias) classOrCtor).getConstructor();
}
classBuilder.annotations(makeAtAlias(aliasedClass, classOrCtor instanceof Constructor ? (Constructor) classOrCtor : null));
classBuilder.isAlias(true);
MethodDefinitionBuilder instantiator = transformClassAliasInstantiator(def, model, aliasedClass);
ClassDefinitionBuilder cbInstantiator = null;
switch(Strategy.defaultParameterMethodOwner(model)) {
case STATIC:
cbInstantiator = classBuilder;
break;
case OUTER:
cbInstantiator = classBuilder.getContainingClassBuilder();
break;
case OUTER_COMPANION:
cbInstantiator = classBuilder.getContainingClassBuilder().getCompanionBuilder(Decl.getClassOrInterfaceContainer(model, true));
break;
default:
throw BugException.unhandledEnumCase(Strategy.defaultParameterMethodOwner(model));
}
cbInstantiator.method(instantiator);
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class ClassTransformer method addAtContainer.
private void addAtContainer(ClassDefinitionBuilder classBuilder, TypeDeclaration model) {
Scope scope = Decl.getNonSkippedContainer((Scope) model);
Scope declarationScope = Decl.getFirstDeclarationContainer((Scope) model);
boolean inlineObjectInToplevelAttr = Decl.isTopLevelObjectExpressionType(model);
if (scope == null || (scope instanceof Package && !inlineObjectInToplevelAttr) && scope == declarationScope)
return;
if (scope instanceof ClassOrInterface && scope == declarationScope && !inlineObjectInToplevelAttr && // we do not check for types inside initialiser section which are private and not captured because we treat them as members
!(model instanceof Interface && Decl.hasLocalNotInitializerAncestor(model))) {
ClassOrInterface container = (ClassOrInterface) scope;
List<JCAnnotation> atContainer = makeAtContainer(container.getType());
classBuilder.annotations(atContainer);
} else {
if (model instanceof Interface)
classBuilder.annotations(makeLocalContainerPath((Interface) model));
Declaration declarationContainer = getDeclarationContainer(model);
classBuilder.annotations(makeAtLocalDeclaration(model.getQualifier(), declarationContainer == null));
}
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class CeylonVisitor method visit.
// FIXME: also support Tree.SequencedTypeParameter
public void visit(Tree.TypeParameterDeclaration param) {
TypeDeclaration container = (TypeDeclaration) param.getDeclarationModel().getContainer();
classBuilder.typeParameter(param);
ClassDefinitionBuilder companionBuilder = classBuilder.getCompanionBuilder(container);
if (companionBuilder != null)
companionBuilder.typeParameter(param);
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class ClassTransformer method getFirstSatisfiedType.
private Type getFirstSatisfiedType(Type currentType, Interface iface) {
Type found = null;
TypeDeclaration currentDecl = currentType.getDeclaration();
if (Decl.equal(currentDecl, iface)) {
return currentType;
}
if (currentType.getExtendedType() != null) {
Type supertype = currentType.getSupertype(currentType.getExtendedType().getDeclaration());
found = getFirstSatisfiedType(supertype, iface);
if (found != null)
return found;
}
for (Type superInterfaceType : currentType.getSatisfiedTypes()) {
found = getFirstSatisfiedType(superInterfaceType, iface);
if (found != null)
return found;
}
return null;
}
Aggregations