mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 14:17:48 +00:00
Documented @Delegate with javadoc.
This commit is contained in:
1 parent
c340c9c24f
commit
3c092da93a
2 files changed
+23
-2
No files matched your search
@@ -26,8 +26,27 @@ import java.lang.annotation.Retention;
|
||||
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:
|
||||
* <pre>
|
||||
* private @Delegate List<String> foo;
|
||||
* </pre>
|
||||
*
|
||||
* 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 java.lang.Object}, and except for methods that are already present in the class.
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@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.
|
||||
*/
|
||||
Class<?>[] value() default {};
|
||||
}
|
||||
@@ -54,7 +54,6 @@ import com.sun.tools.javac.code.Type.ClassType;
|
||||
import com.sun.tools.javac.code.Type.TypeVar;
|
||||
import com.sun.tools.javac.code.Types;
|
||||
import com.sun.tools.javac.model.JavacTypes;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
|
||||
import com.sun.tools.javac.tree.JCTree.JCBlock;
|
||||
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
|
||||
@@ -89,7 +88,10 @@ public class HandleDelegate implements JavacAnnotationHandler<Delegate> {
|
||||
"finalize()"));
|
||||
|
||||
@Override public boolean handle(AnnotationValues<Delegate> annotation, JCAnnotation ast, JavacNode annotationNode) {
|
||||
if (annotationNode.up().getKind() != Kind.FIELD) return false; // TODO error
|
||||
if (annotationNode.up().getKind() != Kind.FIELD) {
|
||||
// As the annotation is legal on fields only, javac itself will take care of printing an error message for this.
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Object> delegateTypes = annotation.getActualExpressions("value");
|
||||
JavacResolution reso = new JavacResolution(annotationNode.getContext());
|
||||
|
||||
Reference in new issue
Block a user