Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@
* into a warning and turn into a null value.
*/
Class<? extends Exception>[] warnExceptions() default {};

/**
* if we evaluate to null if all blocks are null
*/
boolean allNullsIsNull() default true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ public class EvaluatorImplementer {
private final ProcessFunction processFunction;
private final ClassName implementation;
private final boolean processOutputsMultivalued;
private final boolean allNullsIsNull;

public EvaluatorImplementer(
Elements elements,
javax.lang.model.util.Types types,
ExecutableElement processFunction,
String extraName,
List<TypeMirror> warnExceptions
List<TypeMirror> warnExceptions,
boolean allNullsIsNull
) {
this.declarationType = (TypeElement) processFunction.getEnclosingElement();
this.processFunction = new ProcessFunction(types, processFunction, warnExceptions);
Expand All @@ -66,7 +68,8 @@ public EvaluatorImplementer(
elements.getPackageOf(declarationType).toString(),
declarationType.getSimpleName() + extraName + "Evaluator"
);
this.processOutputsMultivalued = this.processFunction.hasBlockType && (this.processFunction.builderArg != null);
this.processOutputsMultivalued = this.processFunction.hasBlockType;
this.allNullsIsNull = allNullsIsNull;
}

public JavaFile sourceFile() {
Expand Down Expand Up @@ -199,7 +202,7 @@ private MethodSpec realEval(boolean blockStyle) {

builder.beginControlFlow("position: for (int p = 0; p < positionCount; p++)");
{
if (blockStyle) {
if (blockStyle && allNullsIsNull) {
if (processOutputsMultivalued == false) {
processFunction.args.stream().forEach(a -> a.skipNull(builder));
} else {
Expand All @@ -223,15 +226,21 @@ private MethodSpec realEval(boolean blockStyle) {
args.add(declarationType);
args.add(processFunction.function.getSimpleName());
processFunction.args.stream().forEach(a -> {
if (args.size() > 2) {
if (pattern.subSequence(pattern.length() - 1, pattern.length()).equals("(") == false) {
pattern.append(", ");
}
a.buildInvocation(pattern, args, blockStyle);
});
pattern.append(")");
String builtPattern;
if (processFunction.builderArg == null) {
builtPattern = vectorize ? "result.$L(p, " + pattern + ")" : "result.$L(" + pattern + ")";
if (vectorize) {
builtPattern = "result.$L(p, " + pattern + ")";
} else if (processOutputsMultivalued) {
builtPattern = "result.beginPositionEntry().$L(" + pattern + ").endPositionEntry()";
} else {
builtPattern = "result.$L(" + pattern + ")";
}
args.add(0, processFunction.appendMethod());
} else {
builtPattern = pattern.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnv
env.getTypeUtils(),
(ExecutableElement) evaluatorMethod,
evaluatorAnn.extraName(),
warnExceptionsTypes
warnExceptionsTypes,
evaluatorAnn.allNullsIsNull()
).sourceFile(),
env
);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading