use of org.eclipse.ceylon.compiler.js.GenerateJsVisitor.PrototypeInitCallback in project ceylon by eclipse.
the class TypeGenerator method initializeType.
/**
* Generates a function to initialize the specified type.
* @param initDeferrer
*/
static void initializeType(final Node type, final GenerateJsVisitor gen, InitDeferrer initDeferrer) {
Tree.ExtendedType extendedType = null;
Tree.SatisfiedTypes satisfiedTypes = null;
final ClassOrInterface decl;
final List<Tree.Statement> stmts;
Value objDecl = null;
if (type instanceof Tree.ClassDefinition) {
Tree.ClassDefinition classDef = (Tree.ClassDefinition) type;
extendedType = classDef.getExtendedType();
satisfiedTypes = classDef.getSatisfiedTypes();
decl = classDef.getDeclarationModel();
Tree.Declaration nh = gen.getNativeHeader(decl);
if (nh == null && NativeUtil.hasNativeMembers(decl)) {
nh = classDef;
}
stmts = NativeUtil.mergeStatements(classDef.getClassBody(), nh, Backend.JavaScript);
} else if (type instanceof Tree.InterfaceDefinition) {
satisfiedTypes = ((Tree.InterfaceDefinition) type).getSatisfiedTypes();
decl = ((Tree.InterfaceDefinition) type).getDeclarationModel();
final Tree.InterfaceDefinition idef = (Tree.InterfaceDefinition) type;
Tree.Declaration nh = gen.getNativeHeader(decl);
if (nh == null && NativeUtil.hasNativeMembers(decl)) {
nh = idef;
}
stmts = NativeUtil.mergeStatements(idef.getInterfaceBody(), nh, Backend.JavaScript);
} else if (type instanceof Tree.ObjectDefinition) {
Tree.ObjectDefinition objectDef = (Tree.ObjectDefinition) type;
extendedType = objectDef.getExtendedType();
satisfiedTypes = objectDef.getSatisfiedTypes();
decl = (ClassOrInterface) objectDef.getDeclarationModel().getTypeDeclaration();
objDecl = objectDef.getDeclarationModel();
Tree.Declaration nh = gen.getNativeHeader(decl);
if (nh == null && NativeUtil.hasNativeMembers(decl)) {
nh = objectDef;
}
stmts = NativeUtil.mergeStatements(objectDef.getClassBody(), nh, Backend.JavaScript);
} else if (type instanceof Tree.ObjectExpression) {
Tree.ObjectExpression objectDef = (Tree.ObjectExpression) type;
extendedType = objectDef.getExtendedType();
satisfiedTypes = objectDef.getSatisfiedTypes();
decl = (ClassOrInterface) objectDef.getAnonymousClass();
stmts = objectDef.getClassBody().getStatements();
} else if (type instanceof Tree.Enumerated) {
Tree.Enumerated vc = (Tree.Enumerated) type;
stmts = vc.getBlock().getStatements();
decl = (ClassOrInterface) vc.getDeclarationModel().getTypeDeclaration().getContainer();
} else {
stmts = null;
decl = null;
}
final PrototypeInitCallback callback = new PrototypeInitCallback() {
@Override
public void addToPrototypeCallback() {
if (decl != null) {
gen.addToPrototype(type, decl, stmts);
}
}
};
typeInitialization(extendedType, satisfiedTypes, decl, callback, gen, objDecl, initDeferrer);
}
Aggregations