aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/lombok/core/AnnotationValues.java20
-rw-r--r--src/core/lombok/core/TransformationsUtil.java263
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java74
-rw-r--r--src/core/lombok/eclipse/handlers/HandleGetter.java10
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSetter.java8
-rw-r--r--src/core/lombok/experimental/Accessors.java56
-rw-r--r--src/core/lombok/javac/handlers/HandleGetter.java11
-rw-r--r--src/core/lombok/javac/handlers/HandleSetter.java19
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java82
-rw-r--r--src/utils/lombok/core/TransformationsUtil.java186
-rw-r--r--src/utils/lombok/javac/Javac.java53
-rw-r--r--website/features/experimental/Accessors.html103
-rw-r--r--website/features/experimental/index.html45
-rw-r--r--website/features/index.html2
14 files changed, 672 insertions, 260 deletions
diff --git a/src/core/lombok/core/AnnotationValues.java b/src/core/lombok/core/AnnotationValues.java
index 64111dae..df056dd4 100644
--- a/src/core/lombok/core/AnnotationValues.java
+++ b/src/core/lombok/core/AnnotationValues.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 The Project Lombok Authors.
+ * Copyright (C) 2009-2012 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
@@ -118,6 +118,18 @@ public class AnnotationValues<A extends Annotation> {
this.ast = ast;
}
+ public static <A extends Annotation> AnnotationValues<A> of(Class<A> type) {
+ return new AnnotationValues<A>(type, Collections.<String, AnnotationValue>emptyMap(), null);
+ }
+
+ /**
+ * Creates a new annotation wrapper with all default values, and using the provided ast as lookup anchor for
+ * class literals.
+ */
+ public static <A extends Annotation> AnnotationValues<A> of(Class<A> type, LombokNode<?, ?, ?> ast) {
+ return new AnnotationValues<A>(type, Collections.<String, AnnotationValue>emptyMap(), ast);
+ }
+
/**
* Thrown on the fly if an actual annotation instance procured via the {@link #getInstance()} method is queried
* for a method for which this AnnotationValues instance either doesn't have a guess or can't manage to fit
@@ -423,7 +435,7 @@ public class AnnotationValues<A extends Annotation> {
}
/* 2. Walk through non-star imports and search for a match. */ {
- for (String im : ast.getImportStatements()) {
+ for (String im : ast == null ? Collections.<String>emptyList() : ast.getImportStatements()) {
if (im.endsWith(".*")) continue;
int idx = im.lastIndexOf('.');
String simple = idx == -1 ? im : im.substring(idx+1);
@@ -434,7 +446,7 @@ public class AnnotationValues<A extends Annotation> {
}
/* 3. Walk through star imports and, if they start with "java.", use Class.forName based resolution. */ {
- List<String> imports = new ArrayList<String>(ast.getImportStatements());
+ List<String> imports = ast == null ? Collections.<String>emptyList() : new ArrayList<String>(ast.getImportStatements());
imports.add("java.lang.*");
for (String im : imports) {
if (!im.endsWith(".*") || !im.startsWith("java.")) continue;
@@ -465,7 +477,7 @@ public class AnnotationValues<A extends Annotation> {
private static String inLocalPackage(LombokNode<?, ?, ?> node, String typeName) {
StringBuilder result = new StringBuilder();
- if (node.getPackageDeclaration() != null) result.append(node.getPackageDeclaration());
+ if (node != null && node.getPackageDeclaration() != null) result.append(node.getPackageDeclaration());
if (result.length() > 0) result.append('.');
result.append(typeName);
return result.toString();
diff --git a/src/core/lombok/core/TransformationsUtil.java b/src/core/lombok/core/TransformationsUtil.java
new file mode 100644
index 00000000..60d9bab0
--- /dev/null
+++ b/src/core/lombok/core/TransformationsUtil.java
@@ -0,0 +1,263 @@
+/*
+ * Copyright (C) 2009-2012 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
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package lombok.core;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import lombok.experimental.Accessors;
+
+/**
+ * Container for static utility methods useful for some of the standard lombok transformations, regardless of
+ * target platform (e.g. useful for both javac and Eclipse lombok implementations).
+ */
+public class TransformationsUtil {
+ private TransformationsUtil() {
+ //Prevent instantiation
+ }
+
+ /**
+ * Given the name of a field, return the 'base name' of that field. For example, {@code fFoobar} becomes {@code foobar} if {@code f} is in the prefix list.
+ * For prefixes that end in a letter character, the next character must be a non-lowercase character (i.e. {@code hashCode} is not {@code ashCode} even if
+ * {@code h} is in the prefix list, but {@code hAshcode} would become {@code ashCode}). The first prefix that matches is used. If the prefix list is empty,
+ * or the empty string is in the prefix list and no prefix before it matches, the fieldName will be returned verbatim.
+ *
+ * If no prefix matches and the empty string is not in the prefix list and the prefix list is not empty, {@code null} is returned.
+ *
+ * @param fieldName The full name of a field.
+ * @param prefixes A list of prefixes, usually provided by the {@code Accessors} settings annotation, listing field prefixes.
+ * @return The base name of the field.
+ */
+ private static CharSequence removePrefix(CharSequence fieldName, String[] prefixes) {
+ if (prefixes == null || prefixes.length == 0) return fieldName;
+
+ outer:
+ for (String prefix : prefixes) {
+ if (prefix.length() == 0) return fieldName;
+ if (fieldName.length() <= prefix.length()) continue outer;
+ for (int i = 0; i < prefix.length(); i++) {
+ if (fieldName.charAt(i) != prefix.charAt(i)) continue outer;
+ }
+ char followupChar = fieldName.charAt(prefix.length());
+ // if prefix is a letter then follow up letter needs to not be lowercase, i.e. 'foo' is not a match
+ // as field named 'oo' with prefix 'f', but 'fOo' would be.
+ if (Character.isLetter(prefix.charAt(prefix.length() - 1)) &&
+ Character.isLowerCase(followupChar)) continue outer;
+ return "" + Character.toLowerCase(followupChar) + fieldName.subSequence(prefix.length() + 1, fieldName.length());
+ }
+
+ return null;
+ }
+
+ /** Matches any of the 8 primitive names, such as {@code boolean}. */
+ public static final Pattern PRIMITIVE_TYPE_NAME_PATTERN = Pattern.compile(
+ "^(boolean|byte|short|int|long|float|double|char)$");
+
+ /* NB: 'notnull' is not part of the pattern because there are lots of @NotNull annotations out there that are crappily named and actually mean
+ something else, such as 'this field must not be null _when saved to the db_ but its perfectly okay to start out as such, and a no-args
+ constructor and the implied starts-out-as-null state that goes with it is in fact mandatory' which happens with javax.validation.constraints.NotNull.
+ Various problems with spring have also been reported. See issue #287, issue #271, and issue #43. */
+
+ /** Matches the simple part of any annotation that lombok considers as indicative of NonNull status. */
+ public static final Pattern NON_NULL_PATTERN = Pattern.compile("^(?:nonnull)$", Pattern.CASE_INSENSITIVE);
+
+ /** Matches the simple part of any annotation that lombok considers as indicative of Nullable status. */
+ public static final Pattern NULLABLE_PATTERN = Pattern.compile("^(?:nullable|checkfornull)$", Pattern.CASE_INSENSITIVE);
+
+ /**
+ * Generates a getter name from a given field name.
+ *
+ * Strategy:
+ * <ul>
+ * <li>Reduce the field's name to its base name by stripping off any prefix (from {@code Accessors}). If the field name does not fit
+ * the prefix list, this method immediately returns {@null}.</li>
+ * <li>If {@code Accessors} has {@code fluent=true}, then return the basename.</li>
+ * <li>Pick a prefix. 'get' normally, but 'is' if {@code isBoolean} is true.</li>
+ * <li>Only if {@code isBoolean} is true: Check if the field starts with {@code is} followed by a non-lowercase character. If so, return the field name verbatim.</li>
+ * <li>Check if the first character of the field is lowercase. If so, check if the second character
+ * exists and is title or upper case. If so, uppercase the first character. If not, titlecase the first character.</li>
+ * <li>Return the prefix plus the possibly title/uppercased first character, and the rest of the field name.</li>
+ * </ul>
+ *
+ * @param accessors Accessors configuration.
+ * @param fieldName the name of the field.
+ * @param isBoolean if the field is of type 'boolean'. For fields of type {@code java.lang.Boolean}, you should provide {@code false}.
+ * @return The getter name for this field, or {@code null} if this field does not fit expected patterns and therefore cannot be turned into a getter name.
+ */
+ public static String toGetterName(AnnotationValues<Accessors> accessors, CharSequence fieldName, boolean isBoolean) {
+ if (fieldName.length() == 0) return null;
+
+ Accessors ac = accessors.getInstance();
+ fieldName = removePrefix(fieldName, ac.prefix());
+ if (fieldName == null) return null;
+
+ if (ac.fluent()) return fieldName.toString();
+
+ if (isBoolean && fieldName.toString().startsWith("is") && fieldName.length() > 2 && !Character.isLowerCase(fieldName.charAt(2))) {
+ // The field is for example named 'isRunning'.
+ return fieldName.toString();
+ }
+
+ return buildName(isBoolean ? "is" : "get", fieldName.toString());
+ }
+
+ /**
+ * Generates a setter name from a given field name.
+ *
+ * Strategy:
+ * <ul>
+ * <li>Reduce the field's name to its base name by stripping off any prefix (from {@code Accessors}). If the field name does not fit
+ * the prefix list, this method immediately returns {@null}.</li>
+ * <li>If {@code Accessors} has {@code fluent=true}, then return the basename.</li>
+ * <li>Only if {@code isBoolean} is true: Check if the field starts with {@code is} followed by a non-lowercase character.
+ * If so, replace {@code is} with {@code set} and return that.</li>
+ * <li>Check if the first character of the field is lowercase. If so, check if the second character
+ * exists and is title or upper case. If so, uppercase the first character. If not, titlecase the first character.</li>
+ * <li>Return {@code "set"} plus the possibly title/uppercased first character, and the rest of the field name.</li>
+ * </ul>
+ *
+ * @param accessors Accessors configuration.
+ * @param fieldName the name of the field.
+ * @param isBoolean if the field is of type 'boolean'. For fields of type {@code java.lang.Boolean}, you should provide {@code false}.
+ * @return The setter name for this field, or {@code null} if this field does not fit expected patterns and therefore cannot be turned into a getter name.
+ */
+ public static String toSetterName(AnnotationValues<Accessors> accessors, CharSequence fieldName, boolean isBoolean) {
+ if (fieldName.length() == 0) return null;
+ Accessors ac = accessors.getInstance();
+ fieldName = removePrefix(fieldName, ac.prefix());
+ if (fieldName == null) return null;
+
+ String fName = fieldName.toString();
+ if (ac.fluent()) return fName;
+
+ if (isBoolean && fName.startsWith("is") && fieldName.length() > 2 && !Character.isLowerCase(fName.charAt(2))) {
+ // The field is for example named 'isRunning'.
+ return "set" + fName.substring(2);
+ }
+
+ return buildName("set", fName);
+ }
+
+ /**
+ * Returns all names of methods that would represent the getter for a field with the provided name.
+ *
+ * For example if {@code isBoolean} is true, then a field named {@code isRunning} would produce:<br />
+ * {@code [isRunning, getRunning, isIsRunning, getIsRunning]}
+ *
+ * @param accessors Accessors configuration.
+ * @param fieldName the name of the field.
+ * @param isBoolean if the field is of type 'boolean'. For fields of type 'java.lang.Boolean', you should provide {@code false}.
+ */
+ public static List<String> toAllGetterNames(AnnotationValues<Accessors> accessors, CharSequence fieldName, boolean isBoolean) {
+ if (!isBoolean) return Collections.singletonList(toGetterName(accessors, fieldName, false));
+
+ Accessors acc = accessors.getInstance();
+ fieldName = removePrefix(fieldName, acc.prefix());
+ if (fieldName == null) return Collections.emptyList();
+
+ List<String> baseNames = toBaseNames(fieldName, isBoolean, acc.fluent());
+
+ Set<String> names = new HashSet<String>();
+ for (String baseName : baseNames) {
+ if (acc.fluent()) {
+ names.add(baseName);
+ } else {
+ names.add(buildName("is", baseName));
+ names.add(buildName("get", baseName));
+ }
+ }
+
+ return new ArrayList<String>(names);
+ }
+
+ /**
+ * Returns all names of methods that would represent the setter for a field with the provided name.
+ *
+ * For example if {@code isBoolean} is true, then a field named {@code isRunning} would produce:<br />
+ * {@code [setRunning, setIsRunning]}
+ *
+ * @param fieldName the name of the field.
+ * @param isBoolean if the field is of type 'boolean'. For fields of type 'java.lang.Boolean', you should provide {@code false}.
+ */
+ public static List<String> toAllSetterNames(AnnotationValues<Accessors> accessors, CharSequence fieldName, boolean isBoolean) {
+ if (!isBoolean) return Collections.singletonList(toSetterName(accessors, fieldName, false));
+
+ Accessors acc = accessors.getInstance();
+ fieldName = removePrefix(fieldName, acc.prefix());
+ if (fieldName == null) return Collections.emptyList();
+
+ List<String> baseNames = toBaseNames(fieldName, isBoolean, acc.fluent());
+
+ Set<String> names = new HashSet<String>();
+ for (String baseName : baseNames) {
+ if (acc.fluent()) {
+ names.add(baseName);
+ } else {
+ names.add(buildName("set", baseName));
+ }
+ }
+
+ return new ArrayList<String>(names);
+ }
+
+ private static List<String> toBaseNames(CharSequence fieldName, boolean isBoolean, boolean fluent) {
+ List<String> baseNames = new ArrayList<String>();
+ baseNames.add(fieldName.toString());
+
+ // isPrefix = field is called something like 'isRunning', so 'running' could also be the fieldname.
+ String fName = fieldName.toString();
+ if (fName.startsWith("is") && fName.length() > 2 && !Character.isLowerCase(fName.charAt(2))) {
+ String baseName = fName.substring(2);
+ if (fluent) {
+ baseNames.add("" + Character.toLowerCase(baseName.charAt(0)) + baseName.substring(1));
+ } else {
+ baseNames.add(baseName);
+ }
+ }
+
+ return baseNames;
+ }
+
+ /**
+ * @param prefix Something like {@code get} or {@code set} or {@code is}.
+ * @param suffix Something like {@code running}.
+ * @return prefix + smartly title-cased suffix. For example, {@code setRunning}.
+ */
+ private static String buildName(String prefix, String suffix) {
+ if (suffix.length() == 0) return prefix;
+ if (prefix.length() == 0) return suffix;
+
+ char first = suffix.charAt(0);
+ if (Character.isLowerCase(first)) {
+ boolean useUpperCase = suffix.length() > 2 &&
+ (Character.isTitleCase(suffix.charAt(1)) || Character.isUpperCase(suffix.charAt(1)));
+ suffix = String.format("%s%s",
+ useUpperCase ? Character.toUpperCase(first) : Character.toTitleCase(first),
+ suffix.subSequence(1, suffix.length()));
+ }
+ return String.format("%s%s", prefix, suffix);
+ }
+}
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index 56f51573..ff743601 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -41,11 +41,12 @@ import lombok.Data;
import lombok.Getter;
import lombok.Lombok;
import lombok.core.AnnotationValues;
+import lombok.core.TransformationsUtil;
import lombok.core.AST.Kind;
import lombok.core.AnnotationValues.AnnotationValue;
import lombok.eclipse.EclipseAST;
import lombok.eclipse.EclipseNode;
-import lombok.core.TransformationsUtil;
+import lombok.experimental.Accessors;
import lombok.core.TypeResolver;
import org.eclipse.core.runtime.ILog;
@@ -777,7 +778,7 @@ public class EclipseHandlerUtil {
TypeReference fieldType = ((FieldDeclaration)field.get()).type;
boolean isBoolean = nameEquals(fieldType.getTypeName(), "boolean") && fieldType.dimensions() == 0;
EclipseNode typeNode = field.up();
- for (String potentialGetterName : TransformationsUtil.toAllGetterNames(field.getName(), isBoolean)) {
+ for (String potentialGetterName : toAllGetterNames(field, isBoolean)) {
for (EclipseNode potentialGetter : typeNode.down()) {
if (potentialGetter.getKind() != Kind.METHOD) continue;
if (!(potentialGetter.get() instanceof MethodDeclaration)) continue;
@@ -820,7 +821,8 @@ public class EclipseHandlerUtil {
}
if (hasGetterAnnotation) {
- String getterName = TransformationsUtil.toGetterName(field.getName(), isBoolean);
+ String getterName = toGetterName(field, isBoolean);
+ if (getterName == null) return null;
return new GetterMethod(getterName.toCharArray(), fieldType);
}
@@ -930,6 +932,52 @@ public class EclipseHandlerUtil {
}
/**
+ * Translates the given field into all possible getter names.
+ * Convenient wrapper around {@link TransformationsUtil#toAllGetterNames(lombok.core.AnnotationValues, CharSequence, boolean)}.
+ */
+ public static List<String> toAllGetterNames(EclipseNode field, boolean isBoolean) {
+ String fieldName = field.getName();
+ AnnotationValues<Accessors> accessors = EclipseHandlerUtil.getAccessorsForField(field);
+
+ return TransformationsUtil.toAllGetterNames(accessors, fieldName, isBoolean);
+ }
+
+ /**
+ * @return the likely getter name for the stated field. (e.g. private boolean foo; to isFoo).
+ *
+ * Convenient wrapper around {@link TransformationsUtil#toGetterName(lombok.core.AnnotationValues, CharSequence, boolean)}.
+ */
+ public static String toGetterName(EclipseNode field, boolean isBoolean) {
+ String fieldName = field.getName();
+ AnnotationValues<Accessors> accessors = EclipseHandlerUtil.getAccessorsForField(field);
+
+ return TransformationsUtil.toGetterName(accessors, fieldName, isBoolean);
+ }
+
+ /**
+ * Translates the given field into all possible setter names.
+ * Convenient wrapper around {@link TransformationsUtil#toAllSetterNames(lombok.core.AnnotationValues, CharSequence, boolean)}.
+ */
+ public static java.util.List<String> toAllSetterNames(EclipseNode field, boolean isBoolean) {
+ String fieldName = field.getName();
+ AnnotationValues<Accessors> accessors = EclipseHandlerUtil.getAccessorsForField(field);
+
+ return TransformationsUtil.toAllSetterNames(accessors, fieldName, isBoolean);
+ }
+
+ /**
+ * @return the likely setter name for the stated field. (e.g. private boolean foo; to setFoo).
+ *
+ * Convenient wrapper around {@link TransformationsUtil#toSetterName(lombok.core.AnnotationValues, CharSequence, boolean)}.
+ */
+ public static String toSetterName(EclipseNode field, boolean isBoolean) {
+ String fieldName = field.getName();
+ AnnotationValues<Accessors> accessors = EclipseHandlerUtil.getAccessorsForField(field);
+
+ return TransformationsUtil.toSetterName(accessors, fieldName, isBoolean);
+ }
+
+ /**
* Checks if the field should be included in operations that work on 'all' fields:
* If the field is static, or starts with a '$', or is actually an enum constant, 'false' is returned, indicating you should skip it.
*/
@@ -949,6 +997,26 @@ public class EclipseHandlerUtil {
return true;
}
+ public static AnnotationValues<Accessors> getAccessorsForField(EclipseNode field) {
+ for (EclipseNode node : field.down()) {
+ if (annotationTypeMatches(Accessors.class, node)) {
+ return createAnnotation(Accessors.class, node);
+ }
+ }
+
+ EclipseNode current = field.up();
+ while (current != null) {
+ for (EclipseNode node : field.down()) {
+ if (annotationTypeMatches(Accessors.class, node)) {
+ return createAnnotation(Accessors.class, node);
+ }
+ }
+ current = current.up();
+ }
+
+ return AnnotationValues.of(Accessors.class, field);
+ }
+
/**
* Checks if there is a field with the provided name.
*
diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java
index 5aeda5a5..d53bf89b 100644
--- a/src/core/lombok/eclipse/handlers/HandleGetter.java
+++ b/src/core/lombok/eclipse/handlers/HandleGetter.java
@@ -187,13 +187,17 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> {
}
TypeReference fieldType = copyType(field.type, source);
- String fieldName = new String(field.name);
boolean isBoolean = nameEquals(fieldType.getTypeName(), "boolean") && fieldType.dimensions() == 0;
- String getterName = TransformationsUtil.toGetterName(fieldName, isBoolean);
+ String getterName = toGetterName(fieldNode, isBoolean);
+
+ if (getterName == null) {
+ errorNode.addWarning("Not generating getter for this field: It does not fit your @Accessors prefix list.");
+ return;
+ }
int modifier = toEclipseModifier(level) | (field.modifiers & ClassFileConstants.AccStatic);
- for (String altName : TransformationsUtil.toAllGetterNames(fieldName, isBoolean)) {
+ for (String altName : toAllGetterNames(fieldNode, isBoolean)) {
switch (methodExists(altName, fieldNode, false, 0)) {
case EXISTS_BY_LOMBOK:
return;
diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java
index 01926155..3fa872f9 100644
--- a/src/core/lombok/eclipse/handlers/HandleSetter.java
+++ b/src/core/lombok/eclipse/handlers/HandleSetter.java
@@ -148,11 +148,15 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
FieldDeclaration field = (FieldDeclaration) fieldNode.get();
TypeReference fieldType = copyType(field.type, source);
boolean isBoolean = nameEquals(fieldType.getTypeName(), "boolean") && fieldType.dimensions() == 0;
- String setterName = TransformationsUtil.toSetterName(new String(field.name), isBoolean);
+ String setterName = toSetterName(fieldNode, isBoolean);
+ if (setterName == null) {
+ errorNode.addWarning("Not generating setter for this field: It does not fit your @Accessors prefix list.");
+ return;
+ }
int modifier = toEclipseModifier(level) | (field.modifiers & ClassFileConstants.AccStatic);
- for (String altName : TransformationsUtil.toAllSetterNames(new String(field.name), isBoolean)) {
+ for (String altName : toAllSetterNames(fieldNode, isBoolean)) {
switch (methodExists(altName, fieldNode, false, 1)) {
case EXISTS_BY_LOMBOK:
return;
diff --git a/src/core/lombok/experimental/Accessors.java b/src/core/lombok/experimental/Accessors.java
new file mode 100644
index 00000000..5b454273
--- /dev/null
+++ b/src/core/lombok/experimental/Accessors.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2012 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
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package lombok.experimental;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A container for settings for the generation of getters and setters.
+ * Using this annotation does nothing by itself; an annotation that makes lombok generate getters and setters,
+ * such as {@link lombok.Setter} or {@link lombok.Data} is also required.
+ */
+@Target({ElementType.TYPE, ElementType.FIELD})
+@Retention(RetentionPolicy.SOURCE)
+public @interface Accessors {
+ /**
+ * If true, accessors will be named after the field and not include a <code>get</code> or <code>set</code>
+ * prefix. If true and <code>chain</code> is omitted, <code>chain</code> defaults to <code>true</code>.
+ * <strong>default: false</strong>
+ */
+ boolean fluent() default false;
+
+ /**
+ * If true, setters return <code>this</code> instead of <code>void</code>.
+ * <strong>default: false</strong>, unless <code>fluent=true</code>, then <strong>default: true</code>
+ */
+ boolean chain() default false;
+
+ /**
+ * If present, only fields with any of the stated prefixes are given the getter/setter treatment.
+ * Note that a prefix only counts if the next character is NOT a lowercase character. If multiple fields
+ * all turn into the same name when the prefix is stripped, an error will be generated.
+ */
+ String[] prefix() default {};
+}
diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java
index 09da2d4b..dd0a99ad 100644
--- a/src/core/lombok/javac/handlers/HandleGetter.java
+++ b/src/core/lombok/javac/handlers/HandleGetter.java
@@ -188,9 +188,14 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
}
}
- String methodName = toGetterName(fieldDecl);
+ String methodName = toGetterName(fieldNode);
- for (String altName : toAllGetterNames(fieldDecl)) {
+ if (methodName == null) {
+ source.addWarning("Not generating getter for this field: It does not fit your @Accessors prefix list.");
+ return;
+ }
+
+ for (String altName : toAllGetterNames(fieldNode)) {
switch (methodExists(altName, fieldNode, false, 0)) {
case EXISTS_BY_LOMBOK:
return;
@@ -229,7 +234,7 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
}
JCBlock methodBody = treeMaker.Block(0, statements);
- Name methodName = field.toName(toGetterName(fieldNode));
+ Name methodName = field.toName(toGetterName(field));
List<JCTypeParameter> methodGenericParams = List.nil();
List<JCVariableDecl> parameters = List.nil();
diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java
index 20b8375b..2a91fb37 100644
--- a/src/core/lombok/javac/handlers/HandleSetter.java
+++ b/src/core/lombok/javac/handlers/HandleSetter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2011 The Project Lombok Authors.
+ * Copyright (C) 2009-2012 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
@@ -162,9 +162,14 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> {
}
JCVariableDecl fieldDecl = (JCVariableDecl)fieldNode.get();
- String methodName = toSetterName(fieldDecl);
+ String methodName = toSetterName(fieldNode);
- for (String altName : toAllSetterNames(fieldDecl)) {
+ if (methodName == null) {
+ source.addWarning("Not generating setter for this field: It does not fit your @Accessors prefix list.");
+ return;
+ }
+
+ for (String altName : toAllSetterNames(fieldNode)) {
switch (methodExists(altName, fieldNode, false, 1)) {
case EXISTS_BY_LOMBOK:
return;
@@ -184,10 +189,14 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> {
long access = toJavacModifier(level) | (fieldDecl.mods.flags & Flags.STATIC);
- injectMethod(fieldNode.up(), createSetter(access, fieldNode, fieldNode.getTreeMaker(), source.get()));
+ JCMethodDecl createdSetter = createSetter(access, fieldNode, fieldNode.getTreeMaker(), source.get());
+ injectMethod(fieldNode.up(), createdSetter);
}
private JCMethodDecl createSetter(long access, JavacNode field, TreeMaker treeMaker, JCTree source) {
+ String setterName = toSetterName(field);
+ if (setterName == null) return null;
+
JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
JCExpression fieldRef = createFieldAccessor(treeMaker, field, FieldAccess.ALWAYS_FIELD);
@@ -206,7 +215,7 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> {
}
JCBlock methodBody = treeMaker.Block(0, statements);
- Name methodName = field.toName(toSetterName(fieldDecl));
+ Name methodName = field.toName(setterName);
List<JCAnnotation> annsOnParam = nonNulls.appendList(nullables);
JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(Flags.FINAL, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index 9234812e..92629a3c 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -37,9 +37,11 @@ import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.core.AnnotationValues;
+import lombok.core.TransformationsUtil;
import lombok.core.TypeResolver;
import lombok.core.AST.Kind;
import lombok.core.AnnotationValues.AnnotationValue;
+import lombok.experimental.Accessors;
import lombok.javac.Javac;
import lombok.javac.JavacNode;
@@ -290,6 +292,81 @@ public class JavacHandlerUtil {
}
/**
+ * Translates the given field into all possible getter names.
+ * Convenient wrapper around {@link TransformationsUtil#toAllGetterNames(lombok.core.AnnotationValues, CharSequence, boolean)}.
+ */
+ public static java.util.List<String> toAllGetterNames(JavacNode field) {
+ String fieldName = field.getName();
+ boolean isBoolean = isBoolean(field);
+ AnnotationValues<Accessors> accessors = JavacHandlerUtil.getAccessorsForField(field);
+
+ return TransformationsUtil.toAllGetterNames(accessors, fieldName, isBoolean);
+ }
+
+ /**
+ * @return the likely getter name for the stated field. (e.g. private boolean foo; to isFoo).
+ *
+ * Convenient wrapper around {@link TransformationsUtil#toGetterName(lombok.core.AnnotationValues, CharSequence, boolean)}.
+ */
+ public static String toGetterName(JavacNode field) {
+ String fieldName = field.getName();
+ boolean isBoolean = isBoolean(field);
+ AnnotationValues<Accessors> accessors = JavacHandlerUtil.getAccessorsForField(field);
+
+ return TransformationsUtil.toGetterName(accessors, fieldName, isBoolean);
+ }
+
+ /**
+ * Translates the given field into all possible setter names.
+ * Convenient wrapper around {@link TransformationsUtil#toAllSetterNames(lombok.core.AnnotationValues, CharSequence, boolean)}.
+ */
+ public static java.util.List<String> toAllSetterNames(JavacNode field) {
+ String fieldName = field.getName();
+ boolean isBoolean = isBoolean(field);
+ AnnotationValues<Accessors> accessors = JavacHandlerUtil.getAccessorsForField(field);
+
+ return TransformationsUtil.toAllSetterNames(accessors, fieldName, isBoolean);
+ }
+
+ /**
+ * @return the likely setter name for the stated field. (e.g. private boolean foo; to setFoo).
+ *
+ * Convenient wrapper around {@link TransformationsUtil#toSetterName(lombok.core.AnnotationValues, CharSequence, boolean)}.
+ */
+ public static String toSetterName(JavacNode field) {
+ String fieldName = field.getName();
+ boolean isBoolean = isBoolean(field);
+ AnnotationValues<Accessors> accessors = JavacHandlerUtil.getAccessorsForField(field);
+
+ return TransformationsUtil.toSetterName(accessors, fieldName, isBoolean);
+ }
+
+ private static boolean isBoolean(JavacNode field) {
+ JCExpression varType = ((JCVariableDecl) field.get()).vartype;
+ return varType != null && varType.toString().equals("boolean");
+ }
+
+ public static AnnotationValues<Accessors> getAccessorsForField(JavacNode field) {
+ for (JavacNode node : field.down()) {
+ if (annotationTypeMatches(Accessors.class, node)) {
+ return createAnnotation(Accessors.class, node);
+ }
+ }
+
+ JavacNode current = field.up();
+ while (current != null) {
+ for (JavacNode node : field.down()) {
+ if (annotationTypeMatches(Accessors.class, node)) {
+ return createAnnotation(Accessors.class, node);
+ }
+ }
+ current = current.up();
+ }
+
+ return AnnotationValues.of(Accessors.class, field);
+ }
+
+ /**
* Checks if there is a field with the provided name.
*
* @param fieldName the field name to check for.
@@ -420,7 +497,7 @@ public class JavacHandlerUtil {
private static GetterMethod findGetter(JavacNode field) {
JCVariableDecl decl = (JCVariableDecl)field.get();
JavacNode typeNode = field.up();
- for (String potentialGetterName : toAllGetterNames(decl)) {
+ for (String potentialGetterName : toAllGetterNames(field)) {
for (JavacNode potentialGetter : typeNode.down()) {
if (potentialGetter.getKind() != Kind.METHOD) continue;
JCMethodDecl method = (JCMethodDecl) potentialGetter.get();
@@ -462,7 +539,8 @@ public class JavacHandlerUtil {
}
if (hasGetterAnnotation) {
- String getterName = toGetterName(decl);
+ String getterName = toGetterName(field);
+ if (getterName == null) return null;
return new GetterMethod(field.toName(getterName), decl.vartype);
}
diff --git a/src/utils/lombok/core/TransformationsUtil.java b/src/utils/lombok/core/TransformationsUtil.java
deleted file mode 100644
index 56ae0fb0..00000000
--- a/src/utils/lombok/core/TransformationsUtil.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright (C) 2009 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
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package lombok.core;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-/**
- * Container for static utility methods useful for some of the standard lombok transformations, regardless of
- * target platform (e.g. useful for both javac and Eclipse lombok implementations).
- */
-public class TransformationsUtil {
- private TransformationsUtil() {
- //Prevent instantiation
- }
-
- /**
- * Generates a getter name from a given field name.
- *
- * Strategy:
- *
- * First, pick a prefix. 'get' normally, but 'is' if {@code isBoolean} is true.
- *
- * Then, check if the first character of the field is lowercase. If so, check if the second character
- * exists and is title or upper case. If so, uppercase the first character. If not, titlecase the first character.
- *
- * return the prefix plus the possibly title/uppercased first character, and the rest of the field name.
- *
- * Note that for boolean fields, if the field starts with 'is', and the character after that is
- * <b>not</b> a lowercase character, the field name is returned without changing any character's case and without
- * any prefix.
- *
- * @param fieldName the name of the field.
- * @param isBoolean if the field is of type 'boolean'. For fields of type 'java.lang.Boolean', you should provide {@code false}.
- */
- public static String toGetterName(CharSequence fieldName, boolean isBoolean) {
- final String prefix = isBoolean ? "is" : "get";
-
- if (fieldName.length() == 0) return prefix;
-
- if (isBoolean && fieldName.toString().startsWith("is") && fieldName.length() > 2 && !Character.isLowerCase(fieldName.charAt(2))) {
- // The field is for example named 'isRunning'.
- return fieldName.toString();
- }
-
- return buildName(prefix, fieldName.toString());
- }
-
- public static final Pattern PRIMITIVE_TYPE_NAME_PATTERN = Pattern.compile(
- "^(boolean|byte|short|int|long|float|double|char)$");
-
- /* NB: 'notnull' is not part of the pattern because there are lots of @NotNull annotations out there that are crappily named and actually mean
- something else, such as 'this field must not be null _when saved to the db_ but its perfectly okay to start out as such, and a no-args
- constructor and the implied starts-out-as-null state that goes with it is in fact mandatory' which happens with javax.validation.constraints.NotNull.
- Various problems with spring have also been reported. See issue #287, issue #271, and issue #43. */
- public static final Pattern NON_NULL_PATTERN = Pattern.compile("^(?:nonnull)$", Pattern.CASE_INSENSITIVE);
- public static final Pattern NULLABLE_PATTERN = Pattern.compile("^(?:nullable|checkfornull)$", Pattern.CASE_INSENSITIVE);
-
- /**
- * Generates a setter name from a given field name.
- *
- * Strategy:
- *
- * Check if the first character of the field is lowercase. If so, check if the second character
- * exists and is title or upper case. If so, uppercase the first character. If not, titlecase the first character.
- *
- * return "set" plus the possibly title/uppercased first character, and the rest of the field name.
- *
- * Note that if the field is boolean and starts with 'is' followed by a non-lowercase letter, the 'is' is stripped and replaced with 'set'.
- *
- * @param fieldName the name of the field.
- * @param isBoolean if the field is of type 'boolean'. For fields of type 'java.lang.Boolean', you should provide {@code false}.
- */
- public static String toSetterName(CharSequence fieldName, boolean isBoolean) {
- if (fieldName.length() == 0) return "set";
-
- if (isBoolean && fieldName.toString().startsWith("is") && fieldName.length() > 2 && !Character.isLowerCase(fieldName.charAt(2))) {
- // The field is for example named 'isRunning'.
- return "set" + fieldName.toString().substring(2);
- }
-
- return buildName("set", fieldName.toString());
- }
-
- private static String buildName(String prefix, String suffix) {
- if (suffix.length() == 0) return prefix;
-
- char first = suffix.charAt(0);
- if (Character.isLowerCase(first)) {
- boolean useUpperCase = suffix.length() > 2 &&
- (Character.isTitleCase(suffix.charAt(1)) || Character.isUpperCase(suffix.charAt(1)));
- suffix = String.format("%s%s",
- useUpperCase ? Character.toUpperCase(first) : Character.toTitleCase(first),
- suffix.subSequence(1, suffix.length()));
- }
- return String.format("%s%s", prefix, suffix);
- }
-
- /**
- * Returns all names of methods that would represent the getter for a field with the provided name.
- *
- * For example if {@code isBoolean} is true, then a field named {@code isRunning} would produce:<br />
- * {@code [isRunning, getRunning, isIsRunning, getIsRunning]}
- *
- * @param fieldName the name of the field.
- * @param isBoolean if the field is of type 'boolean'. For fields of type 'java.lang.Boolean', you should provide {@code false}.
- */
- public static List<String> toAllGetterNames(CharSequence fieldName, boolean isBoolean) {
- if (!isBoolean) return Collections.singletonList(toGetterName(fieldName, false));
-
- List<String> baseNames = new ArrayList<String>();
- baseNames.add(fieldName.toString());
-
- // isPrefix = field is called something like 'isRunning', so 'running' could also be the fieldname.
- if (fieldName.toString().startsWith("is") && fieldName.length() > 2 && !Character.isLowerCase(fieldName.charAt(2))) {
- baseNames.add(fieldName.toString().substring(2));
- }
-
- Set<String> names = new HashSet<String>();
- for (String baseName : baseNames) {
- if (baseName.length() > 0 && Character.isLowerCase(baseName.charAt(0))) {
- baseName = Character.toTitleCase(baseName.charAt(0)) + baseName.substring(1);
- }
-
- names.add("is" + baseName);
- names.add("get" + baseName);
- }
-
- return new ArrayList<String>(names);
- }
-
- /**
- * Returns all names of methods that would represent the setter for a field with the provided name.
- *
- * For example if {@code isBoolean} is true, then a field named {@code isRunning} would produce:<br />
- * {@code [setRunning, setIsRunning]}
- *
- * @param fieldName the name of the field.
- * @param isBoolean if the field is of type 'boolean'. For fields of type 'java.lang.Boolean', you should provide {@code false}.
- */
- public static List<String> toAllSetterNames(CharSequence fieldName, boolean isBoolean) {
- if (!isBoolean) return Collections.singletonList(toSetterName(fieldName, false));
-
- List<String> baseNames = new ArrayList<String>();
- baseNames.add(fieldName.toString());
-
- // isPrefix = field is called something like 'isRunning', so 'running' could also be the fieldname.
- if (fieldName.toString().startsWith("is") && fieldName.length() > 2 && !Character.isLowerCase(fieldName.charAt(2))) {
- baseNames.add(fieldName.toString().substring(2));
- }
-
- Set<String> names = new HashSet<String>();
- for (String baseName : baseNames) {
- if (baseName.length() > 0 && Character.isLowerCase(baseName.charAt(0))) {
- baseName = Character.toTitleCase(baseName.charAt(0)) + baseName.substring(1);
- }
-
- names.add("set" + baseName);
- }
-
- return new ArrayList<String>(names);
- }
-}
diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java
index fb24df93..d97746f1 100644
--- a/src/utils/lombok/javac/Javac.java
+++ b/src/utils/lombok/javac/Javac.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2011 The Project Lombok Authors.
+ * Copyright (C) 2009-2012 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,7 +27,6 @@ import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
import com.sun.tools.javac.tree.JCTree.JCIdent;
import com.sun.tools.javac.tree.JCTree.JCLiteral;
-import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
/**
* Container for static utility methods relevant to lombok's operation on javac.
@@ -38,56 +37,6 @@ public class Javac {
}
/**
- * Translates the given field into all possible getter names.
- * Convenient wrapper around {@link TransformationsUtil#toAllGetterNames(CharSequence, boolean)}.
- */
- public static java.util.List<String> toAllGetterNames(JCVariableDecl field) {
- CharSequence fieldName = field.name;
-
- boolean isBoolean = field.vartype.toString().equals("boolean");
-
- return TransformationsUtil.toAllGetterNames(fieldName, isBoolean);
- }
-
- /**
- * @return the likely getter name for the stated field. (e.g. private boolean foo; to isFoo).
- *
- * Convenient wrapper around {@link TransformationsUtil#toGetterName(CharSequence, boolean)}.
- */
- public static String toGetterName(JCVariableDecl field) {
- CharSequence fieldName = field.name;
-
- boolean isBoolean = field.vartype.toString().equals("boolean");
-
- return TransformationsUtil.toGetterName(fieldName, isBoolean);
- }
-
- /**
- * Translates the given field into all possible setter names.
- * Convenient wrapper around {@link TransformationsUtil#toAllSetterNames(CharSequence, boolean)}.
- */
- public static java.util.List<String> toAllSetterNames(JCVariableDecl field) {
- CharSequence fieldName = field.name;
-
- boolean isBoolean = field.vartype.toString().equals("boolean");
-
- return TransformationsUtil.toAllSetterNames(fieldName, isBoolean);
- }
-
- /**
- * @return the likely setter name for the stated field. (e.g. private boolean foo; to setFoo).
- *
- * Convenient wrapper around {@link TransformationsUtil#toSetterName(CharSequence, boolean)}.
- */
- public static String toSetterName(JCVariableDecl field) {
- CharSequence fieldName = field.name;
-
- boolean isBoolean = field.vartype.toString().equals("boolean");
-
- return TransformationsUtil.toSetterName(fieldName, isBoolean);
- }
-
- /**
* Checks if the given expression (that really ought to refer to a type expression) represents a primitive type.
*/
public static boolean isPrimitive(JCExpression ref) {
diff --git a/website/features/experimental/Accessors.html b/website/features/experimental/Accessors.html
new file mode 100644
index 00000000..bbcd80bb
--- /dev/null
+++ b/website/features/experimental/Accessors.html
@@ -0,0 +1,103 @@
+<!DOCTYPE html>
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <link rel="stylesheet" type="text/css" href="../../logi/reset.css" />
+ <link rel="stylesheet" type="text/css" href="../features.css" />
+ <link rel="shortcut icon" href="../../favicon.ico" type="image/x-icon" />
+ <meta name="description" content="Spice up your java" />
+ <title>EXPERIMENTAL - @Accessors</title>
+</head><body><div id="pepper">
+ <div class="minimumHeight"></div>
+ <div class="meat">
+ <div class="header"><a href="../../index.html">Project Lombok</a></div>
+ <h1>@Accessors</h1>
+ <div class="byline">A more fluent API for getters and setters.</div>
+ <div class="since">
+ <h3>Since</h3>
+ <p>
+ @Accessors was introduced as experimental feature in lombok v0.10.10.
+ </p>
+ </div>
+ <div class="experimental">
+ <h3>Experimental</h3>
+ <p>
+ Experimental because:
+ <ul>
+ <li>We may want to roll these features into a more complete property support concept.</li>
+ <li>New feature - community feedback requested.</li>
+ </ul>
+ Current status: <em>positive</em> - Currently we feel this feature may move out of experimental status with no or minor changes soon.
+ </div>
+ <div class="overview">
+ <h3>Overview</h3>
+ <p>
+ The <code>@Accessors</code> annotation is used to configure how lombok generates and looks for getters and setters.
+ </p><p>
+ By default, lombok follows the <em>bean specification</em> for getters and setters: The getter for a field named <code>pepper</code>
+ is <code>getPepper</code> for example. However, some might like to break with the <em>bean specification</em> in order to end up with
+ nicer looking APIs. <code>@Accessors</code> lets you do this.
+ </p><p>
+ Some programmers like to use a prefix for their fields, i.e. they write <code>fPepper</code> instead of <code>pepper</code>.
+ We <em>strongly</em> discourage doing this, as you can't unit test the validity of your prefixes, and refactor scripts may turn fields
+ into local variables or method names. Furthermore, your tools (such as your editor) can take care of rendering the identifier in a
+ certain way if you want this information to be instantly visible. Nevertheless, you can list the prefixes that your project uses via
+ <code>@Accessors</code> as well.
+ </p><p>
+ <code>@Accessors</code> therefore has 3 options:<ul>
+ <li><code>fluent</code> - A boolean. If <em>true</em>, the getter for <code>pepper</code> is just <code>pepper()</code>, and the
+ setter is <code>pepper(T newValue)</code>. Furthermore, unless specified, <code>chain</code> defaults to <em>true</em>.<br />
+ Default: <em>false</em>.</li>
+ <li><code>chain</code> - A boolean. If <em>true</em>, generated setters return <code>this</code> instead of <code>void</code>.<br />
+ Default: <em>false</em>, unless <code>fluent=true</code>, then Default: <em>true</em>.</li>
+ <li><code>prefix</code> - A list of strings. If present, fields must be prefixed with any of these prefixes. Each field name is
+ compared to each prefix in the list in turn, and if a match is found, the prefix is stripped out to create the base name for
+ the field. It is legal to include an empty string in the list, which will always match. For characters which are letters, the
+ character following the prefix must not be a lowercase letter, i.e. <code>pepper</code> is not a match even to prefix <code>p</code>,
+ but <code>pEpper</code> would be (and would mean the base name of this field is <code>epper</code>).</li>
+ </p><p>
+ The <code>@Accessors</code> annotation is legal on types and fields; the annotation that applies is the one on the field if present,
+ otherwise the one on the class. When a <code>@Accessors</code> annotation on a field is present, any <code>@Accessors</code> annotation
+ also present on that field's type is ignored.
+ </p>
+ </div>
+ <div class="snippets">
+ <div class="pre">
+ <h3>With Lombok</h3>
+ <div class="snippet">@HTML_PRE@</div>
+ </div>
+ <div class="sep"></div>
+ <div class="post">
+ <h3>Vanilla Java</h3>
+ <div class="snippet">@HTML_POST@</div>
+ </div>
+ </div>
+ <div style="clear: left;"></div>
+ <div class="overview">
+ <h3>Small print</h3><div class="smallprint">
+ <p>
+ The nearest <code>@Accessors</code> annotation is also used for the various methods in lombok that look for getters, such as
+ <code>@EqualsAndHashCode</code>.
+ </p><p>
+ If a prefix list is provided and a field does not start with one of them, that field is skipped entirely by lombok, and
+ a warning will be generated.
+ </p>
+ </div>
+ </div>
+ <div class="footer">
+ <a href="index.html">Back to experimental features</a> | <span class="disabled">Previous feature</span> | <span class="disabled">Next feature</span><br />
+ <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright &copy; 2009-2012 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span>
+ </div>
+ <div style="clear: both;"></div>
+ </div>
+</div>
+<script type="text/javascript">
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+</script>
+<script type="text/javascript">
+ try {
+ var pageTracker = _gat._getTracker("UA-9884254-1");
+ pageTracker._trackPageview();
+ } catch(err) {}
+</script>
+</body></html>
diff --git a/website/features/experimental/index.html b/website/features/experimental/index.html
new file mode 100644
index 00000000..e4e90c41
--- /dev/null
+++ b/website/features/experimental/index.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <link rel="stylesheet" type="text/css" href="../../logi/reset.css" />
+ <link rel="stylesheet" type="text/css" href="../features.css" />
+ <link rel="shortcut icon" href="../../favicon.ico" type="image/x-icon" />
+ <meta name="description" content="Spice up your java" />
+ <title>Lombok feature overview</title>
+</head><body><div id="pepper">
+ <div class="minimumHeight"></div>
+ <div class="meat">
+ <div class="header"><a href="../../index.html">Project Lombok</a></div>
+ <h1>Lombok experimental features</h1>
+ <div class="index overview">
+ Experimental features are available in your normal lombok installation, but are not as robustly supported as lombok's main features.
+ In particular, experimental features:<ul>
+ <li>Are not tested as well as the core features.</li>
+ <li>Do not get bugs fixed as quickly as core features.</li>
+ <li>May have APIs that will change, possibly drastically if we find a different, better way to solve the same problem.</li>
+ <li>May disappear entirely if the feature is too difficult to support or does bust enough boilerplate.</li>
+ </ul>
+ Features that receive positive community feedback and which seem to produce clean, flexible code will eventually become accepted
+ as a core feature and move out of the experimental package.
+ <dl>
+ <dt><a href="Accessors.html"><code>@Accessors</code></a></dt>
+ <dd>A more fluent API for getters and setters.</dd>
+ </dl>
+ </div>
+ <div class="footer">
+ <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright &copy; 2009-2012 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span>
+ </div>
+ <div style="clear: both;"></div>
+ </div>
+</div>
+<script type="text/javascript">
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+</script>
+<script type="text/javascript">
+ try {
+ var pageTracker = _gat._getTracker("UA-9884254-1");
+ pageTracker._trackPageview();
+ } catch(err) {}
+</script>
+</body></html>
diff --git a/website/features/index.html b/website/features/index.html
index 1a4531f4..00669bb5 100644
--- a/website/features/index.html
+++ b/website/features/index.html
@@ -38,6 +38,8 @@
<dd>Finally! Hassle-free final local variables.</dd>
<dt><a href="Delegate.html"><code>@Delegate</code></a></dt>
<dd>Don't lose your composition.</dd>
+ <dt><a href="experimental/index.html">experimental features</a></dt>
+ <dd>Here be dragons: Extra features which aren't quite ready for prime time yet.</dd>
</dl>
</div>
<div class="pointer">