From a40a86ad532881acd311200a665b5f55790c55cc Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Thu, 9 Jan 2014 21:00:44 +0100 Subject: [#625] Instead of '31' as a prime number for hashCode(), use something else. 31, probably owing to its inclusion in Effective Java, is overused, as proven by Maaartinus in issue 625. Switching to 277 instead. Also, 1231/1237 pair used for booleans has been replaced by 2591/2609. --- usage_examples/DataExample_post.jpage | 4 ++-- usage_examples/EqualsAndHashCodeExample_post.jpage | 4 ++-- usage_examples/ValueExample_post.jpage | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'usage_examples') diff --git a/usage_examples/DataExample_post.jpage b/usage_examples/DataExample_post.jpage index 3dc675e9..896839de 100644 --- a/usage_examples/DataExample_post.jpage +++ b/usage_examples/DataExample_post.jpage @@ -55,7 +55,7 @@ public class DataExample { } @Override public int hashCode() { - final int PRIME = 31; + final int PRIME = 277; int result = 1; final long temp1 = Double.doubleToLongBits(this.getScore()); result = (result*PRIME) + (this.getName() == null ? 0 : this.getName().hashCode()); @@ -101,7 +101,7 @@ public class DataExample { } @Override public int hashCode() { - final int PRIME = 31; + final int PRIME = 277; int result = 1; result = (result*PRIME) + (this.getName() == null ? 0 : this.getName().hashCode()); result = (result*PRIME) + (this.getValue() == null ? 0 : this.getValue().hashCode()); diff --git a/usage_examples/EqualsAndHashCodeExample_post.jpage b/usage_examples/EqualsAndHashCodeExample_post.jpage index 4a90e7dc..57191f55 100644 --- a/usage_examples/EqualsAndHashCodeExample_post.jpage +++ b/usage_examples/EqualsAndHashCodeExample_post.jpage @@ -24,7 +24,7 @@ public class EqualsAndHashCodeExample { } @Override public int hashCode() { - final int PRIME = 31; + final int PRIME = 277; int result = 1; final long temp1 = Double.doubleToLongBits(this.score); result = (result*PRIME) + (this.name == null ? 0 : this.name.hashCode()); @@ -57,7 +57,7 @@ public class EqualsAndHashCodeExample { } @Override public int hashCode() { - final int PRIME = 31; + final int PRIME = 277; int result = 1; result = (result*PRIME) + super.hashCode(); result = (result*PRIME) + this.width; diff --git a/usage_examples/ValueExample_post.jpage b/usage_examples/ValueExample_post.jpage index ac9b64d1..c5971262 100644 --- a/usage_examples/ValueExample_post.jpage +++ b/usage_examples/ValueExample_post.jpage @@ -46,7 +46,7 @@ public final class ValueExample { @java.lang.Override public int hashCode() { - final int PRIME = 31; + final int PRIME = 277; int result = 1; final Object $name = this.getName(); result = result * PRIME + ($name == null ? 0 : $name.hashCode()); @@ -103,7 +103,7 @@ public final class ValueExample { @java.lang.Override public int hashCode() { - final int PRIME = 31; + final int PRIME = 277; int result = 1; final Object $name = this.getName(); result = result * PRIME + ($name == null ? 0 : $name.hashCode()); -- cgit From 14cc54527663018cdf7343eefffc8c37fbce93bb Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Sun, 19 Jan 2014 21:49:35 +0100 Subject: Issue 625: use (even) better primes for hashcodes --- doc/changelog.markdown | 1 + src/core/lombok/core/handlers/HandlerUtil.java | 14 +++++++++++--- .../lombok/eclipse/handlers/HandleEqualsAndHashCode.java | 12 ++++++------ .../lombok/javac/handlers/HandleEqualsAndHashCode.java | 8 ++++---- test/transform/resource/after-delombok/Accessors.java | 2 +- test/transform/resource/after-delombok/DataExtended.java | 2 +- test/transform/resource/after-delombok/DataIgnore.java | 2 +- .../resource/after-delombok/DataOnLocalClass.java | 6 +++--- test/transform/resource/after-delombok/DataPlain.java | 8 ++++---- test/transform/resource/after-delombok/DataWithGetter.java | 2 +- .../resource/after-delombok/DataWithGetterNone.java | 2 +- .../resource/after-delombok/EqualsAndHashCode.java | 9 ++++++--- .../EqualsAndHashCodeWithSomeExistingMethods.java | 2 +- .../resource/after-delombok/GetterLazyBoolean.java | 4 ++-- .../resource/after-delombok/GetterLazyEahcToString.java | 2 +- .../resource/after-delombok/GetterSetterJavadoc.java | 2 +- test/transform/resource/after-delombok/ValuePlain.java | 6 +++--- test/transform/resource/after-ecj/Accessors.java | 2 +- test/transform/resource/after-ecj/DataExtended.java | 2 +- test/transform/resource/after-ecj/DataIgnore.java | 2 +- test/transform/resource/after-ecj/DataOnLocalClass.java | 6 +++--- test/transform/resource/after-ecj/DataPlain.java | 8 ++++---- test/transform/resource/after-ecj/DataWithGetter.java | 2 +- test/transform/resource/after-ecj/DataWithGetterNone.java | 2 +- test/transform/resource/after-ecj/EqualsAndHashCode.java | 10 +++++++--- .../EqualsAndHashCodeWithSomeExistingMethods.java | 2 +- test/transform/resource/after-ecj/GetterLazyBoolean.java | 4 ++-- .../resource/after-ecj/GetterLazyEahcToString.java | 2 +- test/transform/resource/after-ecj/GetterSetterJavadoc.java | 2 +- test/transform/resource/after-ecj/ValuePlain.java | 6 +++--- test/transform/resource/before/EqualsAndHashCode.java | 1 + usage_examples/DataExample_post.jpage | 4 ++-- usage_examples/EqualsAndHashCodeExample_post.jpage | 4 ++-- usage_examples/ValueExample_post.jpage | 4 ++-- 34 files changed, 82 insertions(+), 65 deletions(-) (limited to 'usage_examples') diff --git a/doc/changelog.markdown b/doc/changelog.markdown index d4a29177..72291c5b 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -3,6 +3,7 @@ Lombok Changelog ### v1.12.5 "Edgy Guinea Pig" * DETAIL: {Delombok} Inside enum bodies the delombok formatter didn't respect the emptyLines directive [Issue #529](https://code.google.com/p/projectlombok/issues/detail?id=629). +* DETAIL: Use smaller primes (<127) for generating hashcodes [Issue #625](https://code.google.com/p/projectlombok/issues/detail?id=625) ### v1.12.4 (January 15th, 2014) * BUGFIX: v1.12.2's delombok turns all operator+assignments into just assignment. Fixed. [Issue #598](https://code.google.com/p/projectlombok/issues/detail?id=598) diff --git a/src/core/lombok/core/handlers/HandlerUtil.java b/src/core/lombok/core/handlers/HandlerUtil.java index c8076ab6..23b8ccc7 100644 --- a/src/core/lombok/core/handlers/HandlerUtil.java +++ b/src/core/lombok/core/handlers/HandlerUtil.java @@ -27,9 +27,17 @@ import lombok.core.LombokNode; public class HandlerUtil { private HandlerUtil() {} - public static final int PRIME_FOR_HASHCODE = 277; - public static final int PRIME_FOR_TRUE = 2591; - public static final int PRIME_FOR_FALSE = 2609; + public static int primeForHashcode() { + return 59; + } + + public static int primeForTrue() { + return 79; + } + + public static int primeForFalse() { + return 97; + } /** Checks if the given name is a valid identifier. * diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index 8d95ca64..0cc0836e 100644 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -272,7 +272,7 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler>> 32 ^ $d); + result = result * PRIME + (this.b ? 79 : 97); return result; } } @@ -111,7 +114,7 @@ class EqualsAndHashCode4 extends EqualsAndHashCode { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = result * PRIME + super.hashCode(); return result; diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeWithSomeExistingMethods.java b/test/transform/resource/after-delombok/EqualsAndHashCodeWithSomeExistingMethods.java index e1bdc7f7..aa9b984f 100644 --- a/test/transform/resource/after-delombok/EqualsAndHashCodeWithSomeExistingMethods.java +++ b/test/transform/resource/after-delombok/EqualsAndHashCodeWithSomeExistingMethods.java @@ -69,7 +69,7 @@ class EqualsAndHashCodeWithNoExistingMethods { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = result * PRIME + this.x; return result; diff --git a/test/transform/resource/after-delombok/GetterLazyBoolean.java b/test/transform/resource/after-delombok/GetterLazyBoolean.java index ba26e7b7..eb6662e2 100644 --- a/test/transform/resource/after-delombok/GetterLazyBoolean.java +++ b/test/transform/resource/after-delombok/GetterLazyBoolean.java @@ -21,9 +21,9 @@ class GetterLazyBoolean { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; - result = result * PRIME + (this.isBooleanValue() ? 2609 : 2591); + result = result * PRIME + (this.isBooleanValue() ? 79 : 97); return result; } @java.lang.Override diff --git a/test/transform/resource/after-delombok/GetterLazyEahcToString.java b/test/transform/resource/after-delombok/GetterLazyEahcToString.java index 29e2f51c..3e98a25e 100644 --- a/test/transform/resource/after-delombok/GetterLazyEahcToString.java +++ b/test/transform/resource/after-delombok/GetterLazyEahcToString.java @@ -27,7 +27,7 @@ class GetterLazyEahcToString { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; final java.lang.Object $value = this.getValue(); result = result * PRIME + ($value == null ? 0 : $value.hashCode()); diff --git a/test/transform/resource/after-delombok/GetterSetterJavadoc.java b/test/transform/resource/after-delombok/GetterSetterJavadoc.java index 5b12a395..743a3aac 100644 --- a/test/transform/resource/after-delombok/GetterSetterJavadoc.java +++ b/test/transform/resource/after-delombok/GetterSetterJavadoc.java @@ -41,7 +41,7 @@ class GetterSetterJavadoc1 { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = result * PRIME + this.getFieldName(); return result; diff --git a/test/transform/resource/after-delombok/ValuePlain.java b/test/transform/resource/after-delombok/ValuePlain.java index af87d1ba..e880454b 100644 --- a/test/transform/resource/after-delombok/ValuePlain.java +++ b/test/transform/resource/after-delombok/ValuePlain.java @@ -30,7 +30,7 @@ final class Value1 { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = result * PRIME + this.getX(); final java.lang.Object $name = this.getName(); @@ -80,7 +80,7 @@ class Value2 { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = result * PRIME + this.getX(); final java.lang.Object $name = this.getName(); @@ -123,7 +123,7 @@ final class Value3 { @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = result * PRIME + this.getX(); result = result * PRIME + this.getY(); diff --git a/test/transform/resource/after-ecj/Accessors.java b/test/transform/resource/after-ecj/Accessors.java index 52a72d52..c8fdc3bf 100644 --- a/test/transform/resource/after-ecj/Accessors.java +++ b/test/transform/resource/after-ecj/Accessors.java @@ -90,7 +90,7 @@ class AccessorsChain { return (other instanceof AccessorsPrefix3); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; final java.lang.Object $fName = this.getName(); result = ((result * PRIME) + (($fName == null) ? 0 : $fName.hashCode())); diff --git a/test/transform/resource/after-ecj/DataExtended.java b/test/transform/resource/after-ecj/DataExtended.java index 35a7ca34..bcfd26e3 100644 --- a/test/transform/resource/after-ecj/DataExtended.java +++ b/test/transform/resource/after-ecj/DataExtended.java @@ -22,7 +22,7 @@ return (other instanceof DataExtended); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); return result; diff --git a/test/transform/resource/after-ecj/DataIgnore.java b/test/transform/resource/after-ecj/DataIgnore.java index 4a3c051b..d0e72e15 100644 --- a/test/transform/resource/after-ecj/DataIgnore.java +++ b/test/transform/resource/after-ecj/DataIgnore.java @@ -20,7 +20,7 @@ return (other instanceof DataIgnore); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); return result; diff --git a/test/transform/resource/after-ecj/DataOnLocalClass.java b/test/transform/resource/after-ecj/DataOnLocalClass.java index 4a247542..511291c2 100644 --- a/test/transform/resource/after-ecj/DataOnLocalClass.java +++ b/test/transform/resource/after-ecj/DataOnLocalClass.java @@ -36,7 +36,7 @@ class DataOnLocalClass1 { return (other instanceof Local); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); final java.lang.Object $name = this.getName(); @@ -86,7 +86,7 @@ class DataOnLocalClass2 { return (other instanceof Local.InnerLocal); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; final java.lang.Object $name = this.getName(); result = ((result * PRIME) + (($name == null) ? 0 : $name.hashCode())); @@ -124,7 +124,7 @@ class DataOnLocalClass2 { return (other instanceof Local); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); return result; diff --git a/test/transform/resource/after-ecj/DataPlain.java b/test/transform/resource/after-ecj/DataPlain.java index 2105c6f2..aa47fdaa 100644 --- a/test/transform/resource/after-ecj/DataPlain.java +++ b/test/transform/resource/after-ecj/DataPlain.java @@ -31,7 +31,7 @@ import lombok.Data; return (other instanceof Data1); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); final java.lang.Object $name = this.getName(); @@ -78,7 +78,7 @@ import lombok.Data; return (other instanceof Data2); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); final java.lang.Object $name = this.getName(); @@ -120,7 +120,7 @@ final @Data class Data3 { return true; } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); final java.lang.Object $name = this.getName(); @@ -167,7 +167,7 @@ final @Data @lombok.EqualsAndHashCode(callSuper = true) class Data4 extends java return (other instanceof Data4); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + super.hashCode()); result = ((result * PRIME) + this.getX()); diff --git a/test/transform/resource/after-ecj/DataWithGetter.java b/test/transform/resource/after-ecj/DataWithGetter.java index 9676e851..2ce74ceb 100644 --- a/test/transform/resource/after-ecj/DataWithGetter.java +++ b/test/transform/resource/after-ecj/DataWithGetter.java @@ -30,7 +30,7 @@ return (other instanceof DataWithGetter); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); result = ((result * PRIME) + this.getY()); diff --git a/test/transform/resource/after-ecj/DataWithGetterNone.java b/test/transform/resource/after-ecj/DataWithGetterNone.java index d5e190d8..087d0762 100644 --- a/test/transform/resource/after-ecj/DataWithGetterNone.java +++ b/test/transform/resource/after-ecj/DataWithGetterNone.java @@ -30,7 +30,7 @@ return (other instanceof DataWithGetterNone); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.x); result = ((result * PRIME) + this.y); diff --git a/test/transform/resource/after-ecj/EqualsAndHashCode.java b/test/transform/resource/after-ecj/EqualsAndHashCode.java index 492f9344..625a0f87 100644 --- a/test/transform/resource/after-ecj/EqualsAndHashCode.java +++ b/test/transform/resource/after-ecj/EqualsAndHashCode.java @@ -35,7 +35,7 @@ return (other instanceof EqualsAndHashCode); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.x); result = ((result * PRIME) + java.util.Arrays.hashCode(this.y)); @@ -52,6 +52,7 @@ final @lombok.EqualsAndHashCode class EqualsAndHashCode2 { long y; float f; double d; + boolean b; EqualsAndHashCode2() { super(); } @@ -69,10 +70,12 @@ final @lombok.EqualsAndHashCode class EqualsAndHashCode2 { return false; if ((java.lang.Double.compare(this.d, other.d) != 0)) return false; + if ((this.b != other.b)) + return false; return true; } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.x); final long $y = this.y; @@ -80,6 +83,7 @@ final @lombok.EqualsAndHashCode class EqualsAndHashCode2 { result = ((result * PRIME) + java.lang.Float.floatToIntBits(this.f)); final long $d = java.lang.Double.doubleToLongBits(this.d); result = ((result * PRIME) + (int) ($d ^ ($d >>> 32))); + result = ((result * PRIME) + (this.b ? 79 : 97)); return result; } } @@ -125,7 +129,7 @@ final @lombok.EqualsAndHashCode(callSuper = false) class EqualsAndHashCode3 exte return (other instanceof EqualsAndHashCode4); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + super.hashCode()); return result; diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeWithSomeExistingMethods.java b/test/transform/resource/after-ecj/EqualsAndHashCodeWithSomeExistingMethods.java index 83878675..05f7ad97 100644 --- a/test/transform/resource/after-ecj/EqualsAndHashCodeWithSomeExistingMethods.java +++ b/test/transform/resource/after-ecj/EqualsAndHashCodeWithSomeExistingMethods.java @@ -57,7 +57,7 @@ import static lombok.AccessLevel.NONE; return (other instanceof EqualsAndHashCodeWithNoExistingMethods); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.x); return result; diff --git a/test/transform/resource/after-ecj/GetterLazyBoolean.java b/test/transform/resource/after-ecj/GetterLazyBoolean.java index d3b257a7..c37eece2 100644 --- a/test/transform/resource/after-ecj/GetterLazyBoolean.java +++ b/test/transform/resource/after-ecj/GetterLazyBoolean.java @@ -57,9 +57,9 @@ return (other instanceof GetterLazyBoolean); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; - result = ((result * PRIME) + (this.isBooleanValue() ? 2609 : 2591)); + result = ((result * PRIME) + (this.isBooleanValue() ? 79 : 97)); return result; } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { diff --git a/test/transform/resource/after-ecj/GetterLazyEahcToString.java b/test/transform/resource/after-ecj/GetterLazyEahcToString.java index d8a90350..da9f6a83 100644 --- a/test/transform/resource/after-ecj/GetterLazyEahcToString.java +++ b/test/transform/resource/after-ecj/GetterLazyEahcToString.java @@ -46,7 +46,7 @@ return (other instanceof GetterLazyEahcToString); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; final java.lang.Object $value = this.getValue(); result = ((result * PRIME) + (($value == null) ? 0 : $value.hashCode())); diff --git a/test/transform/resource/after-ecj/GetterSetterJavadoc.java b/test/transform/resource/after-ecj/GetterSetterJavadoc.java index 10d9a0be..b7fc15b8 100644 --- a/test/transform/resource/after-ecj/GetterSetterJavadoc.java +++ b/test/transform/resource/after-ecj/GetterSetterJavadoc.java @@ -22,7 +22,7 @@ return (other instanceof GetterSetterJavadoc1); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getFieldName()); return result; diff --git a/test/transform/resource/after-ecj/ValuePlain.java b/test/transform/resource/after-ecj/ValuePlain.java index a23944de..5ca32af8 100644 --- a/test/transform/resource/after-ecj/ValuePlain.java +++ b/test/transform/resource/after-ecj/ValuePlain.java @@ -23,7 +23,7 @@ final @lombok.Value class Value1 { return true; } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); final java.lang.Object $name = this.getName(); @@ -68,7 +68,7 @@ final @lombok.Value class Value1 { return (other instanceof Value2); } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); final java.lang.Object $name = this.getName(); @@ -106,7 +106,7 @@ final @Value class Value3 { return true; } public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); result = ((result * PRIME) + this.getY()); diff --git a/test/transform/resource/before/EqualsAndHashCode.java b/test/transform/resource/before/EqualsAndHashCode.java index 0a1e3290..660f923a 100644 --- a/test/transform/resource/before/EqualsAndHashCode.java +++ b/test/transform/resource/before/EqualsAndHashCode.java @@ -13,6 +13,7 @@ final class EqualsAndHashCode2 { long y; float f; double d; + boolean b; } @lombok.EqualsAndHashCode(callSuper=false) diff --git a/usage_examples/DataExample_post.jpage b/usage_examples/DataExample_post.jpage index 896839de..29e7e328 100644 --- a/usage_examples/DataExample_post.jpage +++ b/usage_examples/DataExample_post.jpage @@ -55,7 +55,7 @@ public class DataExample { } @Override public int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; final long temp1 = Double.doubleToLongBits(this.getScore()); result = (result*PRIME) + (this.getName() == null ? 0 : this.getName().hashCode()); @@ -101,7 +101,7 @@ public class DataExample { } @Override public int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = (result*PRIME) + (this.getName() == null ? 0 : this.getName().hashCode()); result = (result*PRIME) + (this.getValue() == null ? 0 : this.getValue().hashCode()); diff --git a/usage_examples/EqualsAndHashCodeExample_post.jpage b/usage_examples/EqualsAndHashCodeExample_post.jpage index 57191f55..aa6a44ba 100644 --- a/usage_examples/EqualsAndHashCodeExample_post.jpage +++ b/usage_examples/EqualsAndHashCodeExample_post.jpage @@ -24,7 +24,7 @@ public class EqualsAndHashCodeExample { } @Override public int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; final long temp1 = Double.doubleToLongBits(this.score); result = (result*PRIME) + (this.name == null ? 0 : this.name.hashCode()); @@ -57,7 +57,7 @@ public class EqualsAndHashCodeExample { } @Override public int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; result = (result*PRIME) + super.hashCode(); result = (result*PRIME) + this.width; diff --git a/usage_examples/ValueExample_post.jpage b/usage_examples/ValueExample_post.jpage index c5971262..4ac8654e 100644 --- a/usage_examples/ValueExample_post.jpage +++ b/usage_examples/ValueExample_post.jpage @@ -46,7 +46,7 @@ public final class ValueExample { @java.lang.Override public int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; final Object $name = this.getName(); result = result * PRIME + ($name == null ? 0 : $name.hashCode()); @@ -103,7 +103,7 @@ public final class ValueExample { @java.lang.Override public int hashCode() { - final int PRIME = 277; + final int PRIME = 59; int result = 1; final Object $name = this.getName(); result = result * PRIME + ($name == null ? 0 : $name.hashCode()); -- cgit From d5c366e93ea19f286da2bdee16c0fdca8850b22a Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Tue, 21 Jan 2014 23:00:09 +0100 Subject: Issue 630: Several small documentation fixed for Log --- src/core/lombok/extern/slf4j/Slf4j.java | 3 ++- usage_examples/LogExample_post.jpage | 8 -------- usage_examples/LogExample_pre.jpage | 8 -------- website/features/Log.html | 2 +- 4 files changed, 3 insertions(+), 18 deletions(-) (limited to 'usage_examples') diff --git a/src/core/lombok/extern/slf4j/Slf4j.java b/src/core/lombok/extern/slf4j/Slf4j.java index 45942971..8490b6b6 100644 --- a/src/core/lombok/extern/slf4j/Slf4j.java +++ b/src/core/lombok/extern/slf4j/Slf4j.java @@ -52,7 +52,8 @@ import java.lang.annotation.Target; * @see lombok.extern.java.Log @Log * @see lombok.extern.log4j.Log4j @Log4j * @see lombok.extern.log4j.Log4j2 @Log4j2 - */ + * @see lombok.extern.slf4j.XSlf4j @XSlf4j + * */ @Retention(RetentionPolicy.SOURCE) @Target(ElementType.TYPE) public @interface Slf4j { diff --git a/usage_examples/LogExample_post.jpage b/usage_examples/LogExample_post.jpage index cbdc5a9e..2ec7f223 100644 --- a/usage_examples/LogExample_post.jpage +++ b/usage_examples/LogExample_post.jpage @@ -5,11 +5,3 @@ public class LogExample { log.error("Something's wrong here"); } } - -public class LogExampleOther { - private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(java.util.List.class); - - public static void main(String... args) { - log.warn("Something might be wrong here"); - } -} diff --git a/usage_examples/LogExample_pre.jpage b/usage_examples/LogExample_pre.jpage index 7ab64cd4..afabf369 100644 --- a/usage_examples/LogExample_pre.jpage +++ b/usage_examples/LogExample_pre.jpage @@ -7,11 +7,3 @@ public class LogExample { log.error("Something's wrong here"); } } - -@Log(java.util.List.class) -public class LogExampleOther { - - public static void main(String... args) { - log.warn("Something might be wrong here"); - } -} diff --git a/website/features/Log.html b/website/features/Log.html index 2d4fa375..f92af1e3 100644 --- a/website/features/Log.html +++ b/website/features/Log.html @@ -31,7 +31,7 @@
@Slf4j
Creates private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogExample.class);
@XSlf4j
-
Creates private static final org.slf4j.ext.XLogger log = org.slf4j.XLoggerFactory.getXLogger(LogExample.class);
+
Creates private static final org.slf4j.ext.XLogger log = org.slf4j.ext.XLoggerFactory.getXLogger(LogExample.class);

-- cgit From ce8362fad53b0016dba9fb01fcb68ba2dd7ade36 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Tue, 21 Jan 2014 23:09:54 +0100 Subject: Added extra example to the online documentation for @Log --- usage_examples/LogExample_post.jpage | 10 +++++++++- usage_examples/LogExample_pre.jpage | 11 ++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'usage_examples') diff --git a/usage_examples/LogExample_post.jpage b/usage_examples/LogExample_post.jpage index 2ec7f223..4ab35b08 100644 --- a/usage_examples/LogExample_post.jpage +++ b/usage_examples/LogExample_post.jpage @@ -1,7 +1,15 @@ public class LogExample { - private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogExample.class); + private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(LogExample.class.getName()); public static void main(String... args) { log.error("Something's wrong here"); } } + +public class LogExampleOther { + private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogExampleOther.class); + + public static void main(String... args) { + log.error("Something else is wrong here"); + } +} diff --git a/usage_examples/LogExample_pre.jpage b/usage_examples/LogExample_pre.jpage index afabf369..196a9047 100644 --- a/usage_examples/LogExample_pre.jpage +++ b/usage_examples/LogExample_pre.jpage @@ -1,4 +1,5 @@ -import lombok.extern.slf4j.Log; +import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; @Log public class LogExample { @@ -7,3 +8,11 @@ public class LogExample { log.error("Something's wrong here"); } } + +@Slf4j +public class LogExampleOther { + + public static void main(String... args) { + log.error("Something else is wrong here"); + } +} -- cgit From 52bb71582bcff166469b8a8be0960a24bc3f02b7 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Sat, 8 Feb 2014 21:03:17 +0100 Subject: Explained how to customise the category of the generated Log(ger) --- usage_examples/LogExample_post.jpage | 8 ++++++++ usage_examples/LogExample_pre.jpage | 8 ++++++++ website/features/Log.html | 2 ++ 3 files changed, 18 insertions(+) (limited to 'usage_examples') diff --git a/usage_examples/LogExample_post.jpage b/usage_examples/LogExample_post.jpage index 4ab35b08..eab3b046 100644 --- a/usage_examples/LogExample_post.jpage +++ b/usage_examples/LogExample_post.jpage @@ -13,3 +13,11 @@ public class LogExampleOther { log.error("Something else is wrong here"); } } + +public class LogExampleCategory { + private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog("CounterLog"); + + public static void main(String... args) { + log.error("Calling the 'CounterLog' with a message"); + } +} diff --git a/usage_examples/LogExample_pre.jpage b/usage_examples/LogExample_pre.jpage index 196a9047..fa746dba 100644 --- a/usage_examples/LogExample_pre.jpage +++ b/usage_examples/LogExample_pre.jpage @@ -16,3 +16,11 @@ public class LogExampleOther { log.error("Something else is wrong here"); } } + +@CommonsLog("CounterLog") +public class LogExampleCategory { + + public static void main(String... args) { + log.error("Calling the 'CounterLog' with a message"); + } +} diff --git a/website/features/Log.html b/website/features/Log.html index f92af1e3..e6b3ece6 100644 --- a/website/features/Log.html +++ b/website/features/Log.html @@ -33,6 +33,8 @@
@XSlf4j
Creates private static final org.slf4j.ext.XLogger log = org.slf4j.ext.XLoggerFactory.getXLogger(LogExample.class);
+

+ By default, the category (or name) of the logger will be the type where the annotation was placed. This can be customised by specifying a value for the category.

-- cgit From d78135180c8f9e9f4c6c361679759d3eacb63be3 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 10 Feb 2014 21:56:35 +0100 Subject: [deps] Updated eclipse deps to 3.9 tree. This also enables testing java7 features on ecj. [Log] updated naming for @Log (topic= instead of mchmulder's 'value'). --- AUTHORS | 2 +- .../ivy-repo/org.eclipse.custom-core.runtime-3.9.0.xml | 14 ++++++++++++++ buildScripts/ivy-repo/org.eclipse.custom-ecj-4.3.1.xml | 14 ++++++++++++++ .../org.eclipse.custom-equinox.common-3.6.200.xml | 14 ++++++++++++++ .../ivy-repo/org.eclipse.custom-jdt.core-3.9.1.xml | 14 ++++++++++++++ .../ivy-repo/org.eclipse.custom-jdt.ui-3.9.1.xml | 14 ++++++++++++++ .../ivy-repo/org.eclipse.custom-osgi-3.9.0.xml | 14 ++++++++++++++ buildScripts/ivy.xml | 12 ++++++------ src/core/lombok/eclipse/handlers/HandleLog.java | 12 ++++++------ src/core/lombok/extern/apachecommons/CommonsLog.java | 2 +- src/core/lombok/extern/java/Log.java | 2 +- src/core/lombok/extern/log4j/Log4j.java | 2 +- src/core/lombok/extern/log4j/Log4j2.java | 2 +- src/core/lombok/extern/slf4j/Slf4j.java | 2 +- src/core/lombok/extern/slf4j/XSlf4j.java | 2 +- src/core/lombok/javac/handlers/HandleLog.java | 14 ++++++-------- test/core/src/lombok/AbstractRunTests.java | 13 +++++++++++-- test/core/src/lombok/RunTestsViaEcj.java | 3 ++- test/transform/resource/after-ecj/LoggerCommons.java | 2 +- test/transform/resource/after-ecj/LoggerJul.java | 2 +- test/transform/resource/after-ecj/LoggerLog4j.java | 2 +- test/transform/resource/after-ecj/LoggerLog4j2.java | 2 +- test/transform/resource/after-ecj/LoggerSlf4j.java | 2 +- test/transform/resource/after-ecj/LoggerXSlf4j.java | 2 +- .../resource/after-ecj/NonNullWithSneakyThrows.java | 3 ++- .../resource/after-ecj/SneakyThrowsMultiple.java | 18 ++++++++++++------ .../resource/after-ecj/SneakyThrowsPlain.java | 12 ++++++++---- .../resource/after-ecj/SneakyThrowsSingle.java | 9 ++++++--- test/transform/resource/after-ecj/ValComplex.java | 2 +- .../resource/after-ecj/ValInTryWithResources.java | 14 ++++++++++++++ test/transform/resource/after-ecj/ValLessSimple.java | 3 ++- test/transform/resource/before/LoggerCommons.java | 2 +- test/transform/resource/before/LoggerJul.java | 2 +- test/transform/resource/before/LoggerLog4j.java | 2 +- test/transform/resource/before/LoggerLog4j2.java | 2 +- test/transform/resource/before/LoggerSlf4j.java | 2 +- test/transform/resource/before/LoggerXSlf4j.java | 2 +- usage_examples/LogExample_pre.jpage | 2 +- website/features/Log.html | 7 ++----- 39 files changed, 182 insertions(+), 64 deletions(-) create mode 100644 buildScripts/ivy-repo/org.eclipse.custom-core.runtime-3.9.0.xml create mode 100644 buildScripts/ivy-repo/org.eclipse.custom-ecj-4.3.1.xml create mode 100644 buildScripts/ivy-repo/org.eclipse.custom-equinox.common-3.6.200.xml create mode 100644 buildScripts/ivy-repo/org.eclipse.custom-jdt.core-3.9.1.xml create mode 100644 buildScripts/ivy-repo/org.eclipse.custom-jdt.ui-3.9.1.xml create mode 100644 buildScripts/ivy-repo/org.eclipse.custom-osgi-3.9.0.xml create mode 100644 test/transform/resource/after-ecj/ValInTryWithResources.java (limited to 'usage_examples') diff --git a/AUTHORS b/AUTHORS index 32369734..f79ca61e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,12 +1,12 @@ Lombok contributors in alphabetical order: Jappe van der Hel +Maarten Mulders Philipp Eichhorn Reinier Zwitserloot Robbert Jan Grootjans Roel Spilker Sander Koning Taiki Sugawara -Maarten Mulders By adding your name to this list, you grant full and irrevocable copyright and patent indemnity to Project Lombok and all use of Project Lombok, and you certify that you have the right to do so for all commits you add to Project Lombok. diff --git a/buildScripts/ivy-repo/org.eclipse.custom-core.runtime-3.9.0.xml b/buildScripts/ivy-repo/org.eclipse.custom-core.runtime-3.9.0.xml new file mode 100644 index 00000000..45d6a9c3 --- /dev/null +++ b/buildScripts/ivy-repo/org.eclipse.custom-core.runtime-3.9.0.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/buildScripts/ivy-repo/org.eclipse.custom-ecj-4.3.1.xml b/buildScripts/ivy-repo/org.eclipse.custom-ecj-4.3.1.xml new file mode 100644 index 00000000..4ebfc8a4 --- /dev/null +++ b/buildScripts/ivy-repo/org.eclipse.custom-ecj-4.3.1.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/buildScripts/ivy-repo/org.eclipse.custom-equinox.common-3.6.200.xml b/buildScripts/ivy-repo/org.eclipse.custom-equinox.common-3.6.200.xml new file mode 100644 index 00000000..74f7a705 --- /dev/null +++ b/buildScripts/ivy-repo/org.eclipse.custom-equinox.common-3.6.200.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/buildScripts/ivy-repo/org.eclipse.custom-jdt.core-3.9.1.xml b/buildScripts/ivy-repo/org.eclipse.custom-jdt.core-3.9.1.xml new file mode 100644 index 00000000..0e7c5363 --- /dev/null +++ b/buildScripts/ivy-repo/org.eclipse.custom-jdt.core-3.9.1.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/buildScripts/ivy-repo/org.eclipse.custom-jdt.ui-3.9.1.xml b/buildScripts/ivy-repo/org.eclipse.custom-jdt.ui-3.9.1.xml new file mode 100644 index 00000000..0577ee8a --- /dev/null +++ b/buildScripts/ivy-repo/org.eclipse.custom-jdt.ui-3.9.1.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/buildScripts/ivy-repo/org.eclipse.custom-osgi-3.9.0.xml b/buildScripts/ivy-repo/org.eclipse.custom-osgi-3.9.0.xml new file mode 100644 index 00000000..247d76de --- /dev/null +++ b/buildScripts/ivy-repo/org.eclipse.custom-osgi-3.9.0.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml index bcf5ecd1..eed69ac3 100644 --- a/buildScripts/ivy.xml +++ b/buildScripts/ivy.xml @@ -35,17 +35,17 @@ - + - - - - - + + + + + diff --git a/src/core/lombok/eclipse/handlers/HandleLog.java b/src/core/lombok/eclipse/handlers/HandleLog.java index 56160b39..cf1e8018 100644 --- a/src/core/lombok/eclipse/handlers/HandleLog.java +++ b/src/core/lombok/eclipse/handlers/HandleLog.java @@ -161,7 +161,7 @@ public class HandleLog { @ProviderFor(EclipseAnnotationHandler.class) public static class HandleCommonsLog extends EclipseAnnotationHandler { @Override public void handle(AnnotationValues annotation, Annotation source, EclipseNode annotationNode) { - processAnnotation(LoggingFramework.COMMONS, annotation, source, annotationNode, annotation.getInstance().value()); + processAnnotation(LoggingFramework.COMMONS, annotation, source, annotationNode, annotation.getInstance().topic()); } } @@ -171,7 +171,7 @@ public class HandleLog { @ProviderFor(EclipseAnnotationHandler.class) public static class HandleJulLog extends EclipseAnnotationHandler { @Override public void handle(AnnotationValues annotation, Annotation source, EclipseNode annotationNode) { - processAnnotation(LoggingFramework.JUL, annotation, source, annotationNode, annotation.getInstance().value()); + processAnnotation(LoggingFramework.JUL, annotation, source, annotationNode, annotation.getInstance().topic()); } } @@ -181,7 +181,7 @@ public class HandleLog { @ProviderFor(EclipseAnnotationHandler.class) public static class HandleLog4jLog extends EclipseAnnotationHandler { @Override public void handle(AnnotationValues annotation, Annotation source, EclipseNode annotationNode) { - processAnnotation(LoggingFramework.LOG4J, annotation, source, annotationNode, annotation.getInstance().value()); + processAnnotation(LoggingFramework.LOG4J, annotation, source, annotationNode, annotation.getInstance().topic()); } } @@ -191,7 +191,7 @@ public class HandleLog { @ProviderFor(EclipseAnnotationHandler.class) public static class HandleLog4j2Log extends EclipseAnnotationHandler { @Override public void handle(AnnotationValues annotation, Annotation source, EclipseNode annotationNode) { - processAnnotation(LoggingFramework.LOG4J2, annotation, source, annotationNode, annotation.getInstance().value()); + processAnnotation(LoggingFramework.LOG4J2, annotation, source, annotationNode, annotation.getInstance().topic()); } } @@ -201,7 +201,7 @@ public class HandleLog { @ProviderFor(EclipseAnnotationHandler.class) public static class HandleSlf4jLog extends EclipseAnnotationHandler { @Override public void handle(AnnotationValues annotation, Annotation source, EclipseNode annotationNode) { - processAnnotation(LoggingFramework.SLF4J, annotation, source, annotationNode, annotation.getInstance().value()); + processAnnotation(LoggingFramework.SLF4J, annotation, source, annotationNode, annotation.getInstance().topic()); } } @@ -211,7 +211,7 @@ public class HandleLog { @ProviderFor(EclipseAnnotationHandler.class) public static class HandleXSlf4jLog extends EclipseAnnotationHandler { @Override public void handle(AnnotationValues annotation, Annotation source, EclipseNode annotationNode) { - processAnnotation(LoggingFramework.XSLF4J, annotation, source, annotationNode, annotation.getInstance().value()); + processAnnotation(LoggingFramework.XSLF4J, annotation, source, annotationNode, annotation.getInstance().topic()); } } diff --git a/src/core/lombok/extern/apachecommons/CommonsLog.java b/src/core/lombok/extern/apachecommons/CommonsLog.java index 34ac0fe6..2e31edf7 100644 --- a/src/core/lombok/extern/apachecommons/CommonsLog.java +++ b/src/core/lombok/extern/apachecommons/CommonsLog.java @@ -62,5 +62,5 @@ public @interface CommonsLog { /** * Sets the category of the constructed Logger. By default, it will use the type where the annotation is placed. */ - String value() default ""; + String topic() default ""; } \ No newline at end of file diff --git a/src/core/lombok/extern/java/Log.java b/src/core/lombok/extern/java/Log.java index dfa2e2aa..f8cbf03f 100644 --- a/src/core/lombok/extern/java/Log.java +++ b/src/core/lombok/extern/java/Log.java @@ -61,5 +61,5 @@ public @interface Log { /** * Sets the category of the constructed Logger. By default, it will use the type where the annotation is placed. */ - String value() default ""; + String topic() default ""; } \ No newline at end of file diff --git a/src/core/lombok/extern/log4j/Log4j.java b/src/core/lombok/extern/log4j/Log4j.java index 0fe74599..d3164047 100644 --- a/src/core/lombok/extern/log4j/Log4j.java +++ b/src/core/lombok/extern/log4j/Log4j.java @@ -62,5 +62,5 @@ public @interface Log4j { /** * Sets the category of the constructed Logger. By default, it will use the type where the annotation is placed. */ - String value() default ""; + String topic() default ""; } \ No newline at end of file diff --git a/src/core/lombok/extern/log4j/Log4j2.java b/src/core/lombok/extern/log4j/Log4j2.java index 96fab793..0267d98c 100644 --- a/src/core/lombok/extern/log4j/Log4j2.java +++ b/src/core/lombok/extern/log4j/Log4j2.java @@ -62,5 +62,5 @@ public @interface Log4j2 { /** * Sets the category of the constructed Logger. By default, it will use the type where the annotation is placed. */ - String value() default ""; + String topic() default ""; } \ No newline at end of file diff --git a/src/core/lombok/extern/slf4j/Slf4j.java b/src/core/lombok/extern/slf4j/Slf4j.java index c4495990..5d6e7d8c 100644 --- a/src/core/lombok/extern/slf4j/Slf4j.java +++ b/src/core/lombok/extern/slf4j/Slf4j.java @@ -60,5 +60,5 @@ public @interface Slf4j { /** * Sets the category of the constructed Logger. By default, it will use the type where the annotation is placed. */ - String value() default ""; + String topic() default ""; } diff --git a/src/core/lombok/extern/slf4j/XSlf4j.java b/src/core/lombok/extern/slf4j/XSlf4j.java index 306057f0..0f2efe26 100644 --- a/src/core/lombok/extern/slf4j/XSlf4j.java +++ b/src/core/lombok/extern/slf4j/XSlf4j.java @@ -60,5 +60,5 @@ public @interface XSlf4j { /** * Sets the category of the constructed Logger. By default, it will use the type where the annotation is placed. */ - String value() default ""; + String topic() default ""; } diff --git a/src/core/lombok/javac/handlers/HandleLog.java b/src/core/lombok/javac/handlers/HandleLog.java index 12b0cb5c..36f3bbb5 100644 --- a/src/core/lombok/javac/handlers/HandleLog.java +++ b/src/core/lombok/javac/handlers/HandleLog.java @@ -25,9 +25,7 @@ import static lombok.javac.handlers.JavacHandlerUtil.*; import java.lang.annotation.Annotation; -import lombok.NoArgsConstructor; import lombok.core.AnnotationValues; -import lombok.extern.slf4j.Slf4j; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; @@ -111,7 +109,7 @@ public class HandleLog { @ProviderFor(JavacAnnotationHandler.class) public static class HandleCommonsLog extends JavacAnnotationHandler { @Override public void handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { - processAnnotation(LoggingFramework.COMMONS, annotation, annotationNode, annotation.getInstance().value()); + processAnnotation(LoggingFramework.COMMONS, annotation, annotationNode, annotation.getInstance().topic()); } } @@ -121,7 +119,7 @@ public class HandleLog { @ProviderFor(JavacAnnotationHandler.class) public static class HandleJulLog extends JavacAnnotationHandler { @Override public void handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { - processAnnotation(LoggingFramework.JUL, annotation, annotationNode, annotation.getInstance().value()); + processAnnotation(LoggingFramework.JUL, annotation, annotationNode, annotation.getInstance().topic()); } } @@ -131,7 +129,7 @@ public class HandleLog { @ProviderFor(JavacAnnotationHandler.class) public static class HandleLog4jLog extends JavacAnnotationHandler { @Override public void handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { - processAnnotation(LoggingFramework.LOG4J, annotation, annotationNode, annotation.getInstance().value()); + processAnnotation(LoggingFramework.LOG4J, annotation, annotationNode, annotation.getInstance().topic()); } } @@ -141,7 +139,7 @@ public class HandleLog { @ProviderFor(JavacAnnotationHandler.class) public static class HandleLog4j2Log extends JavacAnnotationHandler { @Override public void handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { - processAnnotation(LoggingFramework.LOG4J2, annotation, annotationNode, annotation.getInstance().value()); + processAnnotation(LoggingFramework.LOG4J2, annotation, annotationNode, annotation.getInstance().topic()); } } @@ -151,7 +149,7 @@ public class HandleLog { @ProviderFor(JavacAnnotationHandler.class) public static class HandleSlf4jLog extends JavacAnnotationHandler { @Override public void handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { - processAnnotation(LoggingFramework.SLF4J, annotation, annotationNode, annotation.getInstance().value()); + processAnnotation(LoggingFramework.SLF4J, annotation, annotationNode, annotation.getInstance().topic()); } } @@ -161,7 +159,7 @@ public class HandleLog { @ProviderFor(JavacAnnotationHandler.class) public static class HandleXSlf4jLog extends JavacAnnotationHandler { @Override public void handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { - processAnnotation(LoggingFramework.XSLF4J, annotation, annotationNode, annotation.getInstance().value()); + processAnnotation(LoggingFramework.XSLF4J, annotation, annotationNode, annotation.getInstance().topic()); } } diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java index 2f3f0988..e84aec0d 100644 --- a/test/core/src/lombok/AbstractRunTests.java +++ b/test/core/src/lombok/AbstractRunTests.java @@ -225,8 +225,8 @@ public abstract class AbstractRunTests { actualLines = removeBlanks(actualLines); int size = Math.min(expectedLines.length, actualLines.length); for (int i = 0; i < size; i++) { - String expected = expectedLines[i]; - String actual = actualLines[i]; + String expected = trimRight(expectedLines[i]); + String actual = trimRight(actualLines[i]); assertEquals(String.format("Difference in %s on line %d", name, i + 1), expected, actual); } if (expectedLines.length > actualLines.length) { @@ -237,6 +237,15 @@ public abstract class AbstractRunTests { } } + private static String trimRight(String in) { + int endIdx = in.length() - 1; + while (endIdx > -1 && Character.isWhitespace(in.charAt(endIdx))) { + endIdx--; + } + + return in.substring(0, endIdx); + } + private static String[] removeBlanks(String[] in) { List out = new ArrayList(); for (String s : in) { diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index 586c124a..4f3e2794 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2013 The Project Lombok Authors. + * Copyright (C) 2010-2014 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -70,6 +70,7 @@ public class RunTestsViaEcj extends AbstractRunTests { warnings.put(CompilerOptions.OPTION_ReportUnusedLabel, "ignore"); warnings.put(CompilerOptions.OPTION_ReportUnusedImport, "ignore"); warnings.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, "ignore"); + warnings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_7); options.set(warnings); return options; } diff --git a/test/transform/resource/after-ecj/LoggerCommons.java b/test/transform/resource/after-ecj/LoggerCommons.java index 50d07a14..df102a12 100644 --- a/test/transform/resource/after-ecj/LoggerCommons.java +++ b/test/transform/resource/after-ecj/LoggerCommons.java @@ -15,7 +15,7 @@ import lombok.extern.apachecommons.CommonsLog; super(); } } -@CommonsLog("DifferentName") class LoggerCommonsWithDifferentName { +@CommonsLog(topic = "DifferentName") class LoggerCommonsWithDifferentName { private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog("DifferentName"); () { } diff --git a/test/transform/resource/after-ecj/LoggerJul.java b/test/transform/resource/after-ecj/LoggerJul.java index 3aa8181d..8aa4f59a 100644 --- a/test/transform/resource/after-ecj/LoggerJul.java +++ b/test/transform/resource/after-ecj/LoggerJul.java @@ -15,7 +15,7 @@ import lombok.extern.java.Log; super(); } } -@Log("DifferentName") class LoggerJulWithDifferentName { +@Log(topic = "DifferentName") class LoggerJulWithDifferentName { private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger("DifferentName"); () { } diff --git a/test/transform/resource/after-ecj/LoggerLog4j.java b/test/transform/resource/after-ecj/LoggerLog4j.java index a6c52d61..948412e2 100644 --- a/test/transform/resource/after-ecj/LoggerLog4j.java +++ b/test/transform/resource/after-ecj/LoggerLog4j.java @@ -15,7 +15,7 @@ import lombok.extern.log4j.Log4j; super(); } } -@Log4j("DifferentName") class LoggerLog4jWithDifferentName { +@Log4j(topic = "DifferentName") class LoggerLog4jWithDifferentName { private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("DifferentName"); () { } diff --git a/test/transform/resource/after-ecj/LoggerLog4j2.java b/test/transform/resource/after-ecj/LoggerLog4j2.java index 3243ef2d..c2fcd428 100644 --- a/test/transform/resource/after-ecj/LoggerLog4j2.java +++ b/test/transform/resource/after-ecj/LoggerLog4j2.java @@ -15,7 +15,7 @@ import lombok.extern.log4j.Log4j2; super(); } } -@Log4j2("DifferentName") class LoggerLog4j2WithDifferentName { +@Log4j2(topic = "DifferentName") class LoggerLog4j2WithDifferentName { private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger("DifferentName"); () { } diff --git a/test/transform/resource/after-ecj/LoggerSlf4j.java b/test/transform/resource/after-ecj/LoggerSlf4j.java index a34f85d7..9c5405cb 100644 --- a/test/transform/resource/after-ecj/LoggerSlf4j.java +++ b/test/transform/resource/after-ecj/LoggerSlf4j.java @@ -29,7 +29,7 @@ class LoggerSlf4jOuter { } } -@Slf4j("DifferentLogger") class LoggerSlf4jWithDifferentLoggerName { +@Slf4j(topic = "DifferentLogger") class LoggerSlf4jWithDifferentLoggerName { private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger("DifferentLogger"); () { } diff --git a/test/transform/resource/after-ecj/LoggerXSlf4j.java b/test/transform/resource/after-ecj/LoggerXSlf4j.java index 4cd4cb94..916859a4 100644 --- a/test/transform/resource/after-ecj/LoggerXSlf4j.java +++ b/test/transform/resource/after-ecj/LoggerXSlf4j.java @@ -15,7 +15,7 @@ import lombok.extern.slf4j.XSlf4j; super(); } } -@XSlf4j("DifferentName") class LoggerXSlf4jWithDifferentName { +@XSlf4j(topic = "DifferentName") class LoggerXSlf4jWithDifferentName { private static final org.slf4j.ext.XLogger log = org.slf4j.ext.XLoggerFactory.getXLogger("DifferentName"); () { } diff --git a/test/transform/resource/after-ecj/NonNullWithSneakyThrows.java b/test/transform/resource/after-ecj/NonNullWithSneakyThrows.java index fac8dcdd..1a57be29 100644 --- a/test/transform/resource/after-ecj/NonNullWithSneakyThrows.java +++ b/test/transform/resource/after-ecj/NonNullWithSneakyThrows.java @@ -11,7 +11,8 @@ class NonNullWithSneakyThrows { } System.out.println(in); } - catch (final java.lang.Throwable $ex) { + catch (final java.lang.Throwable $ex) + { throw lombok.Lombok.sneakyThrow($ex); } } diff --git a/test/transform/resource/after-ecj/SneakyThrowsMultiple.java b/test/transform/resource/after-ecj/SneakyThrowsMultiple.java index 82eda411..65862c2b 100644 --- a/test/transform/resource/after-ecj/SneakyThrowsMultiple.java +++ b/test/transform/resource/after-ecj/SneakyThrowsMultiple.java @@ -13,11 +13,13 @@ class SneakyThrowsMultiple { System.out.println("test1"); throw new IOException(); } - catch (final IOException $ex) { + catch (final IOException $ex) + { throw lombok.Lombok.sneakyThrow($ex); } } - catch (final Throwable $ex) { + catch (final Throwable $ex) + { throw lombok.Lombok.sneakyThrow($ex); } } @@ -36,11 +38,13 @@ class SneakyThrowsMultiple { throw new AWTException("WHAT"); } } - catch (final AWTException $ex) { + catch (final AWTException $ex) + { throw lombok.Lombok.sneakyThrow($ex); } } - catch (final IOException $ex) { + catch (final IOException $ex) + { throw lombok.Lombok.sneakyThrow($ex); } } @@ -52,11 +56,13 @@ class SneakyThrowsMultiple { System.out.println("test3"); throw new IOException(); } - catch (final IOException $ex) { + catch (final IOException $ex) + { throw lombok.Lombok.sneakyThrow($ex); } } - catch (final Throwable $ex) { + catch (final Throwable $ex) + { throw lombok.Lombok.sneakyThrow($ex); } } diff --git a/test/transform/resource/after-ecj/SneakyThrowsPlain.java b/test/transform/resource/after-ecj/SneakyThrowsPlain.java index 1b45dc5a..df436891 100644 --- a/test/transform/resource/after-ecj/SneakyThrowsPlain.java +++ b/test/transform/resource/after-ecj/SneakyThrowsPlain.java @@ -6,7 +6,8 @@ class SneakyThrowsPlain { { System.out.println("constructor"); } - catch (final java.lang.Throwable $ex) { + catch (final java.lang.Throwable $ex) + { throw lombok.Lombok.sneakyThrow($ex); } } @@ -16,7 +17,8 @@ class SneakyThrowsPlain { { System.out.println("constructor2"); } - catch (final java.lang.Throwable $ex) { + catch (final java.lang.Throwable $ex) + { throw lombok.Lombok.sneakyThrow($ex); } } @@ -25,7 +27,8 @@ class SneakyThrowsPlain { { System.out.println("test1"); } - catch (final java.lang.Throwable $ex) { + catch (final java.lang.Throwable $ex) + { throw lombok.Lombok.sneakyThrow($ex); } } @@ -34,7 +37,8 @@ class SneakyThrowsPlain { { System.out.println("test2"); } - catch (final java.lang.Throwable $ex) { + catch (final java.lang.Throwable $ex) + { throw lombok.Lombok.sneakyThrow($ex); } } diff --git a/test/transform/resource/after-ecj/SneakyThrowsSingle.java b/test/transform/resource/after-ecj/SneakyThrowsSingle.java index eea593f2..073d690a 100644 --- a/test/transform/resource/after-ecj/SneakyThrowsSingle.java +++ b/test/transform/resource/after-ecj/SneakyThrowsSingle.java @@ -8,7 +8,8 @@ class SneakyThrowsSingle { { System.out.println("test1"); } - catch (final Throwable $ex) { + catch (final Throwable $ex) + { throw lombok.Lombok.sneakyThrow($ex); } } @@ -18,7 +19,8 @@ class SneakyThrowsSingle { System.out.println("test2"); throw new IOException(); } - catch (final IOException $ex) { + catch (final IOException $ex) + { throw lombok.Lombok.sneakyThrow($ex); } } @@ -28,7 +30,8 @@ class SneakyThrowsSingle { System.out.println("test3"); throw new IOException(); } - catch (final IOException $ex) { + catch (final IOException $ex) + { throw lombok.Lombok.sneakyThrow($ex); } } diff --git a/test/transform/resource/after-ecj/ValComplex.java b/test/transform/resource/after-ecj/ValComplex.java index 6e435e56..746e3088 100644 --- a/test/transform/resource/after-ecj/ValComplex.java +++ b/test/transform/resource/after-ecj/ValComplex.java @@ -16,7 +16,7 @@ public class ValComplex { final @val int field = 20; final @val int inner = 10; switch (field) { - case 5 : ; + case 5 : final @val char[] shouldBeCharArray2 = shouldBeCharArray; final @val int innerInner = inner; } diff --git a/test/transform/resource/after-ecj/ValInTryWithResources.java b/test/transform/resource/after-ecj/ValInTryWithResources.java new file mode 100644 index 00000000..a532d48c --- /dev/null +++ b/test/transform/resource/after-ecj/ValInTryWithResources.java @@ -0,0 +1,14 @@ +import lombok.val; +import java.io.IOException; +public class ValInTryWithResources { + public ValInTryWithResources() { + super(); + } + public void whyTryInsteadOfCleanup() throws IOException { + try (final @val java.io.InputStream in = getClass().getResourceAsStream("ValInTryWithResources.class")) + { + final @val java.io.InputStream i = in; + final @val int j = in.read(); + } + } +} diff --git a/test/transform/resource/after-ecj/ValLessSimple.java b/test/transform/resource/after-ecj/ValLessSimple.java index c7587f91..28772d68 100644 --- a/test/transform/resource/after-ecj/ValLessSimple.java +++ b/test/transform/resource/after-ecj/ValLessSimple.java @@ -32,7 +32,8 @@ public class ValLessSimple { { final @val int x = (1 / 0); } - catch (ArithmeticException e) { + catch (ArithmeticException e) + { final @val int y = 0; } } diff --git a/test/transform/resource/before/LoggerCommons.java b/test/transform/resource/before/LoggerCommons.java index ce9e4ec4..00419d00 100644 --- a/test/transform/resource/before/LoggerCommons.java +++ b/test/transform/resource/before/LoggerCommons.java @@ -8,6 +8,6 @@ class LoggerCommons { class LoggerCommonsWithImport { } -@CommonsLog("DifferentName") +@CommonsLog(topic="DifferentName") class LoggerCommonsWithDifferentName { } diff --git a/test/transform/resource/before/LoggerJul.java b/test/transform/resource/before/LoggerJul.java index 41e36220..006cc344 100644 --- a/test/transform/resource/before/LoggerJul.java +++ b/test/transform/resource/before/LoggerJul.java @@ -8,6 +8,6 @@ class LoggerJul { class LoggerJulWithImport { } -@Log("DifferentName") +@Log(topic="DifferentName") class LoggerJulWithDifferentName { } \ No newline at end of file diff --git a/test/transform/resource/before/LoggerLog4j.java b/test/transform/resource/before/LoggerLog4j.java index fa7dad4a..351049c5 100644 --- a/test/transform/resource/before/LoggerLog4j.java +++ b/test/transform/resource/before/LoggerLog4j.java @@ -8,6 +8,6 @@ class LoggerLog4j { class LoggerLog4jWithImport { } -@Log4j("DifferentName") +@Log4j(topic="DifferentName") class LoggerLog4jWithDifferentName { } \ No newline at end of file diff --git a/test/transform/resource/before/LoggerLog4j2.java b/test/transform/resource/before/LoggerLog4j2.java index 13b3605f..c9cf9412 100644 --- a/test/transform/resource/before/LoggerLog4j2.java +++ b/test/transform/resource/before/LoggerLog4j2.java @@ -8,6 +8,6 @@ class LoggerLog4j2 { class LoggerLog4j2WithImport { } -@Log4j2("DifferentName") +@Log4j2(topic="DifferentName") class LoggerLog4j2WithDifferentName { } \ No newline at end of file diff --git a/test/transform/resource/before/LoggerSlf4j.java b/test/transform/resource/before/LoggerSlf4j.java index b620e056..1113a63e 100644 --- a/test/transform/resource/before/LoggerSlf4j.java +++ b/test/transform/resource/before/LoggerSlf4j.java @@ -15,6 +15,6 @@ class LoggerSlf4jOuter { } } -@Slf4j("DifferentLogger") +@Slf4j(topic="DifferentLogger") class LoggerSlf4jWithDifferentLoggerName { } \ No newline at end of file diff --git a/test/transform/resource/before/LoggerXSlf4j.java b/test/transform/resource/before/LoggerXSlf4j.java index 408bd134..a8bcb0c3 100644 --- a/test/transform/resource/before/LoggerXSlf4j.java +++ b/test/transform/resource/before/LoggerXSlf4j.java @@ -8,6 +8,6 @@ class LoggerXSlf4j { class LoggerXSlf4jWithImport { } -@XSlf4j("DifferentName") +@XSlf4j(topic="DifferentName") class LoggerXSlf4jWithDifferentName { } \ No newline at end of file diff --git a/usage_examples/LogExample_pre.jpage b/usage_examples/LogExample_pre.jpage index fa746dba..ba27dd27 100644 --- a/usage_examples/LogExample_pre.jpage +++ b/usage_examples/LogExample_pre.jpage @@ -17,7 +17,7 @@ public class LogExampleOther { } } -@CommonsLog("CounterLog") +@CommonsLog(topic="CounterLog") public class LogExampleCategory { public static void main(String... args) { diff --git a/website/features/Log.html b/website/features/Log.html index e6b3ece6..bc9e017e 100644 --- a/website/features/Log.html +++ b/website/features/Log.html @@ -34,7 +34,7 @@
Creates private static final org.slf4j.ext.XLogger log = org.slf4j.ext.XLoggerFactory.getXLogger(LogExample.class);

- By default, the category (or name) of the logger will be the type where the annotation was placed. This can be customised by specifying a value for the category. + By default, the topic (or name) of the logger will be the class name of the class annotated with the @Log annotation. This can be customised by specifying the topic parameter. For example: @XSlf4j(topic="reporting").

@@ -54,10 +54,7 @@

If a field called log already exists, a warning will be emitted and no code will be generated.

- A future feature of lombok's diverse log annotations is to find calls to the logger field and, if the chosen logging framework supports - it and the log level can be compile-time determined from the log call, guard it with an if statement. This way if - the log statement ends up being ignored, the potentially expensive calculation of the log string is avoided entirely. This does mean - that you should NOT put any side-effects in the expression that you log. + A future feature of lombok's diverse log annotations is to find calls to the logger field and, if the chosen logging framework supports it and the log level can be compile-time determined from the log call, guard it with an if statement. This way if the log statement ends up being ignored, the potentially expensive calculation of the log string is avoided entirely. This does mean that you should NOT put any side-effects in the expression that you log.

-- cgit