Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional prefixes to Builder setter method names #2174

Merged
merged 25 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
64fc7b3
Add iml files to gitignore
floralvikings Jul 10, 2019
5f198d7
Add setterPrefix to Builder annotation
floralvikings Jul 10, 2019
96151ad
Add tests for prefixed builder
floralvikings Jul 10, 2019
88bf742
Implement prefixed setters
floralvikings Jul 10, 2019
4dc5c32
Merge branch 'master' of github.com:rzwitserloot/lombok into feature/…
floralvikings Jul 16, 2019
dc56309
Merge branch 'master' of github.com:rzwitserloot/lombok into feature/…
floralvikings Sep 11, 2019
2baefe0
Explicitly recommend against prefixes
floralvikings Sep 11, 2019
66fbde5
Add myself to AUTHORS
floralvikings Sep 11, 2019
cc07025
Remove extraneous import
floralvikings Sep 11, 2019
36287f2
Duplicate builder tests with setter prefix
floralvikings Sep 12, 2019
5b16b48
Fix class names in after-ecj
floralvikings Sep 12, 2019
f222050
Fix class names in before
floralvikings Sep 12, 2019
8b30eee
Adjusted test classes to include WithSetterPrefix.
atbrinkman Sep 12, 2019
288ee7b
Merge branch 'feature/builder-setter-prefixes' of https://github.com/…
atbrinkman Sep 12, 2019
e1bd41f
Added setterPrefix to javac
atbrinkman Sep 19, 2019
bae66a3
Fix null pointers and incorrect tests
floralvikings Sep 19, 2019
4b6588e
Fix test copy/paste errors
floralvikings Sep 19, 2019
24a49a9
Fix more copy/paste test errors
floralvikings Sep 19, 2019
ffb2997
Fix more broken tests
floralvikings Sep 19, 2019
666defa
Fix up some more tests and copy-paste errors
floralvikings Oct 25, 2019
65302bc
More test fixes
floralvikings Oct 28, 2019
7a8bc61
Remove now-unused variables
floralvikings Oct 28, 2019
2a7afbc
Fix more singulars and tests
floralvikings Oct 28, 2019
1b0c2f3
Fix eclipse map singularization
floralvikings Oct 28, 2019
b7e42d1
Fix last test
floralvikings Oct 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
/.factorypath
/lombok.iml
/.idea
*.iml
*.markdown.html
/junit*.properties
/eclipse.location
/.apt_generated/
/out
/website/lombokSupporters
/pom.xml
/pom.xml
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Lombok contributors in alphabetical order:

Adam Juraszek <juriad@gmail.com>
Bulgakov Alexander <buls@yandex.ru>
Caleb Brinkman <floralvikings@gmail.com>
Christian Nüssgens <christian@nuessgens.com>
Christian Sterzl <christian.sterzl@gmail.com>
DaveLaw <project.lombok@apconsult.de>
Expand Down
13 changes: 13 additions & 0 deletions src/core/lombok/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@
* @return The builder class will be generated with this access modifier.
*/
AccessLevel access() default lombok.AccessLevel.PUBLIC;

/**
* Prefix to prepend to set methods in the generated builder class. By default, generated methods to not include a
* prefix. If this value populated, the first letter of the generated method name will be capitalized.
*
* For example, a method normally generated as {@code someField(String someField)} would instead be generated as {@code withSomeField(String someField)}
*
* Note that using "with" to prefix builder setter methods is strongly discouraged as as "with" normally
* suggests immutable data structures, and builders by definition are mutable objects.
*
* @return The prefix to prepend to generated method names.
*/
String setterPrefix() default "";

/**
* Put on a field (in case of {@code @Builder} on a type) or a parameter (for {@code @Builder} on a constructor or static method) to
Expand Down
21 changes: 19 additions & 2 deletions src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public static final class SingularData {
private final EclipseNode annotation;
private final char[] singularName;
private final char[] pluralName;
private final char[] setterPrefix;
private final List<TypeReference> typeArgs;
private final String targetFqn;
private final EclipseSingularizer singularizer;
Expand All @@ -133,8 +134,20 @@ public SingularData(EclipseNode annotation, char[] singularName, char[] pluralNa
this.targetFqn = targetFqn;
this.singularizer = singularizer;
this.source = source;
this.setterPrefix = new char[0];
}


public SingularData(EclipseNode annotation, char[] singularName, char[] pluralName, List<TypeReference> typeArgs, String targetFqn, EclipseSingularizer singularizer, ASTNode source, char[] setterPrefix) {
this.annotation = annotation;
this.singularName = singularName;
this.pluralName = pluralName;
this.typeArgs = typeArgs;
this.targetFqn = targetFqn;
this.singularizer = singularizer;
this.source = source;
this.setterPrefix = setterPrefix;
}

public void setGeneratedByRecursive(ASTNode target) {
SetGeneratedByVisitor visitor = new SetGeneratedByVisitor(source);

Expand Down Expand Up @@ -162,7 +175,11 @@ public char[] getSingularName() {
public char[] getPluralName() {
return pluralName;
}


public char[] getSetterPrefix() {
return setterPrefix;
}

public List<TypeReference> getTypeArgs() {
return typeArgs;
}
Expand Down
Loading