Topics related to the generation of code as the output of an application, instead of directly writing code by a programmer.
Questions tagged [code-generation]
3642 questions
89
votes
12 answers
Builder pattern code generation in IntelliJ
Is there any way to automate writing Builder patterns in IntelliJ?
For example, given this simple class:
class Film {
private String title;
private int length;
public void setTitle(String title) {
this.title = title;
}
public…

Martyn
- 16,432
- 24
- 71
- 104
78
votes
8 answers
return only Digits 0-9 from a String
I need a regular expression that I can use in VBScript and .NET that will return only the numbers that are found in a string.
For Example any of the following "strings" should return only 1231231234
123 123 1234
(123)…

Brian Boatright
- 36,294
- 34
- 81
- 102
78
votes
11 answers
What's the use of metaprogramming?
I've read:
Wikipedia
Code Generation vs. Metaprogramming
The art of Metaprogramming
Metaprogramming at c2.com
and I confess some confusion at the purpose behind metaprogramming/code generation.
Does anyone have a concrete example of where they use…

Wayne Werner
- 49,299
- 29
- 200
- 290
76
votes
7 answers
Comparison of XSD Code Generators
I'm doing some research in code generation from xsd schema files.
My requirements:
Must generate C# 2.0 code (or above), using generic collections where needed.
Must generate comments from the xsd comments
Must generate fully serializable…

edosoft
- 17,121
- 25
- 77
- 111
75
votes
12 answers
What is the correct way to write HTML using Javascript?
It seems that experienced web developers frown upon using document.write() in JavaScript when writing dynamic HTML.
Why is this? and what is the correct way?

Gary Willoughby
- 50,926
- 41
- 133
- 199
65
votes
11 answers
Can a Java class add a method to itself at runtime?
Can a class add a method to itself at runtime (like from a static block), so that if someone is performing reflection on this class, they'll see the new method, even though it wasn't defined at compile time?
Background:
A framework I'm using expects…

slattery
- 1,379
- 3
- 10
- 19
65
votes
12 answers
How can I generate database tables from C# classes?
Does anyone know a way to auto-generate database tables for a given class? I'm not looking for an entire persistence layer - I already have a data access solution I'm using, but I suddenly have to store a lot of information from a large number of…

VanOrman
- 4,351
- 5
- 35
- 31
63
votes
5 answers
Are there alternatives to cglib?
Just out of curiosity, are there any (stable) open source projects for runtime java code generation other than cglib? And why should I use them?

Mauli
- 16,863
- 27
- 87
- 114
62
votes
10 answers
Type-safe generic data structures in plain-old C?
I have done far more C++ programming than "plain old C" programming. One thing I sorely miss when programming in plain C is type-safe generic data structures, which are provided in C++ via templates.
For sake of concreteness, consider a generic…

Brad Larsen
- 995
- 1
- 12
- 20
60
votes
9 answers
How to generate basic TypeScript interfaces from Swagger schema?
I'm looking for a way to generate simplistic TypeScript interfaces from a Swagger schema. Most solutions I find are needlessly complicated.
I would like to generate interfaces like this:
export interface IBar {
a?: string;
b: number;
c:…

Ivan Koshelev
- 3,830
- 2
- 30
- 50
59
votes
1 answer
Warning: There is no class model available for code generation in Visual Paradigm
I'm dealing with a problem in my Visual Paradigm project. I created some Java sources and I did instant Reverse with them. Then I dragged the model elements of the classes to the Class diagram. I modified the class diagram adding some operations to…

Jonás
- 1,459
- 4
- 27
- 43
58
votes
1 answer
How does C-- compare to LLVM?
After learning a bit of how LLVM work I'm really excited about how portable low-level code can be generated and how modular this 'thing' is built.
But I discovered today the existence of C-- that seems to share some concepts with LLVM.
So I'm…

Alois Cochard
- 9,812
- 2
- 29
- 30
57
votes
4 answers
GetEntryAssembly for web applications
Assembly.GetEntryAssembly() does not work for web applications.
But... I really need something like that.
I work with some deeply-nested code that is used in both web and non-web applications.
My current solution is to browse the StackTrace to find…

Mose
- 1,781
- 3
- 16
- 35
57
votes
9 answers
Generate a Version.java file in Maven
I have a Java project that I build using an Ant script. I am trying to convert the project to Maven.
One of the tasks generates a Java source file called Version.java that contains a static String representation of the compilation timestamp, as…

Ralph
- 31,584
- 38
- 145
- 282
57
votes
10 answers
How do I get Eclipse to resolve classes generated with Maven 2?
I'm using Google Protocol Buffers to generate some Java classes for my project. Using Maven 2 and its "antrun" plugin, these classes are freshly generated before compile, output to target/generated-sources and put on the classpath during the build.…

Hanno Fietz
- 30,799
- 47
- 148
- 234