Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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,10 @@
* into a warning and turn into a null value.
*/
Class<? extends Exception>[] warnExceptions() default {};

/**
* Automatically evaluate each position to null if it is null on all the blocks.
* Setting this to {@code false} requires block parameters, like {@code static boolean process(@Position int position, LongBlock field1, LongBlock field2)}
*/
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 @@ -202,7 +205,7 @@ private MethodSpec realEval(boolean blockStyle) {
if (blockStyle) {
if (processOutputsMultivalued == false) {
processFunction.args.stream().forEach(a -> a.skipNull(builder));
} else {
} else if (allNullsIsNull) {
builder.addStatement("boolean allBlocksAreNulls = true");
// allow block type inputs to be null
processFunction.args.stream().forEach(a -> a.allBlocksAreNull(builder));
Expand All @@ -214,6 +217,8 @@ private MethodSpec realEval(boolean blockStyle) {
}
builder.endControlFlow();
}
} else {
assert allNullsIsNull : "allNullsIsNull == false is only supported for block style.";
}
processFunction.args.stream().forEach(a -> a.read(builder, blockStyle));

Expand All @@ -222,16 +227,19 @@ private MethodSpec realEval(boolean blockStyle) {
pattern.append("$T.$N(");
args.add(declarationType);
args.add(processFunction.function.getSimpleName());
processFunction.args.stream().forEach(a -> {
if (args.size() > 2) {
pattern.append(", ");
}
a.buildInvocation(pattern, args, blockStyle);
});
pattern.append(processFunction.args.stream().map(argument -> {
var invocation = new StringBuilder();
argument.buildInvocation(invocation, args, blockStyle);
return invocation.toString();
}).collect(Collectors.joining(", ")));
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 {
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