code-generation

How to make a copy of a Java class in runtime?

£可爱£侵袭症+ 提交于 2019-12-14 03:47:49
问题 I have a class class Foo { int increment(int x) { return x + 1; } } I want to obtain a copy of this class in runtime, e. g. a class like class Foo$Copy1 { int increment(int x) { return x + 1; } } Which has all the same methods, but a different name. Proxy seem to help with delegating , but not copying the methods with all their bodies. 回答1: You can use Byte Buddy for this: Class<?> type = new ByteBuddy() .redefine(Foo.class) .name("Foo$Copy1") .make() .load(Foo.class.getClassLoader())

Generate JSF2 CRUD's - Can I create the bean and xhtml automatically for any entity?

吃可爱长大的小学妹 提交于 2019-12-14 03:33:24
问题 I'm looking for any kind of software which allows me to generate, in an automatically way, the MVC files (a bean and a xhtml view) of any CRUD of any entity using Java Server Faces 2 and Richfaces 4 technologies. I think one solution would be to use the Hibernate Tools plugin for Eclipse, creating an exporter like the Dao code generator but I don't know if it is possible or how can i do that. I search but I didn't find any documentation about it. Do you know which is the best solution for

An in code class auto generator from a string of text or some other mechanism

允我心安 提交于 2019-12-13 23:11:13
问题 I would like to be able to automatically generate a class in code if possible. I know that I can have a text or script file that can be opened and the contents of that file be loaded into either a vector of strings or a string stream, and from there write back to a file or set of files to generate a class. I'm not interested in the details of the parsing aspect and this is not what I'm actually after. Let's say I have a text file that looks something like this: My current pseudo file above is

Generating C# structure from C structure

て烟熏妆下的殇ゞ 提交于 2019-12-13 16:20:11
问题 I have several dozens of C structures and I need to use them in C#. A typical C structure looks like this one: typedef struct _UM_EVENT { ULONG32 Id; ULONG32 Orgin; ULONG32 OperationType; ULONG32 Size; LARGE_INTEGER Time; HANDLE ProcessId; HANDLE ThreadId; } UM_EVENT, *PUM_EVENT; To use this structure in C# I declare it in C# and then do the marshalling stuff, which can be done roughly in this way: public struct UM_EVENT { public UInt32 Id; public UInt32 Orgin; public UInt32 OperationType;

How do I generate the source code to create an object I'm debugging?

扶醉桌前 提交于 2019-12-13 12:05:09
问题 Typical scenario for me: The legacy code I work on has a bug that only a client in production is having I attach a debugger and figure out how to reproduce the issue on their system given their input. But, I don't know why the error is happening yet. Now I want to write an automated test on my local system to try and reproduce then fix the bug That last step is really hard. The input can be very complex and have a lot of data to it. Creating the input by hand (eg: P p = new P(); p.setX("x");

Entity Framework DbContext code generation generates incorrect code

a 夏天 提交于 2019-12-13 05:35:33
问题 I'm using VS2010 with Entity Framework (file version is 4.4. product version is 5) I have installed the EF5.x DbContext generator. After creating my .edmx file, I right clicked on the empty space and added a new DbContext template, which generated the context.tt and .tt files. However, in the .tt files, this is how the auto generated code looks like: namespace DataObjects.EntityFramework.Models { using System; using System.Collections.Generic; public partial class SubSystem { public string

Is there any way to control the names of properties generated by the linq-to-sql designer?

可紊 提交于 2019-12-13 05:20:11
问题 Say you have a schema that looks something like this Foo FooId Bar BarId SomeFooId // Foreign key to Foo.FooId AnotherFooId // Foreign key to Foo.FooId I would like to be able to do something like this: Bar bar = ... DoSomethingWith(bar.SomeFoo); DoSomethingElseWith(bar.AnotherFoo); However, instead of generating SomeFoo and AnotherFoo properties, the linq-to-sql designer generates Foo and Foo1 . It is not obvious which of Foo and Foo1 refers to SomeFoo , and which refers to AnotherFoo . Is

How to generate Visual Studio Project using T4 using XML?

北战南征 提交于 2019-12-13 05:18:51
问题 Hi all! In earlier days it is possible using Code-Dom , I came to know that using T4 is much easier than Code-Dom. I have gone through many articles but still I am not in a situation to draft-out the code which will meet my requirements. I need to generate a code on the basis of an auto-generated XML document [ I am able to generate the XML document as per my requirements ]. It seems like this : <?xml version="1.0" encoding="utf-8" ?> <GeneratedSolution Name ="name of Solution">

Generating JAVA files and using them at runtime

和自甴很熟 提交于 2019-12-13 02:45:30
问题 I'm trying the following, suggested by Cedric Beust in some other thread. You could do this yourself as a pre-test task: implement a code generator that takes the information in XML form, grab the corresponding Java source file and generate a TestNG source file with all the annotations placed in the right locations. And then you run TestNG on that file. I have no clue with code generation. Can someone guide me in the right direction? Some simple examples would be great. Update: This is the

generate service /dao layer for GWT/Spring/Hibernate/PostgreSQL

一曲冷凌霜 提交于 2019-12-13 02:45:12
问题 We're developing a webapp using GWT 2.0(not to AppEngine), Spring and Hibernate and trying to jumpstart by auto-generating as much code as possible. I've looked at spring roo vs appfuse generate service /dao layer. I tried appfuse but that did NOT work for me; Also, roo for GWT is not quite there yet since it's a Milestone release. If a tool can generate the Service Layer and DAO layer for me, I should be able to do the actual business logic and UI wiring -- although it appears that if I'm