From 7b3968fe401c1db299a34feaba8f862069723e36 Mon Sep 17 00:00:00 2001 From: grootjans Date: Mon, 7 Feb 2011 22:44:55 +0100 Subject: Added documentation for @Delegate. This fixes issue 189 --- buildScripts/website.ant.xml | 3 + usage_examples/DelegateExample_post.jpage | 98 +++++++++++++++++++++++++++++++ usage_examples/DelegateExample_pre.jpage | 27 +++++++++ website/features/Delegate.html | 70 ++++++++++++++++++++++ website/features/index.html | 2 + website/features/val.html | 4 +- 6 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 usage_examples/DelegateExample_post.jpage create mode 100644 usage_examples/DelegateExample_pre.jpage create mode 100644 website/features/Delegate.html diff --git a/buildScripts/website.ant.xml b/buildScripts/website.ant.xml index d1eb92ec..aabc337c 100644 --- a/buildScripts/website.ant.xml +++ b/buildScripts/website.ant.xml @@ -141,6 +141,9 @@ such as converting the changelog into HTML, and creating javadoc. + + + diff --git a/usage_examples/DelegateExample_post.jpage b/usage_examples/DelegateExample_post.jpage new file mode 100644 index 00000000..28c1bbb7 --- /dev/null +++ b/usage_examples/DelegateExample_post.jpage @@ -0,0 +1,98 @@ +import java.util.ArrayList; +import java.util.Collection; +import lombok.Delegate; + +public class DelegateExample { + + long counter = 0L; + @Delegate + private final Collection collection = new ArrayList(); + + public boolean add(String name) { + counter++; + return collection.add(name); + } + + @java.lang.SuppressWarnings("all") + public int size() { + return this.collection.size(); + } + + @java.lang.SuppressWarnings("all") + public boolean isEmpty() { + return this.collection.isEmpty(); + } + + @java.lang.SuppressWarnings("all") + public boolean contains(final java.lang.Object arg0) { + return this.collection.contains(arg0); + } + + @java.lang.SuppressWarnings("all") + public java.util.Iterator iterator() { + return this.collection.iterator(); + } + + @java.lang.SuppressWarnings("all") + public java.lang.Object[] toArray() { + return this.collection.toArray(); + } + + @java.lang.SuppressWarnings("all") + public T[] toArray(final T[] arg0) { + return this.collection.toArray(arg0); + } + + @java.lang.SuppressWarnings("all") + public boolean remove(final java.lang.Object arg0) { + return this.collection.remove(arg0); + } + + @java.lang.SuppressWarnings("all") + public boolean containsAll(final java.util.Collection arg0) { + return this.collection.containsAll(arg0); + } + + @java.lang.SuppressWarnings("all") + public boolean addAll(final java.util.Collection arg0) { + return this.collection.addAll(arg0); + } + + @java.lang.SuppressWarnings("all") + public boolean removeAll(final java.util.Collection arg0) { + return this.collection.removeAll(arg0); + } + + @java.lang.SuppressWarnings("all") + public boolean retainAll(final java.util.Collection arg0) { + return this.collection.retainAll(arg0); + } + + @java.lang.SuppressWarnings("all") + public void clear() { + this.collection.clear(); + } +} + +class PartialDelegationExample { + + @Delegate({SimpleCollection.class}) + private final Collection collection = new ArrayList(); + + private interface SimpleCollection { + + boolean add(String item); + + boolean remove(Object item); + } + + @java.lang.SuppressWarnings("all") + public boolean add(final java.lang.String item) { + return this.collection.add(item); + } + + @java.lang.SuppressWarnings("all") + public boolean remove(final java.lang.Object item) { + return this.collection.remove(item); + } +} \ No newline at end of file diff --git a/usage_examples/DelegateExample_pre.jpage b/usage_examples/DelegateExample_pre.jpage new file mode 100644 index 00000000..b208c4ca --- /dev/null +++ b/usage_examples/DelegateExample_pre.jpage @@ -0,0 +1,27 @@ +import java.util.ArrayList; +import java.util.Collection; + +import lombok.Delegate; + + +public class DelegateExample { + long counter = 0L; + + @Delegate + private final Collection collection = new ArrayList(); + + public boolean add(String name) { + counter++; + return collection.add(name); + } +} + +class PartialDelegationExample { + @Delegate({SimpleCollection.class}) + private final Collection collection = new ArrayList(); + + private interface SimpleCollection { + boolean add(String item); + boolean remove(Object item); + } +} diff --git a/website/features/Delegate.html b/website/features/Delegate.html new file mode 100644 index 00000000..bdb22c26 --- /dev/null +++ b/website/features/Delegate.html @@ -0,0 +1,70 @@ + + + + + + + + @Delegate +
+
+
+ +

@Delegate

+ +
+

Overview

+

+ NEW IN Lombok 0.10: Any field can be annotated with @Delegate to let lombok generate delegate methods that forward the call + to this field. +

+

+ Lombok delegates all public methods of the field's type, as well as those of its supertype except for all methods declared + in java.lang.Object. You can provide a specific implementation for a method by providing you own implementation, lombok will not + generate delegate methods for those already declared in the class. +

+

+ You can pass any number of classes into the @Delegate annotation. If you do that, then lombok will delegate all public + methods in those types (and their supertypes, except java.lang.Object) instead of looking at the field's type. +

+
+
+
+

With Lombok

+
@HTML_PRE@
+
+
+
+

Vanilla Java

+
@HTML_POST@
+
+
+
+
+

Small print

+

+ When passing classes to the annotation, these cannot contain generics. This is a limitation of java that lombok cannot work around. +

+

+ When passing classes to the annotation, these classes do not need to be supertypes of the field. See the example. +

+
+
+ +
+
+
+ + + diff --git a/website/features/index.html b/website/features/index.html index edc173fb..06b6763e 100644 --- a/website/features/index.html +++ b/website/features/index.html @@ -36,6 +36,8 @@
Captain's Log, stardate 24435.7: "What was that line again?"
val
Finally! hassle-free final local variables.
+
@Delegate
+
Don't lose your composition
diff --git a/website/features/val.html b/website/features/val.html index 4e05f8ca..f3e86447 100644 --- a/website/features/val.html +++ b/website/features/val.html @@ -50,8 +50,8 @@
-- cgit