code-generation

Serialize a Java object to Java code?

僤鯓⒐⒋嵵緔 提交于 2019-11-30 12:47:21
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 to partially create complex objects programmatically and then complete the creation manually in code.

Do you use code generation tools?

半世苍凉 提交于 2019-11-30 12:44:12
Do you use code-generation tools (aside from those used to generate proxies and from designers built-in to visual studio)? What part(s) of your application do you generate? Do you typically roll your own generator? If so, what type of generator do you write (asp templates, coddom etc.). If not, what 3rd party tools do you use? I am currently working on a few different projects wich all use a custom code-generator that handles everything from generating the database structure, business entities, DAL, and BLL. I am curious about other peoples experiences are with these kinds of tools. I'm in the

Is it possible to modify a method body at run-time in .NET?

浪尽此生 提交于 2019-11-30 12:22:27
I know that it is possible (in theory) to create a new type at run-time, but is it possible to modify a method body of an existing type at run-time? My plan (if I can get this to work) is to tag up methods with a custom attribute, and then at run-time search for methods with the attribute, and insert some of my own code into the method body. Any suggestions? I suppose if I can't get that approach to work, I could always go with a virtual method in a base class (with the attributes), combined with a static factory to spit out a derived dynamic type with my run-time generated method in the child

Programmatically writing Java [closed]

送分小仙女□ 提交于 2019-11-30 11:38:57
I was wondering if there is already a library to programmatically write a java class or method? I am looking for libraries capable of writing new source code into existing files or extend files that already exist. Nishant Look into Eclipse JDT . The Eclipse Java Development Tools (JDT) provide APIs to access and manipulate Java source code. It allows to access the existing projects in the workspace, create new projects and modify and read existing projects. More specifically, you can create new Java elements e.g. projects, packages, classes using the Java Model API and then you can then create

Atomic operations and code generation for gcc

微笑、不失礼 提交于 2019-11-30 11:33:33
I am curring looking at some assembly generated for atomic operations by gcc. I tried the following short sequence: int x1; int x2; int foo; void test() { __atomic_store_n( &x1, 1, __ATOMIC_SEQ_CST ); if( __atomic_load_n( &x2 ,__ATOMIC_SEQ_CST )) return; foo = 4; } Looking at Herb Sutter's atomic weapons talk on code generation, he mentions that the X86 manual mandates to use xchg for atomic stores and a simple mov for atomic reads. So I was expecting something along the lines of: test(): .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa

Elegant way for C++ code generation

僤鯓⒐⒋嵵緔 提交于 2019-11-30 10:29:43
I am currently working on a database related project in which I generate a lot of C++ code. This code is compiled then and loaded as a dynamic library. I use this techniques to build efficient code for the database schema and queries. Currently, I am using simple file write to generate the code (what was okay for the proof-of-concept implementation). Now, I am searching for a more elegant but comparable flexible solution to generate C++ code. I searched quite a lot but all the solutions I found so far are rather complex/extensive, not efficient enough, or not flexible enough. What libraries

is there a better way to handle RPC_E_CALL_REJECTED exceptions when doing visual studio automation?

淺唱寂寞╮ 提交于 2019-11-30 10:24:52
this is what I'm currently doing: protected void setupProject() { bool lbDone = false; int liCount = 0; while (!lbDone && liCount < pMaxRetries) { try { pProject.ProjectItems.Item("Class1.cs").Delete(); lbDone = true; } catch (System.Runtime.InteropServices.COMException loE) { liCount++; if ((uint)loE.ErrorCode == 0x80010001) { // RPC_E_CALL_REJECTED - sleep half sec then try again System.Threading.Thread.Sleep(pDelayBetweenRetry); } } } } now I have that try catch block around most calls to the EnvDTE stuff, and it works well enough. The problem I have is when I to loop through a collection

Axis2 Web Service Client Generation - Types without modifying the client

久未见 提交于 2019-11-30 10:22:48
Is it possible with Axis2 and Eclipse to generate a Web Service client and have it use java types that you already have in packages instead of creating it's own types. Reason being of course if I have type A already created and it creates it's own Type A I can't just assign variable of type A to variable of type B. The wsdl is being generated from a Web Service deployed to an application server. If it's not possible to generate it from that would it be possible to generate a client from the already existing java files. If you really want to reuse existing classes, you can call the Axis2 API

Code generation by genetic algorithms

拜拜、爱过 提交于 2019-11-30 10:20:15
问题 Evolutionary programming seems to be a great way to solve many optimization problems. The idea is very easy and the implementation does not make problems. I was wondering if there is any way to evolutionarily create a program in ruby/python script (or any other language)? The idea is simple: Create a population of programs Perform genetic operations (roulette-wheel selection or any other selection), create new programs with inheritance from best programs, etc. Loop point 2 until program that

Petri net drawing and code generation

孤者浪人 提交于 2019-11-30 09:23:56
Is there any software for drawing a Petri net and generating any source code from there? The source code could be in any already known programming language... Slightly less desirable option would be outputting a file with only the description of the Petri net graphs in a text-based file in some open format, like XML or any other data language. I could then write the code generator myself, but at least I would like to avoid gui/graph development part ;)) Thanks Check PetriNetSim it is developed in Java, you can draw and simulate simple/colored/timed petrinets. It comes with few examples. You