code-generation

Serialize a Java object to Java code?

大憨熊 提交于 2019-12-12 07:14:45
问题 Is there an implementation that will serialize a Java object as Java code? For example, if I have the object Map<String,Integer> m = new Map<String,Integer>(); m.put("foo",new Integer(21)); I could serialize this using ObjectOutputStream out = new ObjectOutputStream( ... ); out.writeObject( m ); out.flush(); and the output would, for example, be java.util.Map<String,Integer> m = new java.util.Map<String,Integer>(); m.put("foo",new Integer(21)); Why would you want this? Sometimes it is easier

Generate xml from csv data in conformance with given xsd schema

六眼飞鱼酱① 提交于 2019-12-12 06:36:40
问题 I have an xml schema and csv data to generate corresponding xml files. I found this , how to generate xml files from given CSV file. But with my schema, it's always the same mapping because of the element. So the last 5 columns are mapped according to the DataType column. I could expand the code with case switch, and map every element accordingly in each case, but there should be a simpler way to do this. I am new to xml, need some help here. P.S: I tried all the tools, commercial and free,

Live Template for Fluent-API Builder in IntelliJ

六眼飞鱼酱① 提交于 2019-12-12 04:54:54
问题 If I wanted to generate a "fluent builder" in IntelliJ anyone know where to edit the live template that is used in the Replace Constructor with Builder feature? The above mentioned feature will automatically build a Builder pattern object though with the common setAttribute naming convention instead of a more fluentlike naming pattern of .attribute or .withAttribute that I am looking for. Ultimately I would like to just be able to change a setting / template that would be used in rendering

How to Create Clojure `defn` Functions automatically?

こ雲淡風輕ζ 提交于 2019-12-12 04:08:10
问题 UPDATE: I re-wrote this to make the original problem clearer and added the all-macro solution. Please ignore this version and refer to the following: How to create Clojure `defn` functions automatically without macros? Unfortunately, SO will not allow me to delete this older version. Originally motivated by the following question: Mapped calls to clojurescript macro Suppose you want to create many similar functions automatically (i.e. without hand-writing them all). Suppose we have some pre

Possible OCaml code generation bug

£可爱£侵袭症+ 提交于 2019-12-12 03:49:33
问题 The following self contained code highlights a problem in OCaml, possibly with the code generation. Array x has connectivity information for nodes in [0..9]. Function init_graph originally constructed explicit arrays of incoming nodes for every node. The reduced version shown below just prints the two connected nodes. Function init_graph2 is identical to init_graph except for a "useless" else branch. But outputs produced by these two functions are quite different. You can run it and see that

How can I achieve this simple output in MyGeneration?

给你一囗甜甜゛ 提交于 2019-12-12 01:48:04
问题 If I have n tables in my Db schema and if I want to walk through all tables in my Db and create a .cs file for each table that will contain the below generated code: public class TableName { private _tableName = "<%TableName%>" //This string will be generated by MyGeneration // per each table public string TableName { get{ return _tableName; } } How should my template will be written? 回答1: I haven't worked with MyGeneration before but you can do this easily using CodeGenerator. The template

Using Python's basic I/O to manipulate or create Python Files?

♀尐吖头ヾ 提交于 2019-12-11 18:44:44
问题 Would the most efficient way-and I know it's not very efficient, but I honestly can't find any better way-to manipulate a Python (.py) file, to add/subtract/append code, be to use the basic file I/O module included in Python? For an example: obj = open('Codemanipulationtest.py', 'w+') obj.write("print 'This shows you can do basic I/O?'") obj.close() Will manipulate a file I have, named "codemanipulationtest.py", and add to it a print statement. Is this something that can be worked upon or are

Auto Class Generator

天大地大妈咪最大 提交于 2019-12-11 17:48:51
问题 I had originally asked this question here: Former Question It appears that what I was asking for was misunderstood. I will try to make this as clear and as brief as possible: I'm working on a parser that will automatically generate a c++ class and if the names of the header and cpp files are present the parser will write out those files respectively. If they are omitted then the parser will not write any files where it will generate a class automatically based on the information that is

Revisiting the conflict of lombok with java runtime compilation

不问归期 提交于 2019-12-11 17:36:24
问题 I am working in IntelliJ Idea, with JDK and JRE 8. The project makes use of lombok, and I would like to have code generation and runtime compiling. My aim is to produce a code that does the same task as some complicated runtime generated lambda function, to speed up the evaluation. The project makes heavy use of lombok. And I have the same issue as the one discussed here, so I know that one way around this problem is to add particular dependencies. My question is: did there appear any other,

KotlinPoet: Add function to existing class

自闭症网瘾萝莉.ら 提交于 2019-12-11 17:13:30
问题 I want to build an annotation processor that generates a public "non-mutable class" getter function of a private "mutable class" field (e.g. returning a LiveData version of a MutableLiveData field). What I want to write: class MyClass { @WithGetNonMutable private val popup: MutableLiveData<PopupTO?> = MutableLiveData() } What I want to generate class MyClass { private val popup: MutableLiveData<PopupTO?> = MutableLiveData() fun getPopup(): LiveData<PopupTO?> = popup } Generating the function