I found out how to change the default templates in IntelliJ when generating toString and hashCode/equals implementations but I cannot find any proper documentation on what variables are accessible. Autocomplete helps but it does not show me any such option.
Basically, I want to change the toString template to generate a prefix of Foo.Bar for the following inner class
class Foo {
class Bar { }
}
where it now simply puts Bar without the prefix. I do not want to add the package name!
Bonus questions: How can I set the global parameters? I am also trying to change the parameter name of the equals template from o to object.
A documentation on what variables are accessible within the template can be found here: Documentation of the
toStringsettings dialog.Unfortunately, I cannot find anything variable like
class.hasOuterClass,class.outerClassNameor something similar.After a little research I found an ugly solution but it works, if you class name start with a capital letter and your package names are all lower case.
Put the following at the beginning of your template:
#set( $classname = $FQClassname.substring($StringUtil.indexOfAny($FQClassname, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")))Bonus question:
I did not find a similar documentation for the
equals/hashCodetemplate but I looked at the source code of theequalsHelper.vmon GitHub.If you put
#set( $baseParamName = "object" )before the#parse("equalsHelper.vm")the$paramNamewill then be namedobjectif there will be no other local variable with that name. This happens, if you have a member variable with that name.