Skip to content

Commit

Permalink
[issue projectlombok#2368] [withBy] support for ecj
Browse files Browse the repository at this point in the history
  • Loading branch information
rzwitserloot authored and Febell committed Mar 1, 2020
1 parent 0f7fd11 commit f2bf308
Show file tree
Hide file tree
Showing 5 changed files with 464 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
Expand Up @@ -1589,6 +1589,14 @@ public static java.util.List<String> toAllWithNames(EclipseNode field, boolean i
return HandlerUtil.toAllWithNames(field.getAst(), getAccessorsForField(field), field.getName(), isBoolean);
}

/**
* Translates the given field into all possible withBy names.
* Convenient wrapper around {@link HandlerUtil#toAllWithByNames(lombok.core.AnnotationValues, CharSequence, boolean)}.
*/
public static java.util.List<String> toAllWithByNames(EclipseNode field, boolean isBoolean) {
return HandlerUtil.toAllWithByNames(field.getAst(), getAccessorsForField(field), field.getName(), isBoolean);
}

/**
* @return the likely with name for the stated field. (e.g. private boolean foo; to withFoo).
*
Expand All @@ -1598,6 +1606,15 @@ public static String toWithName(EclipseNode field, boolean isBoolean) {
return HandlerUtil.toWithName(field.getAst(), getAccessorsForField(field), field.getName(), isBoolean);
}

/**
* @return the likely withBy name for the stated field. (e.g. private boolean foo; to withFooBy).
*
* Convenient wrapper around {@link HandlerUtil#toWithByName(lombok.core.AnnotationValues, CharSequence, boolean)}.
*/
public static String toWithByName(EclipseNode field, boolean isBoolean) {
return HandlerUtil.toWithByName(field.getAst(), getAccessorsForField(field), field.getName(), isBoolean);
}

/**
* When generating a setter, the setter either returns void (beanspec) or Self (fluent).
* This method scans for the {@code Accessors} annotation and associated config properties to figure that out.
Expand Down
10 changes: 5 additions & 5 deletions src/core/lombok/eclipse/handlers/HandleWith.java
Expand Up @@ -121,7 +121,7 @@ public void generateWithForField(EclipseNode fieldNode, EclipseNode sourceNode,
}

@Override public void handle(AnnotationValues<With> annotation, Annotation ast, EclipseNode annotationNode) {
handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.WITH_FLAG_USAGE, "@With");
handleFlagUsage(annotationNode, ConfigurationKeys.WITH_FLAG_USAGE, "@With");

EclipseNode node = annotationNode.up();
AccessLevel level = annotation.getInstance().value();
Expand Down Expand Up @@ -153,9 +153,9 @@ public void createWithForFields(AccessLevel level, Collection<EclipseNode> field
}

public void createWithForField(
AccessLevel level, EclipseNode fieldNode, EclipseNode sourceNode,
boolean whineIfExists, List<Annotation> onMethod,
List<Annotation> onParam) {
AccessLevel level, EclipseNode fieldNode, EclipseNode sourceNode,
boolean whineIfExists, List<Annotation> onMethod,
List<Annotation> onParam) {

ASTNode source = sourceNode.get();
if (fieldNode.getKind() != Kind.FIELD) {
Expand Down Expand Up @@ -215,7 +215,7 @@ public void createWithForField(
injectMethod(fieldNode.up(), method);
}

public MethodDeclaration createWith(TypeDeclaration parent, EclipseNode fieldNode, String name, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam, boolean makeAbstract ) {
public MethodDeclaration createWith(TypeDeclaration parent, EclipseNode fieldNode, String name, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam, boolean makeAbstract) {
ASTNode source = sourceNode.get();
if (name == null) return null;
FieldDeclaration field = (FieldDeclaration) fieldNode.get();
Expand Down

0 comments on commit f2bf308

Please sign in to comment.