diff --git a/doc/changelog.markdown b/doc/changelog.markdown index 10fedb75..b49f6de8 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -2,9 +2,11 @@ Lombok Changelog ---------------- ### v1.12.7 "Edgy Guinea Pig" +* DEPRECATION: `@Delegate` has been moved to `lombok.experimental.Delegate`, and corner cases such as recursive delegation (delegating a type that itself has fields or methods annotated with `@Delegate`) are now error conditions. See the [feature documentation](http://projectlombok.org/features/experimental/Delegate.html) for more information. * FEATURE: It is now possible to put annotations, such as `@Nullable`, on the one parameter of generated `equals()` methods by specifying the `onParam=` option on `@EqualsAndHashCode`, similar to how that feature already exists for `@Setter`. [Issue #674](https://code.google.com/p/projectlombok/issues/detail?id=674) * CHANGE: suppressConstructorProperties should now be configured via lombok configuration. [Issue #659](https://code.google.com/p/projectlombok/issues/detail?id=659) * CHANGE: The `canEqual` method generated by `@EqualsAndHashCode`, `@Value` and `@Data` is now `protected` instead of `public`. [Issue #660](https://code.google.com/p/projectlombok/issues/detail?id=660) +* BUGFIX: Major work on improving support for JDK8, both for javac and eclipse. * BUGFIX: Deadlocks would occasionally occur in eclipse when using lazy getters [Issue #590](https://code.google.com/p/projectlombok/issues/detail?id=590) * BUGFIX: Usage of `@SneakyThrows` with a javac from JDK8 with `-target 1.8` would result in a post compiler error. [Issue #655](https://code.google.com/p/projectlombok/issues/detail?id=655) * BUGFIX: Switching workspace on some versions of eclipse resulted in a 'duplicate field' error. [Issue #666](https://code.google.com/p/projectlombok/issues/detail?id=666) diff --git a/src/core/lombok/Delegate.java b/src/core/lombok/Delegate.java index 534cfb3d..d5b4b48c 100644 --- a/src/core/lombok/Delegate.java +++ b/src/core/lombok/Delegate.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 @@ -27,23 +27,11 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * Put on any field to make lombok generate delegate methods that forward the call to this field. - * - * Example: - *
- * private @Delegate List<String> foo; - *- * - * will generate for example an {@code boolean add(String)} method, which contains: {@code return foo.add(arg);}, as well as all other methods in {@code List}. - * - * All public instance methods of the field's type, as well as all public instance methods of all the field's type's superfields are delegated, except for all methods - * that exist in {@link Object}, the {@code canEqual(Object)} method, and any methods that appear in types - * that are listed in the {@code excludes} property. - *
- * Complete documentation is found at the project lombok features page for @Delegate.
+ * @deprecated Use {@link lombok.experimental.Delegate} instead.
*/
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.SOURCE)
+@Deprecated
public @interface Delegate {
/**
* Normally the type of the field is used as delegate type. However, to choose a different type to delegate, you can list one (or more) types here. Note that types with
diff --git a/src/core/lombok/core/LombokInternalAliasing.java b/src/core/lombok/core/LombokInternalAliasing.java
index 4fd7b29d..8d6794ae 100644
--- a/src/core/lombok/core/LombokInternalAliasing.java
+++ b/src/core/lombok/core/LombokInternalAliasing.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 The Project Lombok Authors.
+ * Copyright (C) 2013-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
@@ -21,12 +21,14 @@
*/
package lombok.core;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class LombokInternalAliasing {
- public static final Map
+ * Complete documentation is found at the project lombok features page for @Delegate.
+ */
+@Target({ElementType.FIELD, ElementType.METHOD})
+@Retention(RetentionPolicy.SOURCE)
+public @interface Delegate {
+ /**
+ * Normally the type of the field is used as delegate type. However, to choose a different type to delegate, you can list one (or more) types here. Note that types with
+ * type arguments can only be done as a field type. A solution for this is to create a private inner interface/class with the appropriate types extended, and possibly
+ * with all methods you'd like to delegate listed, and then supply that class here. The field does not actually have to implement the type you're delegating; the
+ * type listed here is used only to determine which delegate methods to generate.
+ *
+ * NB: All methods in {@code Object}, as well as {@code canEqual(Object other)} will never be delegated.
+ */
+ Class>[] types() default {};
+
+ /**
+ * Each method in any of the types listed here (include supertypes) will not be delegated.
+ *
+ * NB: All methods in {@code Object}, as well as {@code canEqual(Object other)} will never be delegated.
+ */
+ Class>[] excludes() default {};
+}
diff --git a/src/core/lombok/javac/JavacImportList.java b/src/core/lombok/javac/JavacImportList.java
index d5d7460a..2665ca7c 100644
--- a/src/core/lombok/javac/JavacImportList.java
+++ b/src/core/lombok/javac/JavacImportList.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 The Project Lombok Authors.
+ * Copyright (C) 2013-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
@@ -23,7 +23,6 @@ package lombok.javac;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Map;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
@@ -59,12 +58,15 @@ public class JavacImportList implements ImportList {
}
@Override public boolean hasStarImport(String packageName) {
- for (Map.Entry
+ @Delegate was introduced as feature in lombok v0.10. It was moved to the experimental package in lombok v1.14; the old version from the main lombok package is now deprecated.
+
+ Experimental because:
+
- NEW IN Lombok 0.10: Any field or no-argument method can be annotated with
- Lombok delegates all
+ Lombok delegates all
+
You can pass any number of classes into the
- All public non-
+ All public non-
+
To have very precise control over what is delegated and what isn't, write private inner interfaces with method signatures, then specify these
private inner interfaces as types in
+
+ * private @Delegate List<String> foo;
+ *
+ *
+ * will generate for example an {@code boolean add(String)} method, which contains: {@code return foo.add(arg);}, as well as all other methods in {@code List}.
+ *
+ * All public instance methods of the field's type, as well as all public instance methods of all the field's type's superfields are delegated, except for all methods
+ * that exist in {@link Object}, the {@code canEqual(Object)} method, and any methods that appear in types
+ * that are listed in the {@code excludes} property.
+ * @Delegate
+ Since
+ Experimental
+
+
+ Current status: negative - Currently we feel this feature will not move out of experimental status anytime soon, and support for this feature may be dropped if future versions of javac or ecj make it difficult to continue to maintain the feature.
+ @Delegate generate delegates for whatever you didn't manually implement, but due to issues with generics erasure this also can't be made to work without caveats.
+ Overview
@Delegate to let lombok generate delegate methods
- that forward the call to this field (or the result of invoking this method).
- public methods of the field's type (or method's return type), as well as those of its supertype except for all
+ Any field or no-argument method can be annotated with @Delegate to let lombok generate delegate methods that forward the call to this field (or the result of invoking this method).
+ public methods of the field's type (or method's return type), as well as those of its supertypes except for all
methods declared in java.lang.Object.
- @Delegate annotation's types parameter.
- 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/method's type.
- Object methods that are part of the calculated type(s) are
- copied, whether or not you also wrote implementations for those methods. That would thus result in duplicate method errors. You can avoid these
+ 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/method's type.
+ Object methods that are part of the calculated type(s) are copied, whether or not you also wrote implementations for those methods. That would thus result in duplicate method errors. You can avoid these
by using the @Delegate(excludes=SomeType.class) parameter to exclude all public methods in the excluded type(s), and their supertypes.
- @Delegate(types=PrivateInnerInterfaceWithIncludesList.class, excludes=SameForExcludes.class).
@Delegate cannot be used on static fields or methods.
- @Delegate cannot be used when the calculated type(s) to delegate / exclude themselves contain @Delegate annotations; in other words, @Delegate will error if you attempt to use it recursively.
@FieldDefaults@Delegate@WitheronMethod= / onConstructor= / onParam=@Log@Delegate