Example #1
0
    def run(self):
        src_name = self.module_name.split('.')[-1]
        self.class_name = util.to_class_name(src_name)

        name_format = util.to_utf8(self.generator_info.get("name_format"))
        if name_format:
            self.class_name = name_format % self.class_name

        self.file_path = os.path.join(self.output_path,
                                      self.class_name + ".java")

        path = os.path.dirname(self.file_path)
        util.safe_makedirs(path)

        self.write_line(0, "// 此文件由导表工具自动生成,禁止手动修改。")
        self.write_line()

        package = util.to_utf8(
            self.generator_info.get("package", xlsconfig.DEFAULT_JAVA_PACKAGE))

        self.write_line(0, "package %s;" % package)
        self.write_line()

        imports = self.generator_info.get("imports")
        if imports:
            for imp in imports:
                self.write_line(0, "import %s;" % imp.encode("utf-8"))
            self.write_line()

        items = self.collect_members(self.module)

        self.gen_class(items, 0)

        self.save_to_file(self.file_path)
Example #2
0
    def gen_get_set(self, items, indent):
        for item in items:
            name, comment, type, _ = item

            java_name = util.to_class_name(name)

            self.write_line(indent, "public %s get%s() {" % (type, java_name))
            self.write_line(indent + 1, "return %s;" % name)
            self.write_line(indent, "}")

            self.write_line(
                indent, "public void set%s(%s %s) {" % (java_name, type, name))
            self.write_line(indent + 1, "this.%s = %s;" % (name, name))
            self.write_line(indent, "}")

            self.write_line()

        self.write_line()
    def run(self):
        file_path = util.resolve_path(self.generator_info["file_path"])
        util.ensure_folder_exist(file_path)
        print "生成文件列表", file_path

        only_name = os.path.splitext(os.path.basename(file_path))[0]

        wt = JsonWriter(file_path, None)
        wt.begin_write()

        package = to_utf8(
            self.generator_info.get("package", xlsconfig.DEFAULT_JAVA_PACKAGE))
        wt.write_value("package", to_utf8(package))

        class_name_format = to_utf8(
            self.generator_info.get("class_name_format"))
        enum_name_format = to_utf8(self.generator_info.get("enum_name_format"))

        keys = self.exporter.data_modules.keys()
        keys.sort()

        ret = []
        for key in keys:
            data_module = self.exporter.data_modules[key]
            converter_name = data_module.info["parser"]

            file_name = os.path.splitext(key)[0]

            enum_name = file_name.replace('\\', '_').replace('/', '_').upper()
            if enum_name_format: enum_name = enum_name_format % enum_name

            fpath, fname = os.path.split(file_name)
            file_name = os.path.join(only_name, fpath, "%s.wg" % fname)
            file_name = format_slash(file_name)

            class_name = to_class_name(converter_name.split('.')[-1])
            if class_name_format: class_name = class_name_format % class_name

            ret.append([enum_name, file_name, class_name])

        wt.write_value(only_name, ret)

        wt.end_write()
        wt.close()
	def begin_write(self):
		super(JavaWriter, self).begin_write()

		module_info = self.data_module.info
		parser_name = module_info["parser"].split('.')[-1]
		class_name = util.to_class_name(parser_name)
		self.write_value("class", class_name)

		self.is_multi_key = module_info["multi_key"]
		self.write_value("multiKey", self.is_multi_key)

		sheet_types = module_info["sheet_types"]["main_sheet"]

		fields = sheet_types.keys()
		fields.sort()
		self.fields = fields

		texts = [sheet_types[field][2] for field in fields]
		headers = [texts, fields, ]
		self.write_value("header", headers, 2)
Example #5
0
    def run(self):
        src_name = self.module_name.split('.')[-1]
        self.class_name = util.to_class_name(src_name)

        generator_info = self.generator_info
        name_format = util.to_utf8(generator_info.get("name_format"))
        if name_format:
            self.class_name = name_format % self.class_name

        ns = {
            "FILE_PATH": self.class_name,
        }
        self.file_path = util.resolve_path(generator_info["file_path"], (
            ns,
            xlsconfig,
        ))
        util.ensure_folder_exist(self.file_path)

        self.write_line(0, "// 此文件由导表工具自动生成,禁止手动修改。")
        self.write_line()

        package = util.to_utf8(
            generator_info.get("package", xlsconfig.DEFAULT_JAVA_PACKAGE))

        self.write_line(0, "package %s;" % package)
        self.write_line()

        imports = generator_info.get("imports")
        if imports:
            for imp in imports:
                self.write_line(0, "import %s;" % imp.encode("utf-8"))
            self.write_line()

        items = self.collect_members(self.module)

        self.gen_class(items, 0)

        self.save_to_file(self.file_path)