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
32
votes
3 answers
How to emit and execute Java bytecode at runtime?
I am writing an interpreter in Java for a domain-specific language with some scripting capabilities. I have already implemented a parser and now need to do a back end. To this end I am considering either to write my own interpreter (either working…

vitaut
- 49,672
- 25
- 199
- 336
31
votes
4 answers
How to use OpenAPI "oneOf" property with openapi-generator-maven-plugin when generating Spring code
I am developing an application with an Angular frontend and RESTful Spring Boot Backend
I found this very handy maven plugin openapi-generator-maven-plugin from org.openapitools. With its code generation capability, it helps enforce a "contract…

CeeTee
- 778
- 1
- 9
- 17
31
votes
14 answers
(Kotlin) Backend Internal error: Exception during code generation
I am creating a very thorough converter for Android with Kotlin, using the latest Android Studio Canary build and latest Kotlin.
I am suddenly getting a compiling error, even thought Android Studio doesn't see any bug in the code, it is complaining…

Josep Bigorra
- 733
- 2
- 9
- 20
31
votes
6 answers
How to output namespace in T4 templates?
I have a T4 template for a class set up with TextTemplatingFileGenerator Custom Tool in Visual Studio:
<#@ template language="C#v3.5" hostspecific="True" debug="True" #>
<#
var className =…

Hallgrim
- 15,143
- 10
- 46
- 54
31
votes
4 answers
Automatically generate C++ file from header?
I have a bunch of C++ header files with various class and function declarations. So far, when I've been writing the C++ source file implementations of the declared classes and functions, I've been manually:
Copying the declarations from the header…

Michael Aaron Safyan
- 93,612
- 16
- 138
- 200
31
votes
26 answers
Do you create your own code generators?
The Pragmatic Programmer advocates the use of code generators.
Do you create code generators on your projects? If yes, what do you use them for?

lajos
- 25,525
- 19
- 65
- 75
30
votes
10 answers
JPA java code generation
I am specifically looking for JPA code generation technique
First, what are all the project could generate JPA compliant code? (Eg. HibernateTools)
Second, I would also like to customize the code generation utility, as it has to compliant to our…

Mohan Narayanaswamy
- 2,149
- 6
- 33
- 40
30
votes
5 answers
Is there code generation API for TypeScript?
When I needed to generate some C# code, for example DTO classes from xsd schema, or an excel table, I've used some roslyn API's.
Is there something simmilar for typescript?
[EDIT]: I've end up using ts-morph

Liero
- 25,216
- 29
- 151
- 297
30
votes
2 answers
How to automatically generate function headers for .h file in Clion?
When writing a library in C, I usually end up implementing functions before defining them in the corresponding header file. As copying function header's in the header file is a repetitive task, I was wondering if I can automatically generate…

Ali Alavi
- 2,367
- 2
- 18
- 22
30
votes
10 answers
Java code generation
What are the leading frameworks for java code generation?
I am not looking for a DB or app generation tool. I have a skeleton of a class, and I need to generate it with different dynamic parts for different use cases. The majority of the class is…

YaOg
- 1,748
- 5
- 24
- 43
29
votes
2 answers
Is Pex (Test generation) really useful tool?
Yes, it is possible to generate tests on boundary values for functions like "Sum" or "Divide". Pex is a good tool here.
But more often we create tests on business behaviour. Let's consider example from classic Beck's tdd book:
[Test]
public void…

Yauheni Sivukha
- 2,586
- 20
- 22
29
votes
15 answers
Why should I use code generators
I have encountered this topic lately and couldn't understand why they are needed.
Can you explain why I should use them in my projects and how they can ease my life.
Examples will be great, and where from I can learn this topic little more.

Night Walker
- 20,638
- 52
- 151
- 228
29
votes
7 answers
Is there a key combination in Xcode to implement a Protocol?
In Visual Studio if I define a class to implement an interface e.g.
class MyObject : ISerializable {}
I am able to right click on ISerializable, select "Implement Interface" from the context menu and see the appropriate methods appear in my class…

AidenMontgomery
- 1,612
- 1
- 17
- 24
29
votes
4 answers
Change unhandled exception auto-generated catch code in Eclipse?
If I have unhandled exception in Java, Eclipse proposes two options to me: (1) add throws declaration and (2) surround with try/catch.
If I choose (2) it adds a code
try {
myfunction();
} catch (MyUnhandledException e) {
// TODO…

Suzan Cioc
- 29,281
- 63
- 213
- 385
29
votes
8 answers
How should I unit test a code-generator?
This is a difficult and open-ended question I know, but I thought I'd throw it to the floor and see if anyone had any interesting suggestions.
I have developed a code-generator that takes our python interface to our C++ code (generated via SWIG) and…

jkp
- 78,960
- 28
- 103
- 104