Skip to content

Instantly share code, notes, and snippets.

@pascalalich
Created February 18, 2015 06:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pascalalich/436952ccf778e9181ba8 to your computer and use it in GitHub Desktop.
Save pascalalich/436952ccf778e9181ba8 to your computer and use it in GitHub Desktop.
Eclipse Templates for Java logging, hashCode, equals, and toString with SLF4J and Guava
Just download the template file and import it in your Eclipse IDE via Window/Preferences/Java/Editor/Templates -> Import
<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="true" context="java" deleted="false" description="equals (Guava)" enabled="true" name="equals">${:import(com.google.common.base.Objects)}&#13;
@Override&#13;
public boolean equals(final Object obj) {&#13;
if (this == obj) {&#13;
return true;&#13;
}&#13;
if (obj == null) {&#13;
return false;&#13;
}&#13;
if (getClass() != obj.getClass()) {&#13;
return false;&#13;
}&#13;
&#13;
final ${enclosing_type} other = (${enclosing_type}) obj;&#13;
return Objects.equal(this.${field}, other.${field})&#13;
&amp;&amp; ${cursor};&#13;
}</template><template autoinsert="true" context="java" deleted="false" description="hashCode (Guava)" enabled="true" name="hashCode">${:import(com.google.common.base.Objects)}&#13;
@Override&#13;
public int hashCode() {&#13;
return Objects.hashCode(this.${field}, ${cursor});&#13;
}</template><template autoinsert="true" context="java" deleted="false" description="Logger Instantiation (SL4J)" enabled="true" name="log">${:import(org.slf4j.Logger,org.slf4j.LoggerFactory)}&#13;
private static final Logger LOG = LoggerFactory.getLogger(${enclosing_type}.class);&#13;
</template><template autoinsert="true" context="java" deleted="false" description="toString (Guava)" enabled="true" name="toString">${:import(com.google.common.base.Objects)}&#13;
@Override&#13;
public String toString() {&#13;
return Objects.toStringHelper(this)&#13;
.add("${field}", this.${field})&#13;
.add(${cursor})&#13;
.tostring();&#13;
}</template></templates>
@sarnobat
Copy link

line 29 - capitalize the "S"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment