mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 06:17:44 +00:00
Fix: getters and setters for $foo fields (including our own $lock!) are now no longer generated.
This commit is contained in:
1 parent
4bf8ee3f67
commit
56616f3bec
3 files changed
+7
-2
No files matched your search
@@ -87,6 +87,8 @@ public class HandleData implements EclipseAnnotationHandler<Data> {
|
||||
for (EclipseNode child : typeNode.down()) {
|
||||
if (child.getKind() != Kind.FIELD) continue;
|
||||
FieldDeclaration fieldDecl = (FieldDeclaration) child.get();
|
||||
//Skip fields that start with $
|
||||
if (fieldDecl.name.length > 0 && fieldDecl.name[0] == '$') continue;
|
||||
//Skip static fields.
|
||||
if ((fieldDecl.modifiers & ClassFileConstants.AccStatic) != 0) continue;
|
||||
boolean isFinal = (fieldDecl.modifiers & ClassFileConstants.AccFinal) != 0;
|
||||
|
||||
@@ -70,15 +70,15 @@ public class HandleData implements JavacAnnotationHandler<Data> {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<JavacNode> nodesForEquality = List.nil();
|
||||
List<JavacNode> nodesForConstructor = List.nil();
|
||||
for (JavacNode child : typeNode.down()) {
|
||||
if (child.getKind() != Kind.FIELD) continue;
|
||||
JCVariableDecl fieldDecl = (JCVariableDecl) child.get();
|
||||
//Skip fields that start with $
|
||||
if (fieldDecl.name.toString().startsWith("$")) continue;
|
||||
long fieldFlags = fieldDecl.mods.flags;
|
||||
//Skip static fields.
|
||||
if ((fieldFlags & Flags.STATIC) != 0) continue;
|
||||
if ((fieldFlags & Flags.TRANSIENT) == 0) nodesForEquality = nodesForEquality.append(child);
|
||||
boolean isFinal = (fieldFlags & Flags.FINAL) != 0;
|
||||
boolean isNonNull = !findAnnotations(child, TransformationsUtil.NON_NULL_PATTERN).isEmpty();
|
||||
if ((isFinal || isNonNull) && fieldDecl.init == null) nodesForConstructor = nodesForConstructor.append(child);
|
||||
|
||||
@@ -69,6 +69,9 @@
|
||||
<em>null</em>. Therefore, these annotations result in an explicit null check in the generated constructor for the provided field. Also, these
|
||||
annotations (as well as any annotation named <code>@Nullable</code>) are copied to the constructor parameter, in both the true constructor and
|
||||
any static constructor. The same principle applies to generated getters and setters (see the documentation for <a href="GetterSetter.html">@Getter / @Setter</a>)
|
||||
</p><p>
|
||||
By default, any variables that start with a $ symbol are excluded automatically.
|
||||
You can include them by specifying an explicit annotation (<code>@Getter</code> or <code>@ToString</code>, for example) and using the 'of' parameter.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user