aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2018-06-13 23:21:00 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2018-06-13 23:21:00 +0200
commit19ad4fd57d32afad1a33f20613fbb2e7607cfee0 (patch)
tree694dedb4dcd2399194f9abb612232a28f8292a45 /src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java
parent3256ab6fc71b2b52fe2aedcbf0f59f8f95a0d7e5 (diff)
downloadlombok-19ad4fd57d32afad1a33f20613fbb2e7607cfee0.tar.gz
lombok-19ad4fd57d32afad1a33f20613fbb2e7607cfee0.tar.bz2
lombok-19ad4fd57d32afad1a33f20613fbb2e7607cfee0.zip
[SuperBuilder] code review, style update, making it JDK1.6 compatible, documentation review, bugfix for setter auto-presuming chaining even when you didn’t configure it to chain.
Diffstat (limited to 'src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java45
1 files changed, 25 insertions, 20 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java
index e24cd5b5..b9b9e07d 100644
--- a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java
+++ b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015-2017 The Project Lombok Authors.
+ * Copyright (C) 2015-2018 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
@@ -30,7 +30,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.function.Supplier;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
@@ -65,6 +64,14 @@ import lombok.core.TypeLibrary;
import lombok.eclipse.EclipseNode;
public class EclipseSingularsRecipes {
+ public interface TypeReferenceMaker {
+ TypeReference make();
+ }
+
+ public interface StatementMaker {
+ Statement make();
+ }
+
private static final EclipseSingularsRecipes INSTANCE = new EclipseSingularsRecipes();
private final Map<String, EclipseSingularizer> singularizers = new HashMap<String, EclipseSingularizer>();
private final TypeLibrary singularizableTypes = new TypeLibrary();
@@ -220,37 +227,35 @@ public class EclipseSingularsRecipes {
}
public abstract List<EclipseNode> generateFields(SingularData data, EclipseNode builderType);
-
+
/**
- * Generates the singular, plural, and clear methods for the given
- * {@link SingularData}.<br>
- * Uses the given <code>builderType</code> as return type if
- * <code>chain == true</code>, <code>void</code> otherwise. If you need more
- * control over the return type and value, use
- * {@link #generateMethods(SingularData, boolean, EclipseNode, boolean, Supplier, Supplier)}.
+ * Generates the singular, plural, and clear methods for the given {@link SingularData}.
+ * Uses the given {@code builderType} as return type if {@code chain == true}, {@code void} otherwise.
+ * If you need more control over the return type and value, use
+ * {@link #generateMethods(SingularData, boolean, EclipseNode, boolean, TypeReferenceMaker, StatementMaker)}.
*/
public void generateMethods(SingularData data, boolean deprecate, final EclipseNode builderType, boolean fluent, final boolean chain) {
- // TODO: Make these lambdas when switching to a source level >= 1.8.
- Supplier<TypeReference> returnType = new Supplier<TypeReference>() {
- @Override public TypeReference get() {
+ TypeReferenceMaker returnTypeMaker = new TypeReferenceMaker() {
+ @Override public TypeReference make() {
return chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
}
};
- Supplier<ReturnStatement> returnStatement = new Supplier<ReturnStatement>() {
- @Override public ReturnStatement get() {
+
+ StatementMaker returnStatementMaker = new StatementMaker() {
+ @Override public ReturnStatement make() {
return chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
}
};
- generateMethods(data, deprecate, builderType, fluent, returnType, returnStatement);
+
+ generateMethods(data, deprecate, builderType, fluent, returnTypeMaker, returnStatementMaker);
}
/**
- * Generates the singular, plural, and clear methods for the given
- * {@link SingularData}.<br>
- * Uses the given <code>returnType</code> and <code>returnStatement</code> for the generated methods.
+ * Generates the singular, plural, and clear methods for the given {@link SingularData}.
+ * Uses the given {@code returnTypeMaker} and {@code returnStatementMaker} for the generated methods.
*/
- public abstract void generateMethods(SingularData data, boolean deprecate, EclipseNode builderType, boolean fluent, Supplier<TypeReference> returnType, Supplier<ReturnStatement> returnStatement);
-
+ public abstract void generateMethods(SingularData data, boolean deprecate, EclipseNode builderType, boolean fluent, TypeReferenceMaker returnTypeMaker, StatementMaker returnStatementMaker);
+
public abstract void appendBuildCode(SingularData data, EclipseNode builderType, List<Statement> statements, char[] targetVariableName, String builderVariable);
public boolean requiresCleaning() {