Esempio n. 1
0
    def match_Class(self, c):
        name = c.name.match(self.namer)
        fields = []
        methods = []
        constructor = None
        doc = self.doc(c.annotations)

        if c.base:
            base_class = c.base.match(self.namer)
            fields.append(base_class + ".prototype.__init_fields__.call(this);")
        else:
            base_class = None

        if c.package:
            c.package.readme += "## %s\n" % name
            c.package.readme += self.doc(c.annotations, head="", prefix="", tail="")

        for definition in c.definitions:
            if isinstance(definition, ast.Field):
                field_doc = self.doc(definition.annotations)
                fields.append(field_doc + definition.match(self.fieldr))
            elif not definition.type:
                assert constructor is None
                constructor = definition
            else:
                methods.append(definition.match(self, class_name=name))

        res = "\n// CLASS %s\n" % name + doc
        if constructor:
            res += constructor.match(self, class_name=name)
        else:
            if c.base:
                cons = base_constructors(c)
                params = []
                args = ["this"]
                if cons:
                    assert len(cons) == 1
                    params = [p.match(self) for p in cons[0].params]
                    args.extend([p.name.match(self.namer) for p in cons[0].params])
                res += "function %s(%s) {\n    %s.super_.call(%s);\n}\n" % \
                       (name, ", ".join(params), name, ", ".join(args))
            else:
                res += "function %s() {\n    this.__init_fields__();\n}\n" % name
        res += "exports.%s = %s;\n" % (name, name)
        if base_class:
            res += "_qrt.util.inherits(%s, %s);\n" % (name, base_class)

        res += "\nfunction %s__init_fields__() {" % name + java.indent("\n".join(fields)) + "}\n"
        res += "%s.prototype.__init_fields__ = %s__init_fields__;\n" % (name, name)

        res += "\n".join(methods)

        return res
Esempio n. 2
0
 def match_Block(self, b, header=None):
     header = header or []
     return "{%s}" % java.indent("\n".join(header + [s.match(self) for s in b.statements]))