Skip to content

Instantly share code, notes, and snippets.

@dfparker2002
Forked from pascalalich/eclipse-templates.xml
Created March 16, 2018 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfparker2002/1d52dd26f46e6025269f148dc2a38b13 to your computer and use it in GitHub Desktop.
Save dfparker2002/1d52dd26f46e6025269f148dc2a38b13 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment