private ClassTransformer(Context context) {
super(context);
}
public List<JCTree> transform(final Tree.ClassOrInterface def) {
final ClassOrInterface model = def.getDeclarationModel();
// we only create types for aliases so they can be imported with the model loader
// and since we can't import local declarations let's just not create those types
// in that case
if(model.isAlias()
&& Decl.isAncestorLocal(def))
return List.nil();
naming.clearSubstitutions(model);
final String javaClassName;
String ceylonClassName = def.getIdentifier().getText();
if (def instanceof Tree.AnyInterface) {
javaClassName = naming.makeTypeDeclarationName(model, QUALIFIED).replaceFirst(".*\\.", "");
} else {
javaClassName = Naming.quoteClassName(def.getIdentifier().getText());
}
ClassDefinitionBuilder instantiatorImplCb;
ClassDefinitionBuilder instantiatorDeclCb;
if (Decl.withinInterface(model)) {
instantiatorImplCb = gen().current().getCompanionBuilder((Interface)model.getContainer());
instantiatorDeclCb = gen().current();
} else {
instantiatorImplCb = gen().current();
instantiatorDeclCb = null;
}
ClassDefinitionBuilder classBuilder = ClassDefinitionBuilder
.klass(this, javaClassName, ceylonClassName, Decl.isLocal(model))
.forDefinition(model);
TypeParameterList typeParameterList = def.getTypeParameterList();
// Very special case for Anything
if ("ceylon.language::Anything".equals(model.getQualifiedNameString())) {
classBuilder.extending(model.getType(), null);
}
if (def instanceof Tree.AnyClass) {
Tree.ParameterList paramList = ((Tree.AnyClass)def).getParameterList();
Class cls = ((Tree.AnyClass)def).getDeclarationModel();
// Member classes need a instantiator method
boolean generateInstantiator = Strategy.generateInstantiator(cls);
if(generateInstantiator){
generateInstantiators(cls, classBuilder, paramList, cls, instantiatorDeclCb, instantiatorImplCb, typeParameterList);
}
classBuilder.annotations(expressionGen().transform(def.getAnnotationList()));
if(def instanceof Tree.ClassDefinition){
transformClass((Tree.ClassDefinition)def, (Class)model, classBuilder, paramList, generateInstantiator, cls, instantiatorDeclCb, instantiatorImplCb, typeParameterList);
}else{
// class alias
classBuilder.constructorModifiers(PRIVATE);
transformClassAlias((Tree.AnyClass)def, classBuilder);
}
addMissingUnrefinedMembers(def, cls, classBuilder);
}
if (def instanceof Tree.AnyInterface) {
classBuilder.annotations(expressionGen().transform(def.getAnnotationList()));
if(def instanceof Tree.InterfaceDefinition){
transformInterface(def, (Interface)model, classBuilder, typeParameterList);
}else{
// interface alias
classBuilder.annotations(makeAtAlias(model.getExtendedType()));
classBuilder.isAlias(true);
}
classBuilder.isDynamic(model.isDynamic());
}
// make sure we set the container in case we move it out
addAtContainer(classBuilder, model);
// Transform the class/interface members
List<JCStatement> childDefs = visitClassOrInterfaceDefinition(def, classBuilder);
// If it's a Class without initializer parameters...
if (Strategy.generateMain(def)) {
// ... then add a main() method
classBuilder.method(makeMainForClass(model));
}
classBuilder
.modelAnnotations(model.getAnnotations())
.modifiers(transformClassDeclFlags(def))
.satisfies(model.getSatisfiedTypes())
.caseTypes(model.getCaseTypes(), model.getSelfType())
.init(childDefs);
// aliases don't need a $getType method
if(!model.isAlias()){
// only classes get a $getType method
if(model instanceof Class)
classBuilder.addGetTypeMethod(model.getType());
if(supportsReifiedAlias(model))
classBuilder.reifiedAlias(model.getType());
}
List<JCTree> result;
if (Decl.isAnnotationClass(def)) {
ListBuffer<JCTree> trees = ListBuffer.lb();