mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-17 08:14:37 +00:00
[fixes #2327] mostly trivial: Added this. for field access and unified code gen of build() methods for @Builder.
This commit is contained in:
63 files changed
+144
-87
No files matched your search
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2009-2019 The Project Lombok Authors.
|
||||
* Copyright (C) 2009-2020 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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2019 The Project Lombok Authors.
|
||||
* Copyright (C) 2015-2020 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
|
||||
@@ -273,6 +273,10 @@ public class EclipseSingularsRecipes {
|
||||
|
||||
public abstract void appendBuildCode(SingularData data, EclipseNode builderType, List<Statement> statements, char[] targetVariableName, String builderVariable);
|
||||
|
||||
public boolean shadowedDuringBuild() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean requiresCleaning() {
|
||||
try {
|
||||
return !getClass().getMethod("appendCleaningCode", SingularData.class, EclipseNode.class, List.class).getDeclaringClass().equals(EclipseSingularizer.class);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2019 The Project Lombok Authors.
|
||||
* Copyright (C) 2013-2020 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
|
||||
@@ -40,7 +40,6 @@ import org.eclipse.jdt.internal.compiler.ast.Argument;
|
||||
import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Assignment;
|
||||
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression;
|
||||
import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.EqualExpression;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Expression;
|
||||
@@ -713,6 +712,13 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
|
||||
List<Expression> args = new ArrayList<Expression>();
|
||||
for (BuilderFieldData bfd : builderFields) {
|
||||
if (bfd.nameOfSetFlag != null) {
|
||||
LocalDeclaration ld = new LocalDeclaration(bfd.builderFieldName, 0, 0);
|
||||
ld.type = copyType(bfd.type);
|
||||
FieldReference builderAssign = new FieldReference(bfd.builderFieldName, 0);
|
||||
builderAssign.receiver = new ThisReference(0, 0);
|
||||
ld.initialization = builderAssign;
|
||||
statements.add(ld);
|
||||
|
||||
MessageSend inv = new MessageSend();
|
||||
inv.sourceStart = source.sourceStart;
|
||||
inv.sourceEnd = source.sourceEnd;
|
||||
@@ -720,12 +726,19 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
|
||||
inv.selector = bfd.nameOfDefaultProvider;
|
||||
inv.typeArguments = typeParameterNames(((TypeDeclaration) type.get()).typeParameters);
|
||||
|
||||
args.add(new ConditionalExpression(
|
||||
new SingleNameReference(bfd.nameOfSetFlag, 0L),
|
||||
new SingleNameReference(bfd.builderFieldName, 0L),
|
||||
inv));
|
||||
} else {
|
||||
Assignment defaultAssign = new Assignment(new SingleNameReference(bfd.builderFieldName, 0L), inv, 0);
|
||||
FieldReference thisSet = new FieldReference(bfd.nameOfSetFlag, 0L);
|
||||
thisSet.receiver = new ThisReference(0, 0);
|
||||
Expression thisNotSet = new UnaryExpression(thisSet, OperatorIds.NOT);
|
||||
statements.add(new IfStatement(thisNotSet, defaultAssign, 0, 0));
|
||||
}
|
||||
|
||||
if (bfd.nameOfSetFlag != null || (bfd.singularData != null && bfd.singularData.getSingularizer().shadowedDuringBuild())) {
|
||||
args.add(new SingleNameReference(bfd.builderFieldName, 0L));
|
||||
} else {
|
||||
FieldReference fr = new FieldReference(bfd.builderFieldName, 0L);
|
||||
fr.receiver = new ThisReference(0, 0);
|
||||
args.add(fr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2019 The Project Lombok Authors.
|
||||
* Copyright (C) 2010-2020 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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2019 The Project Lombok Authors.
|
||||
* Copyright (C) 2013-2020 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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2019 The Project Lombok Authors.
|
||||
* Copyright (C) 2013-2020 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
|
||||
@@ -661,12 +661,17 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
|
||||
}
|
||||
|
||||
ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
|
||||
Name thisName = type.toName("this");
|
||||
for (BuilderFieldData bfd : builderFields) {
|
||||
if (bfd.nameOfSetFlag != null) {
|
||||
statements.append(maker.VarDef(maker.Modifiers(0L), bfd.builderFieldName, cloneType(maker, bfd.type, source, tdParent.getContext()), maker.Select(maker.Ident(type.toName("this")), bfd.builderFieldName)));
|
||||
statements.append(maker.If(maker.Unary(CTC_NOT, maker.Ident(bfd.nameOfSetFlag)), maker.Exec(maker.Assign(maker.Ident(bfd.builderFieldName), maker.Apply(typeParameterNames(maker, ((JCClassDecl) tdParent.get()).typarams), maker.Select(maker.Ident(((JCClassDecl) tdParent.get()).name), bfd.nameOfDefaultProvider), List.<JCExpression>nil()))), null));
|
||||
statements.append(maker.VarDef(maker.Modifiers(0L), bfd.builderFieldName, cloneType(maker, bfd.type, source, tdParent.getContext()), maker.Select(maker.Ident(thisName), bfd.builderFieldName)));
|
||||
statements.append(maker.If(maker.Unary(CTC_NOT, maker.Select(maker.Ident(thisName), bfd.nameOfSetFlag)), maker.Exec(maker.Assign(maker.Ident(bfd.builderFieldName), maker.Apply(typeParameterNames(maker, ((JCClassDecl) tdParent.get()).typarams), maker.Select(maker.Ident(((JCClassDecl) tdParent.get()).name), bfd.nameOfDefaultProvider), List.<JCExpression>nil()))), null));
|
||||
}
|
||||
if (bfd.nameOfSetFlag != null || (bfd.singularData != null && bfd.singularData.getSingularizer().shadowedDuringBuild())) {
|
||||
args.append(maker.Ident(bfd.builderFieldName));
|
||||
} else {
|
||||
args.append(maker.Select(maker.Ident(thisName), bfd.builderFieldName));
|
||||
}
|
||||
args.append(maker.Ident(bfd.builderFieldName));
|
||||
}
|
||||
|
||||
if (addCleaning) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2019 The Project Lombok Authors.
|
||||
* Copyright (C) 2013-2020 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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2009-2019 The Project Lombok Authors.
|
||||
* Copyright (C) 2009-2020 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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2019 The Project Lombok Authors.
|
||||
* Copyright (C) 2015-2020 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
|
||||
@@ -344,6 +344,10 @@ public class JavacSingularsRecipes {
|
||||
|
||||
public abstract void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable);
|
||||
|
||||
public boolean shadowedDuringBuild() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean requiresCleaning() {
|
||||
try {
|
||||
return !getClass().getMethod("appendCleaningCode", SingularData.class, JavacNode.class, JCTree.class, ListBuffer.class).getDeclaringClass().equals(JavacSingularizer.class);
|
||||
|
||||
Reference in new issue
Block a user