Details
Description
this weekend I tried http://projectlombok.org/ and it is amazing.
Short: it is code generation in the IDE, just say @Getter on a field and
there will be a getter (not visible in code, but in the outlines)
(The editor is filled with annotation and the AST is filled with automatically created code constructs)
But how to handle this?
there are some problems with warnings of unused fields etc.
here the example
package de.lgohlke.qdox; import lombok.EqualsAndHashCode; import lombok.Getter; import com.thoughtworks.qdox.model.**JavaMethod; @EqualsAndHashCode public class JavaMethodHashed { @Getter private final JavaMethod method; private final String signature; private final String clazz; public JavaMethodHashed(final JavaMethod method) { this.method = method; this.signature = method.**getDeclarationSignature(true); this.clazz = method.getParentClass().**getFullyQualifiedName(); } }
it really would be expressed without lombok with this
package de.lgohlke.qdox; import com.thoughtworks.qdox.model.**JavaMethod; public class JavaMethodHashed { private final JavaMethod method; private final String signature; private final String clazz; public JavaMethodHashed(final JavaMethod method) { this.method = method; this.signature = method.**getDeclarationSignature(true); this.clazz = method.getParentClass().** getFullyQualifiedName(); } @java.lang.Override @java.lang.SuppressWarnings("**all") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (o == null) return false; if (o.getClass() != this.getClass()) return false; final JavaMethodHashed other = (JavaMethodHashed)o; if (this.getMethod() == null ? other.getMethod() != null : !this.getMethod().equals(**other.getMethod())) return false; if (this.signature == null ? other.signature != null : !this.signature.equals(other.**signature)) return false; if (this.clazz == null ? other.clazz != null : !this.clazz.equals(other.**clazz)) return false; return true; } @java.lang.Override @java.lang.SuppressWarnings("**all") public int hashCode() { final int PRIME = 31; int result = 1; result = result * PRIME + (this.getMethod() == null ? 0 : this.getMethod().hashCode()); result = result * PRIME + (this.signature == null ? 0 : this.signature.hashCode()); result = result * PRIME + (this.clazz == null ? 0 : this.clazz.hashCode()); return result; } @java.lang.SuppressWarnings("**all") public JavaMethod getMethod() { return this.method; } }
there are some issues with this, see sub tickets
Attachments
Issue Links
- is related to
-
SONARJAVA-1156 FP on S1068: Annotated unused private fields should be ignored
-
- Closed
-
-
SONAR-2718 [CodeGen - Lombok] false warning hint
-
- Closed
-
-
SONAR-2720 [CodeGen - Lombok] false warning hint (Unused Private Field)
-
- Closed
-
-
SONARJAVA-990 S1068 Add support for more lombok annotations
-
- Closed
-
- relates to
-
SONAR-1090 Detect unused private and protected methods
-
- Closed
-
-
SONARJAVA-117 Rule "Unused private method" should not log violation on method having the @PostConstruct and @PreDestroy annotations
-
- Closed
-