From 1c323332493148f0aaa936e668e1b0da5d09c8be Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Thu, 11 Nov 2010 01:58:48 +0100 Subject: @Getter(lazy=true) support for javac --- .../resource/after-delombok/GetterLazy.java | 19 ++++ .../after-delombok/GetterLazyEahcToString.java | 44 ++++++++ .../resource/after-delombok/GetterLazyInvalid.java | 22 ++++ .../resource/after-delombok/GetterLazyNative.java | 124 +++++++++++++++++++++ test/transform/resource/before/GetterLazy.java | 7 ++ .../resource/before/GetterLazyEahcToString.java | 6 + .../resource/before/GetterLazyInvalid.java | 24 ++++ .../resource/before/GetterLazyNative.java | 25 +++++ .../GetterLazyInvalid.java.messages | 6 + 9 files changed, 277 insertions(+) create mode 100644 test/transform/resource/after-delombok/GetterLazy.java create mode 100644 test/transform/resource/after-delombok/GetterLazyEahcToString.java create mode 100644 test/transform/resource/after-delombok/GetterLazyInvalid.java create mode 100644 test/transform/resource/after-delombok/GetterLazyNative.java create mode 100644 test/transform/resource/before/GetterLazy.java create mode 100644 test/transform/resource/before/GetterLazyEahcToString.java create mode 100644 test/transform/resource/before/GetterLazyInvalid.java create mode 100644 test/transform/resource/before/GetterLazyNative.java create mode 100644 test/transform/resource/messages-delombok/GetterLazyInvalid.java.messages (limited to 'test') diff --git a/test/transform/resource/after-delombok/GetterLazy.java b/test/transform/resource/after-delombok/GetterLazy.java new file mode 100644 index 00000000..d7f97f0d --- /dev/null +++ b/test/transform/resource/after-delombok/GetterLazy.java @@ -0,0 +1,19 @@ +class GetterLazy { + static class ValueType { + } + private final java.util.concurrent.atomic.AtomicReference> fieldName = new java.util.concurrent.atomic.AtomicReference>(); + @java.lang.SuppressWarnings("all") + public ValueType getFieldName() { + java.util.concurrent.atomic.AtomicReference value = this.fieldName.get(); + if (value == null) { + synchronized (this.fieldName) { + value = this.fieldName.get(); + if (value == null) { + value = new java.util.concurrent.atomic.AtomicReference(new ValueType()); + this.fieldName.set(value); + } + } + } + return value.get(); + } +} diff --git a/test/transform/resource/after-delombok/GetterLazyEahcToString.java b/test/transform/resource/after-delombok/GetterLazyEahcToString.java new file mode 100644 index 00000000..7d37e46b --- /dev/null +++ b/test/transform/resource/after-delombok/GetterLazyEahcToString.java @@ -0,0 +1,44 @@ +class GetterLazyEahcToString { + private final java.util.concurrent.atomic.AtomicReference> value = new java.util.concurrent.atomic.AtomicReference>(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof GetterLazyEahcToString)) return false; + final GetterLazyEahcToString other = (GetterLazyEahcToString)o; + if (!other.canEqual(this)) return false; + if (this.getValue() == null ? other.getValue() != null : !this.getValue().equals(other.getValue())) return false; + return true; + } + @java.lang.SuppressWarnings("all") + public boolean canEqual(final java.lang.Object other) { + return other instanceof GetterLazyEahcToString; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = result * PRIME + (this.getValue() == null ? 0 : this.getValue().hashCode()); + return result; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "GetterLazyEahcToString(value=" + this.getValue() + ")"; + } + @java.lang.SuppressWarnings("all") + public String getValue() { + java.util.concurrent.atomic.AtomicReference value = this.value.get(); + if (value == null) { + synchronized (this.value) { + value = this.value.get(); + if (value == null) { + value = new java.util.concurrent.atomic.AtomicReference(""); + this.value.set(value); + } + } + } + return value.get(); + } +} \ No newline at end of file diff --git a/test/transform/resource/after-delombok/GetterLazyInvalid.java b/test/transform/resource/after-delombok/GetterLazyInvalid.java new file mode 100644 index 00000000..78cb7c2d --- /dev/null +++ b/test/transform/resource/after-delombok/GetterLazyInvalid.java @@ -0,0 +1,22 @@ +class GetterLazyInvalidNotFinal { + private String fieldName = ""; +} +class GetterLazyInvalidNotPrivate { + final String fieldName = ""; +} +class GetterLazyInvalidNotPrivateFinal { + String fieldName = ""; +} +class GetterLazyInvalidNone { + String fieldName = ""; +} +class GetterLazyInvalidClass { + String fieldName = ""; + @java.lang.SuppressWarnings("all") + public String getFieldName() { + return this.fieldName; + } +} +class GetterLazyInvalidNoInit { + String fieldName; +} \ No newline at end of file diff --git a/test/transform/resource/after-delombok/GetterLazyNative.java b/test/transform/resource/after-delombok/GetterLazyNative.java new file mode 100644 index 00000000..ffa0824b --- /dev/null +++ b/test/transform/resource/after-delombok/GetterLazyNative.java @@ -0,0 +1,124 @@ +class GetterLazyNative { + + private final java.util.concurrent.atomic.AtomicReference> booleanField = new java.util.concurrent.atomic.AtomicReference>(); + private final java.util.concurrent.atomic.AtomicReference> byteField = new java.util.concurrent.atomic.AtomicReference>(); + private final java.util.concurrent.atomic.AtomicReference> shortField = new java.util.concurrent.atomic.AtomicReference>(); + private final java.util.concurrent.atomic.AtomicReference> intField = new java.util.concurrent.atomic.AtomicReference>(); + private final java.util.concurrent.atomic.AtomicReference> longField = new java.util.concurrent.atomic.AtomicReference>(); + private final java.util.concurrent.atomic.AtomicReference> floatField = new java.util.concurrent.atomic.AtomicReference>(); + private final java.util.concurrent.atomic.AtomicReference> doubleField = new java.util.concurrent.atomic.AtomicReference>(); + private final java.util.concurrent.atomic.AtomicReference> charField = new java.util.concurrent.atomic.AtomicReference>(); + + @java.lang.SuppressWarnings("all") + public boolean getBooleanField() { + java.util.concurrent.atomic.AtomicReference value = this.booleanField.get(); + if (value == null) { + synchronized (this.booleanField) { + value = this.booleanField.get(); + if (value == null) { + value = new java.util.concurrent.atomic.AtomicReference(true); + this.booleanField.set(value); + } + } + } + return value.get(); + } + @java.lang.SuppressWarnings("all") + public byte getByteField() { + java.util.concurrent.atomic.AtomicReference value = this.byteField.get(); + if (value == null) { + synchronized (this.byteField) { + value = this.byteField.get(); + if (value == null) { + value = new java.util.concurrent.atomic.AtomicReference(1); + this.byteField.set(value); + } + } + } + return value.get(); + } + @java.lang.SuppressWarnings("all") + public short getShortField() { + java.util.concurrent.atomic.AtomicReference value = this.shortField.get(); + if (value == null) { + synchronized (this.shortField) { + value = this.shortField.get(); + if (value == null) { + value = new java.util.concurrent.atomic.AtomicReference(1); + this.shortField.set(value); + } + } + } + return value.get(); + } + @java.lang.SuppressWarnings("all") + public int getIntField() { + java.util.concurrent.atomic.AtomicReference value = this.intField.get(); + if (value == null) { + synchronized (this.intField) { + value = this.intField.get(); + if (value == null) { + value = new java.util.concurrent.atomic.AtomicReference(1); + this.intField.set(value); + } + } + } + return value.get(); + } + @java.lang.SuppressWarnings("all") + public long getLongField() { + java.util.concurrent.atomic.AtomicReference value = this.longField.get(); + if (value == null) { + synchronized (this.longField) { + value = this.longField.get(); + if (value == null) { + value = new java.util.concurrent.atomic.AtomicReference(1); + this.longField.set(value); + } + } + } + return value.get(); + } + @java.lang.SuppressWarnings("all") + public float getFloatField() { + java.util.concurrent.atomic.AtomicReference value = this.floatField.get(); + if (value == null) { + synchronized (this.floatField) { + value = this.floatField.get(); + if (value == null) { + value = new java.util.concurrent.atomic.AtomicReference(1.0F); + this.floatField.set(value); + } + } + } + return value.get(); + } + @java.lang.SuppressWarnings("all") + public double getDoubleField() { + java.util.concurrent.atomic.AtomicReference value = this.doubleField.get(); + if (value == null) { + synchronized (this.doubleField) { + value = this.doubleField.get(); + if (value == null) { + value = new java.util.concurrent.atomic.AtomicReference(1.0); + this.doubleField.set(value); + } + } + } + return value.get(); + } + @java.lang.SuppressWarnings("all") + public char getCharField() { + java.util.concurrent.atomic.AtomicReference value = this.charField.get(); + if (value == null) { + synchronized (this.charField) { + value = this.charField.get(); + if (value == null) { + value = new java.util.concurrent.atomic.AtomicReference('1'); + this.charField.set(value); + } + } + } + return value.get(); + } +} diff --git a/test/transform/resource/before/GetterLazy.java b/test/transform/resource/before/GetterLazy.java new file mode 100644 index 00000000..51c7a921 --- /dev/null +++ b/test/transform/resource/before/GetterLazy.java @@ -0,0 +1,7 @@ +class GetterLazy { + static class ValueType { + } + + @lombok.Getter(lazy=true) + private final ValueType fieldName = new ValueType(); +} diff --git a/test/transform/resource/before/GetterLazyEahcToString.java b/test/transform/resource/before/GetterLazyEahcToString.java new file mode 100644 index 00000000..60509257 --- /dev/null +++ b/test/transform/resource/before/GetterLazyEahcToString.java @@ -0,0 +1,6 @@ +@lombok.EqualsAndHashCode(doNotUseGetters = true) +@lombok.ToString(doNotUseGetters = true) +class GetterLazyEahcToString { + @lombok.Getter(lazy=true) + private final String value = ""; +} diff --git a/test/transform/resource/before/GetterLazyInvalid.java b/test/transform/resource/before/GetterLazyInvalid.java new file mode 100644 index 00000000..ead12443 --- /dev/null +++ b/test/transform/resource/before/GetterLazyInvalid.java @@ -0,0 +1,24 @@ +class GetterLazyInvalidNotFinal { + @lombok.Getter(lazy=true) + private String fieldName = ""; +} +class GetterLazyInvalidNotPrivate { + @lombok.Getter(lazy=true) + final String fieldName = ""; +} +class GetterLazyInvalidNotPrivateFinal { + @lombok.Getter(lazy=true) + String fieldName = ""; +} +class GetterLazyInvalidNone { + @lombok.Getter(lazy=true, value=lombok.AccessLevel.NONE) + String fieldName = ""; +} +@lombok.Getter(lazy = true) +class GetterLazyInvalidClass { + String fieldName = ""; +} +class GetterLazyInvalidNoInit { + @lombok.Getter(lazy = true) + String fieldName; +} diff --git a/test/transform/resource/before/GetterLazyNative.java b/test/transform/resource/before/GetterLazyNative.java new file mode 100644 index 00000000..bd14cbd7 --- /dev/null +++ b/test/transform/resource/before/GetterLazyNative.java @@ -0,0 +1,25 @@ +class GetterLazyNative { + @lombok.Getter(lazy=true) + private final boolean booleanField = true; + + @lombok.Getter(lazy=true) + private final byte byteField = 1; + + @lombok.Getter(lazy=true) + private final short shortField = 1; + + @lombok.Getter(lazy=true) + private final int intField = 1; + + @lombok.Getter(lazy=true) + private final long longField = 1; + + @lombok.Getter(lazy=true) + private final float floatField = 1.0f; + + @lombok.Getter(lazy=true) + private final double doubleField = 1.0; + + @lombok.Getter(lazy=true) + private final char charField = '1'; +} diff --git a/test/transform/resource/messages-delombok/GetterLazyInvalid.java.messages b/test/transform/resource/messages-delombok/GetterLazyInvalid.java.messages new file mode 100644 index 00000000..b53b8550 --- /dev/null +++ b/test/transform/resource/messages-delombok/GetterLazyInvalid.java.messages @@ -0,0 +1,6 @@ +2:9 ERROR 'lazy' requires the field to be private and final. +6:9 ERROR 'lazy' requires the field to be private and final. +10:9 ERROR 'lazy' requires the field to be private and final. +14:9 WARNING 'lazy' does not work with AccessLevel.NONE. +17:1 ERROR 'lazy' is not supported for @Getter on a type. +22:9 ERROR 'lazy' requires the field to be private and final. \ No newline at end of file -- cgit