Does IntelliJ IDE provide custom code generation functinality?
When working on big well designed projects, often there are some conventions about structure. F.e. in one of the projects we had to name all migrations with this pattern '{yyyymmddhh}_MigrationName.cs', f.e. 201909201804_MakeInvalidRecordsInActive.cs
Some years ago at start of my career I have written console code generation tool for myself, that takes MigrationName and generates the the file, I'm still using this :) F.e.
dbmigr MakeInvalidRecordsInActive
will generate
201909201804_MakeInvalidRecordsInActive.cs file and place it to the right place in the project, the content of the will be the next:
using FluentMigrator;
using System;
namespace EzUR.DatabaseMigration
{
[Migration(201909271819)]
public class _201909271819_MakeInvalidRecordsInActive : Migration
{
public override void Up()
{
throw new NotImplementedException();
}
public override void Down()
{
throw new NotImplementedException();
}
}
}
Also there is another example, react application, need to add call to server:
- define url in urls file
- define request and response models
- define call to server with axios in server-api folder
- define call to server-api in api-services folder, api-services folder is a middle layer, which in many cases makes direct call of server-api
There are lot of boilerplate and it takes time to write it, but in theory should be enough just to: write url to server api, and define models, all other code can be autogenerated. So basically I want the tool where I can define task with some inputs that will ouputs files with code from the templates.
I interested is IntelliJ supports such things?
PS. Not related, but I am also looking for tool where I can define model - fields and types and generate models in different languages. Maybe you know some of them?
请先登录再写评论。
You can write a plug-in for IntelliJ IDEA for the code generation. Our Web Services plug-in for Java already can generate code from the URL. For the basic things one can use the File Templates feature: https://www.jetbrains.com/help/idea/using-file-and-code-templates.html .