IntelliJ可以在没有"get"消息的情况下生成吸气剂吗?字首? [英] Can IntelliJ generate getters without the "get" prefix?

查看:66
本文介绍了IntelliJ可以在没有"get"消息的情况下生成吸气剂吗?字首?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IntelliJ具有很酷的功能来生成Java getter.例如,对于字段private final String foo,它将生成一个吸气剂getFoo().

IntelliJ has the cool feature to generate Java getters. For example, for a field private final String foo, it will generate a getter getFoo().

有什么方法可以配置IntelliJ以生成String foo()格式的吸气剂?我主要使用不可变对象,并且更喜欢这种语法.

Is there any way I can configure IntelliJ to generate getters in the format String foo()? I am working mainly with immutable objects and prefer this syntax.

推荐答案

整洁的问题!只是为了澄清@Danny Dan自IntelliJ 15发布以来的答案...

Neat question! Just to clarify @Danny Dan's answer since IntelliJ 15 has been released...

  • Alt + 插入
  • 选择 Getter
  • 从RHS上的'...'打开模板配置
  • 从LHS创建新模板-请参见下面的示例
  • 确定,然后选择新模板
  • Alt+Insert
  • Select Getter
  • Open the template configuration from '...' on the RHS
  • Create a new template from the LHS - see example below
  • Ok and select your new template
 public ##
 #if($field.modifierStatic)
   static ##
 #end
 $field.type ##
 ${field.name}() {
   return $field.name;
 }

您为什么要这样做?

结帐实施域驱动的设计:

简单而有效的对象设计方法使Value Object忠实于泛在语言. getValuePercentage()的使用是一种技术性的计算机声明,但是valuePercentage()是一种流畅的人类可读语言表达.

The simple but effective approach to object design keeps the Value Object faithful to the Ubiquitous Language. The use of getValuePercentage() is a technical computer statement, but valuePercentage() is a fluent human-readable language expression.

这篇关于IntelliJ可以在没有"get"消息的情况下生成吸气剂吗?字首?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆