Reputation: 338316
I would like to customize the naming of the arguments generated by IntelliJ 2017.2 when choosing Code
> Generate
> Constructor
to:
final
.Arg
to the end of each variable name.firstNameArg
& lastNameArg
rather than firstName
& lastName
.@NotNull
.Is there some way to customize the generation of constructor code?
This Question, Customizing of code generation in IntelliJ IDEA, is similar but (a) does not refer to Constructor, and (b) may be outdated.
Upvotes: 5
Views: 2636
Reputation: 47865
I don't think IntelliJ provides this OOTB. You could, perhaps, use a Live Template via Preferences > Editor > Live Templates
.
Template text:
private final $parameterType$ $parameterName$;
public $constructorClass$(final $parameterType$ $parameterName$$parameterNameSuffix$){
this.$parameterName$ = $parameterName$$parameterNameSuffix$;
}
Change the "Applicability" of the Live Template to be:
Java > Declaration
Java > Smart type completion
Click on Edit variables
and set the Expression
associated with each of the variables as follows:
Here are some screenshots showing it in action:
However, this approach has some caveats (some of which may be deal breakers for your use case):
Upvotes: 3