[英]Java Interface - Auto-generate method implementation (optionally limited to Eclipse)
我有一個定義為的接口:
public interface IDomainEntity {
/**
* @return
* A serialized form of the class Object.
* Follows the format:<br/><br/>
* <pre class="brush: java">
* {@code
* public String getPropertiesString() {
* String resultString = new StringBuilder()
* .append( String.valueOf(this.getClass().getSimpleName()) + "@" + Integer.toHexString(this.hashCode()) + " {" )
* .append( " ${property}: '" + String.valueOf(this.${property}) + "'," )
* //... above line repeated N-1 times for N properties (${property})...
* .append( " }" );
* .toString();
*
* resultString = resultString.replace(", }", " }");
* return resultString;
* }
* </pre>
*/
public String getPropertiesString();
}
我可以做些什么使Eclipse
auto-generate
將方法的內容生成為我在javadoc
注釋中所具有的內容,從而擴展該類的所有直接屬性(我不在乎inheritance
parent
屬性)。
目前,Eclipse將給我:
@Override
public String getPropertiesString() {
// TODO Auto-generated method stub
return null;
}
從Java Code Style
>> Code Templates
>> Code
>> Method body
(JDT),但我正在尋找特定於1 interface
東西以及implements
該interface
的結果domain class
。
Fyi,我希望避免任何解決方案都圍繞使用aspects
或reflection
來獲取類的所有屬性。
謝謝!
如果您使用的是Java 8,則可以在界面中添加默認實現
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.