From a6678da649bd971132a3a467c0495b8b480e8735 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Thu, 28 May 2020 21:57:30 +0300 Subject: [PATCH] WIP: linq4j nullability --- linq4j/build.gradle.kts | 1 + .../apache/calcite/linq4j/ModularInteger.java | 4 +- .../calcite/linq4j/tree/AbstractNode.java | 6 ++- .../linq4j/tree/ArrayLengthRecordField.java | 4 +- .../calcite/linq4j/tree/BinaryExpression.java | 9 +++-- .../calcite/linq4j/tree/BlockBuilder.java | 14 ++++--- .../calcite/linq4j/tree/BlockStatement.java | 8 ++-- .../calcite/linq4j/tree/CatchBlock.java | 4 +- .../calcite/linq4j/tree/ClassDeclaration.java | 6 ++- .../linq4j/tree/ClassDeclarationFinder.java | 6 ++- .../linq4j/tree/ConditionalExpression.java | 6 ++- .../linq4j/tree/ConditionalStatement.java | 6 ++- .../linq4j/tree/ConstantExpression.java | 14 ++++--- .../linq4j/tree/ConstantUntypedNull.java | 4 +- .../linq4j/tree/ConstructorDeclaration.java | 6 ++- .../linq4j/tree/DeclarationStatement.java | 6 ++- .../linq4j/tree/DefaultExpression.java | 4 +- .../tree/DeterministicCodeOptimizer.java | 12 +++--- .../linq4j/tree/DynamicExpression.java | 4 +- .../calcite/linq4j/tree/ExpressionType.java | 12 +++--- .../calcite/linq4j/tree/ExpressionWriter.java | 6 ++- .../calcite/linq4j/tree/Expressions.java | 35 ++++++++-------- .../calcite/linq4j/tree/FieldDeclaration.java | 10 +++-- .../calcite/linq4j/tree/ForEachStatement.java | 6 ++- .../calcite/linq4j/tree/ForStatement.java | 12 +++--- .../linq4j/tree/FunctionExpression.java | 12 +++--- .../calcite/linq4j/tree/GotoStatement.java | 16 ++++---- .../calcite/linq4j/tree/IndexExpression.java | 6 ++- .../linq4j/tree/InvocationExpression.java | 4 +- .../calcite/linq4j/tree/LabelStatement.java | 6 ++- .../calcite/linq4j/tree/LabelTarget.java | 4 +- .../calcite/linq4j/tree/LambdaExpression.java | 4 +- .../linq4j/tree/ListInitExpression.java | 4 +- .../calcite/linq4j/tree/MemberExpression.java | 12 +++--- .../linq4j/tree/MemberInitExpression.java | 4 +- .../linq4j/tree/MethodCallExpression.java | 14 ++++--- .../linq4j/tree/MethodDeclaration.java | 6 ++- .../linq4j/tree/NewArrayExpression.java | 14 ++++--- .../calcite/linq4j/tree/NewExpression.java | 10 +++-- .../calcite/linq4j/tree/OptimizeShuttle.java | 4 +- .../linq4j/tree/ParameterExpression.java | 8 ++-- .../apache/calcite/linq4j/tree/Primitive.java | 40 ++++++++++--------- .../linq4j/tree/ReflectedPseudoField.java | 6 ++- .../apache/calcite/linq4j/tree/Shuttle.java | 8 ++-- .../calcite/linq4j/tree/SwitchStatement.java | 4 +- .../linq4j/tree/TernaryExpression.java | 6 ++- .../calcite/linq4j/tree/ThrowStatement.java | 6 ++- .../calcite/linq4j/tree/TryStatement.java | 6 ++- .../linq4j/tree/TypeBinaryExpression.java | 6 ++- .../org/apache/calcite/linq4j/tree/Types.java | 12 +++--- .../calcite/linq4j/tree/UnaryExpression.java | 6 ++- .../apache/calcite/linq4j/tree/Visitor.java | 4 +- .../calcite/linq4j/tree/VisitorImpl.java | 4 +- .../calcite/linq4j/tree/WhileStatement.java | 6 ++- 54 files changed, 277 insertions(+), 170 deletions(-) diff --git a/linq4j/build.gradle.kts b/linq4j/build.gradle.kts index 7a9db175f24e..05f7e1965dd3 100644 --- a/linq4j/build.gradle.kts +++ b/linq4j/build.gradle.kts @@ -19,4 +19,5 @@ dependencies { implementation("com.google.guava:guava") implementation("org.apache.calcite.avatica:avatica-core") + implementation("org.checkerframework:checker-qual") } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/ModularInteger.java b/linq4j/src/main/java/org/apache/calcite/linq4j/ModularInteger.java index e6b7695eefe7..12cc470c468d 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/ModularInteger.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/ModularInteger.java @@ -18,6 +18,8 @@ import com.google.common.base.Preconditions; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * Represents an integer in modular arithmetic. * Its {@code value} is between 0 and {@code m - 1} for some modulus {@code m}. @@ -35,7 +37,7 @@ class ModularInteger { this.modulus = modulus; } - @Override public boolean equals(Object obj) { + @Override public boolean equals(@Nullable Object obj) { return obj == this || obj instanceof ModularInteger && value == ((ModularInteger) obj).value diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/AbstractNode.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/AbstractNode.java index 014db9045ccb..0a2622564d9d 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/AbstractNode.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/AbstractNode.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Type; import java.util.Objects; @@ -70,12 +72,12 @@ public Node accept(Shuttle shuttle) { "visit not supported: " + getClass() + ":" + nodeType); } - public Object evaluate(Evaluator evaluator) { + public @Nullable Object evaluate(Evaluator evaluator) { throw new RuntimeException( "evaluation not supported: " + getClass() + ":" + nodeType); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ArrayLengthRecordField.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ArrayLengthRecordField.java index 780ea62cd092..3b615f4f1cbf 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ArrayLengthRecordField.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ArrayLengthRecordField.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Array; import java.lang.reflect.Type; import java.util.Objects; @@ -58,7 +60,7 @@ public Type getDeclaringClass() { return clazz; } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/BinaryExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/BinaryExpression.java index a18025c2c9f0..d8c5d33e4832 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/BinaryExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/BinaryExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Type; import java.util.Objects; @@ -44,7 +46,7 @@ public class BinaryExpression extends Expression { return visitor.visit(this, expression0, expression1); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -88,8 +90,7 @@ public Object evaluate(Evaluator evaluator) { throw cannotEvaluate(); } case Equal: - return expression0.evaluate(evaluator) - .equals(expression1.evaluate(evaluator)); + return Objects.equals(expression0.evaluate(evaluator), expression1.evaluate(evaluator)); case GreaterThan: switch (primitive) { case INT: @@ -241,7 +242,7 @@ private double evaluateDouble(Expression expression, Evaluator evaluator) { return ((Number) expression.evaluate(evaluator)).doubleValue(); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/BlockBuilder.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/BlockBuilder.java index f8d15a6c3c6e..afe1a3556925 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/BlockBuilder.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/BlockBuilder.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Modifier; import java.lang.reflect.Type; import java.util.ArrayList; @@ -41,7 +43,7 @@ public class BlockBuilder { new HashMap<>(); private final boolean optimizing; - private final BlockBuilder parent; + private final @Nullable BlockBuilder parent; private static final Shuttle OPTIMIZE_SHUTTLE = new OptimizeShuttle(); @@ -66,7 +68,7 @@ public BlockBuilder(boolean optimizing) { * * @param optimizing Whether to eliminate common sub-expressions */ - public BlockBuilder(boolean optimizing, BlockBuilder parent) { + public BlockBuilder(boolean optimizing, @Nullable BlockBuilder parent) { this.optimizing = optimizing; this.parent = parent; } @@ -85,7 +87,7 @@ public void clear() { * (possibly a variable) that represents the result of the newly added * block. */ - public Expression append(String name, BlockStatement block) { + public @Nullable Expression append(String name, BlockStatement block) { return append(name, block, true); } @@ -99,7 +101,7 @@ public Expression append(String name, BlockStatement block) { * a variable. Do not do this if the expression has * side-effects or a time-dependent value. */ - public Expression append(String name, BlockStatement block, + public @Nullable Expression append(String name, BlockStatement block, boolean optimize) { if (statements.size() > 0) { Statement lastStatement = statements.get(statements.size() - 1); @@ -184,7 +186,7 @@ public Expression append(String name, Expression expression) { /** * Appends an expression to a list of statements, if it is not null. */ - public Expression appendIfNotNull(String name, Expression expression) { + public @Nullable Expression appendIfNotNull(String name, @Nullable Expression expression) { if (expression == null) { return null; } @@ -283,7 +285,7 @@ private Expression normalizeDeclaration(DeclarationStatement decl) { * @param expr expression to test * @return existing ParameterExpression or null */ - public DeclarationStatement getComputedExpression(Expression expr) { + public @Nullable DeclarationStatement getComputedExpression(Expression expr) { if (parent != null) { DeclarationStatement decl = parent.getComputedExpression(expr); if (decl != null) { diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/BlockStatement.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/BlockStatement.java index 33e8f78de972..5a42b50326c8 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/BlockStatement.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/BlockStatement.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Type; import java.util.HashSet; import java.util.List; @@ -61,7 +63,7 @@ private boolean distinctVariables(boolean fail) { return shuttle.visit(this, newStatements); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -77,7 +79,7 @@ public R accept(Visitor visitor) { writer.end("}\n"); } - @Override public Object evaluate(Evaluator evaluator) { + @Override public @Nullable Object evaluate(Evaluator evaluator) { Object o = null; for (Statement statement : statements) { o = statement.evaluate(evaluator); @@ -85,7 +87,7 @@ public R accept(Visitor visitor) { return o; } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/CatchBlock.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/CatchBlock.java index 732d63b6b88b..21aff57d96f7 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/CatchBlock.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/CatchBlock.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.util.Objects; /** @@ -31,7 +33,7 @@ public CatchBlock(ParameterExpression parameter, this.body = body; } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ClassDeclaration.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ClassDeclaration.java index f4e0c9a266c7..f858ba992b37 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ClassDeclaration.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ClassDeclaration.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Modifier; import java.lang.reflect.Type; import java.util.List; @@ -66,11 +68,11 @@ public ClassDeclaration accept(Shuttle shuttle) { return shuttle.visit(this, members1); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ClassDeclarationFinder.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ClassDeclarationFinder.java index 6373931df3da..89400626826c 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ClassDeclarationFinder.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ClassDeclarationFinder.java @@ -18,6 +18,8 @@ import org.apache.calcite.linq4j.function.Function1; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -30,7 +32,7 @@ * created for optimizing a new expression tree. */ public class ClassDeclarationFinder extends Shuttle { - protected final ClassDeclarationFinder parent; + protected final @Nullable ClassDeclarationFinder parent; /** * The list of new final static fields to be added to the current class. @@ -254,7 +256,7 @@ protected boolean isConstant(Iterable list) { * @param expression input expression * @return always returns null */ - protected ParameterExpression findDeclaredExpression(Expression expression) { + protected @Nullable ParameterExpression findDeclaredExpression(Expression expression) { return null; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConditionalExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConditionalExpression.java index 55c00cefba48..73d1a1991842 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConditionalExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConditionalExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Type; import java.util.List; import java.util.Objects; @@ -41,7 +43,7 @@ public ConditionalExpression(List expressionList, Type type) { this.expressionList = expressionList; } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -59,7 +61,7 @@ public R accept(Visitor visitor) { } } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConditionalStatement.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConditionalStatement.java index 9d15a458bed9..8f36414d50aa 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConditionalStatement.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConditionalStatement.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.util.List; import java.util.Objects; @@ -46,7 +48,7 @@ public ConditionalStatement(List expressionList) { return shuttle.visit(this, list); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -72,7 +74,7 @@ private static E last(List collection) { return collection.get(collection.size() - 1); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstantExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstantExpression.java index 38b75879bc5c..cb26a11205f9 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstantExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstantExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Type; @@ -32,9 +34,9 @@ * Represents an expression that has a constant value. */ public class ConstantExpression extends Expression { - public final Object value; + public final @Nullable Object value; - public ConstantExpression(Type type, Object value) { + public ConstantExpression(Type type, @Nullable Object value) { super(ExpressionType.Constant, type); this.value = value; if (value != null) { @@ -54,7 +56,7 @@ public ConstantExpression(Type type, Object value) { } } - public Object evaluate(Evaluator evaluator) { + public @Nullable Object evaluate(Evaluator evaluator) { return value; } @@ -62,7 +64,7 @@ public Object evaluate(Evaluator evaluator) { return shuttle.visit(this); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -77,7 +79,7 @@ public R accept(Visitor visitor) { } private static ExpressionWriter write(ExpressionWriter writer, - final Object value, Type type) { + final Object value, @Nullable Type type) { if (value == null) { return writer.append("null"); } @@ -328,7 +330,7 @@ private static void escapeString(StringBuilder buf, String s) { buf.append('"'); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { // REVIEW: Should constants with the same value and different type // (e.g. 3L and 3) be considered equal. if (this == o) { diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstantUntypedNull.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstantUntypedNull.java index 48ab4ee8452b..204f82d8e901 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstantUntypedNull.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstantUntypedNull.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * Represents a constant null of unknown type * Java allows type inference for such nulls, thus "null" cannot always be @@ -36,7 +38,7 @@ private ConstantUntypedNull() { writer.append("null"); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { return o == INSTANCE; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstructorDeclaration.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstructorDeclaration.java index 40ed8603b538..ef7cd8111dc0 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstructorDeclaration.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ConstructorDeclaration.java @@ -18,6 +18,8 @@ import com.google.common.collect.Lists; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Modifier; import java.lang.reflect.Type; import java.util.List; @@ -54,7 +56,7 @@ public ConstructorDeclaration(int modifier, Type declaredAgainst, return shuttle.visit(this, body); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -78,7 +80,7 @@ public void accept(ExpressionWriter writer) { writer.newlineAndIndent(); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DeclarationStatement.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DeclarationStatement.java index 31a529dcecce..075801a7ee44 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DeclarationStatement.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DeclarationStatement.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Modifier; import java.util.Objects; @@ -45,7 +47,7 @@ public DeclarationStatement(int modifiers, ParameterExpression parameter, return shuttle.visit(this, initializer); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -78,7 +80,7 @@ public void accept2(ExpressionWriter writer, boolean withType) { } } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DefaultExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DefaultExpression.java index 57381686917a..13d956414908 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DefaultExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DefaultExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * Represents the default value of a type or an empty expression. */ @@ -28,7 +30,7 @@ public DefaultExpression(Class type) { return shuttle.visit(this); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DeterministicCodeOptimizer.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DeterministicCodeOptimizer.java index abc71a7f61d3..f34a695fab26 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DeterministicCodeOptimizer.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DeterministicCodeOptimizer.java @@ -21,6 +21,8 @@ import com.google.common.collect.ImmutableSet; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -176,7 +178,7 @@ && isMethodDeterministic(methodCallExpression.method)) { } @Override public Expression visit(MemberExpression memberExpression, - Expression expression) { + @Nullable Expression expression) { Expression result = super.visit(memberExpression, expression); if (isConstant(expression) @@ -224,7 +226,7 @@ && isMethodDeterministic(methodCallExpression.method)) { * @param expression input expression * @return parameter of the already existing declaration, or null */ - protected ParameterExpression findDeclaredExpression(Expression expression) { + protected @Nullable ParameterExpression findDeclaredExpression(Expression expression) { if (!dedup.isEmpty()) { ParameterExpression pe = dedup.get(expression); if (pe != null) { @@ -294,7 +296,7 @@ protected String inventFieldName(Expression expression) { * @param expression expression to test * @return true when the expression is known to be constant */ - @Override protected boolean isConstant(Expression expression) { + @Override protected boolean isConstant(@Nullable Expression expression) { return expression == null || expression instanceof ConstantExpression || !constants.isEmpty() && constants.containsKey(expression) @@ -330,7 +332,7 @@ protected boolean isConstructorDeterministic(NewExpression newExpression) { && constructor.isAnnotationPresent(Deterministic.class); } - private Constructor getConstructor(Class klass) { + private @Nullable Constructor getConstructor(Class klass) { try { return klass.getConstructor(); } catch (NoSuchMethodException e) { @@ -347,7 +349,7 @@ private Constructor getConstructor(Class klass) { */ protected boolean allMethodsDeterministic(Class klass) { return DETERMINISTIC_CLASSES.contains(klass) - || klass.getCanonicalName().equals("org.apache.calcite.avatica.util.DateTimeUtils") + || "org.apache.calcite.avatica.util.DateTimeUtils".equals(klass.getCanonicalName()) || klass.isAnnotationPresent(Deterministic.class); } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DynamicExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DynamicExpression.java index e56f1b899188..42d14042405c 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DynamicExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/DynamicExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * Represents a dynamic operation. */ @@ -28,7 +30,7 @@ public DynamicExpression(Class type) { return shuttle.visit(this); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ExpressionType.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ExpressionType.java index 636620af0318..5f20ae169d37 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ExpressionType.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ExpressionType.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + /** *

Analogous to LINQ's System.Linq.Expressions.ExpressionType.

*/ @@ -596,8 +598,8 @@ public enum ExpressionType { */ While; - final String op; - final String op2; + final @Nullable String op; + final @Nullable String op2; final boolean postfix; final int lprec; final int rprec; @@ -607,16 +609,16 @@ public enum ExpressionType { this(null, false, 0, false); } - ExpressionType(String op, boolean postfix, int prec, boolean right) { + ExpressionType(@Nullable String op, boolean postfix, int prec, boolean right) { this(op, null, postfix, prec, right); } - ExpressionType(String op, String op2, boolean postfix, int prec, + ExpressionType(@Nullable String op, @Nullable String op2, boolean postfix, int prec, boolean right) { this(op, op2, postfix, prec, right, false); } - ExpressionType(String op, String op2, boolean postfix, int prec, + ExpressionType(@Nullable String op, @Nullable String op2, boolean postfix, int prec, boolean right, boolean modifiesLvalue) { this.op = op; this.op2 = op2; diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ExpressionWriter.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ExpressionWriter.java index cb7c9113d90e..8bc640bac6e4 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ExpressionWriter.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ExpressionWriter.java @@ -18,6 +18,8 @@ import org.apache.calcite.avatica.util.Spacer; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Type; import java.util.Iterator; @@ -130,13 +132,13 @@ public ExpressionWriter append(AbstractNode o) { return this; } - public ExpressionWriter append(Object o) { + public ExpressionWriter append(@Nullable Object o) { checkIndent(); buf.append(o); return this; } - public ExpressionWriter append(String s) { + public ExpressionWriter append(@Nullable String s) { checkIndent(); buf.append(s); return this; diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Expressions.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Expressions.java index 8260055542d9..ea94ccc5b42c 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Expressions.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Expressions.java @@ -26,6 +26,8 @@ import com.google.common.collect.ImmutableList; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Member; @@ -283,7 +285,7 @@ public static BlockStatement block(Statement... statements) { * Creates a BlockExpression that contains the given expressions, * has no variables and has specific result type. */ - public static BlockStatement block(Type type, + public static BlockStatement block(@Nullable Type type, Iterable expressions) { List list = toList(expressions); if (type == null) { @@ -561,7 +563,7 @@ public static ConstantExpression constant(Object value) { * Creates a ConstantExpression that has the Value and Type * properties set to the specified values. */ - public static ConstantExpression constant(Object value, Type type) { + public static ConstantExpression constant(@Nullable Object value, Type type) { if (value != null && type instanceof Class) { // Fix up value so that it matches type. Class clazz = (Class) type; @@ -839,7 +841,7 @@ public static MemberExpression field(Expression expression, Field field) { /** * Creates a MemberExpression that represents accessing a field. */ - public static MemberExpression field(Expression expression, + public static MemberExpression field(@Nullable Expression expression, PseudoField field) { return makeMemberAccess(expression, field); } @@ -857,7 +859,7 @@ public static MemberExpression field(Expression expression, /** * Creates a MemberExpression that represents accessing a field. */ - public static MemberExpression field(Expression expression, Type type, + public static MemberExpression field(@Nullable Expression expression, Type type, String fieldName) { PseudoField field = Types.getField(fieldName, type); return makeMemberAccess(expression, field); @@ -1384,7 +1386,7 @@ public static ListInitExpression listInit(NewExpression newExpression, */ public static ForStatement for_( Iterable declarations, - Expression condition, Expression post, Statement body) { + @Nullable Expression condition, @Nullable Expression post, Statement body) { return new ForStatement(toList(declarations), condition, post, body); } @@ -1393,7 +1395,7 @@ public static ForStatement for_( */ public static ForStatement for_( DeclarationStatement declaration, - Expression condition, Expression post, Statement body) { + @Nullable Expression condition, @Nullable Expression post, Statement body) { return new ForStatement(Collections.singletonList(declaration), condition, post, body); } @@ -1585,7 +1587,7 @@ public static GotoStatement makeGoto(GotoExpressionKind kind, /** * Creates a MemberExpression that represents accessing a field. */ - public static MemberExpression makeMemberAccess(Expression expression, + public static MemberExpression makeMemberAccess(@Nullable Expression expression, PseudoField member) { return new MemberExpression(expression, member); } @@ -1631,7 +1633,7 @@ public static UnaryExpression makeUnary(ExpressionType expressionType, * method, by calling the appropriate factory method. */ public static UnaryExpression makeUnary(ExpressionType expressionType, - Expression expression, Type type, Method method) { + Expression expression, Type type, @Nullable Method method) { assert type != null; return new UnaryExpression(expressionType, type, expression); } @@ -1917,7 +1919,8 @@ public static UnaryExpression negateChecked(Expression expression) { */ public static UnaryExpression negateChecked(Expression expression, Method method) { - return makeUnary(ExpressionType.NegateChecked, expression, null, method); + throw new UnsupportedOperationException("not implemented"); + //return makeUnary(ExpressionType.NegateChecked, expression, null, method); } /** @@ -2509,13 +2512,13 @@ public static GotoStatement return_(LabelTarget labelTarget) { * Creates a GotoExpression representing a return statement. The * value passed to the label upon jumping can be specified. */ - public static GotoStatement return_(LabelTarget labelTarget, - Expression expression) { + public static GotoStatement return_(@Nullable LabelTarget labelTarget, + @Nullable Expression expression) { return makeGoto(GotoExpressionKind.Return, labelTarget, expression); } public static GotoStatement makeGoto(GotoExpressionKind kind, - LabelTarget labelTarget, Expression expression) { + @Nullable LabelTarget labelTarget, @Nullable Expression expression) { return new GotoStatement(kind, labelTarget, expression); } @@ -2959,7 +2962,7 @@ public static DeclarationStatement declare(int modifiers, String name, /** * Creates a statement that executes an expression. */ - public static Statement statement(Expression expression) { + public static Statement statement(@Nullable Expression expression) { return new GotoStatement(GotoExpressionKind.Sequence, null, expression); } @@ -3116,14 +3119,14 @@ private static T[] toArray(Iterable iterable, T[] a) { return toCollection(iterable).toArray(a); } - static Expression accept(T node, Shuttle shuttle) { + static Expression accept(@Nullable T node, Shuttle shuttle) { if (node == null) { return null; } return node.accept(shuttle); } - static Statement accept(T node, Shuttle shuttle) { + static Statement accept(@Nullable T node, Shuttle shuttle) { if (node == null) { return null; } @@ -3187,7 +3190,7 @@ static List acceptDeclarations( } static List acceptMemberDeclarations( - List memberDeclarations, Shuttle shuttle) { + @Nullable List memberDeclarations, Shuttle shuttle) { if (memberDeclarations == null || memberDeclarations.isEmpty()) { return memberDeclarations; // short cut } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FieldDeclaration.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FieldDeclaration.java index 7780f8c4dfb4..dc2ea7653e51 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FieldDeclaration.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FieldDeclaration.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Modifier; import java.util.Objects; @@ -25,10 +27,10 @@ public class FieldDeclaration extends MemberDeclaration { public final int modifier; public final ParameterExpression parameter; - public final Expression initializer; + public final @Nullable Expression initializer; public FieldDeclaration(int modifier, ParameterExpression parameter, - Expression initializer) { + @Nullable Expression initializer) { assert parameter != null : "parameter should not be null"; this.modifier = modifier; this.parameter = parameter; @@ -43,7 +45,7 @@ public FieldDeclaration(int modifier, ParameterExpression parameter, return shuttle.visit(this, initializer); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -61,7 +63,7 @@ public void accept(ExpressionWriter writer) { writer.newlineAndIndent(); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ForEachStatement.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ForEachStatement.java index b6369fc74871..0db972840596 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ForEachStatement.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ForEachStatement.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.util.Objects; /** @@ -44,7 +46,7 @@ public ForEachStatement(ParameterExpression parameter, Expression iterable, return shuttle.visit(this, parameter, iterable1, body1); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -59,7 +61,7 @@ public R accept(Visitor visitor) { .append(Blocks.toBlock(body)); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { return this == o || o instanceof ForEachStatement && parameter.equals(((ForEachStatement) o).parameter) diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ForStatement.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ForStatement.java index 9ff6cf4c82f8..cfa89a19cb51 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ForStatement.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ForStatement.java @@ -18,6 +18,8 @@ import org.apache.calcite.linq4j.Ord; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.util.List; import java.util.Objects; @@ -26,8 +28,8 @@ */ public class ForStatement extends Statement { public final List declarations; - public final Expression condition; - public final Expression post; + public final @Nullable Expression condition; + public final @Nullable Expression post; public final Statement body; /** * Cache the hash code for the expression @@ -35,7 +37,7 @@ public class ForStatement extends Statement { private int hash; public ForStatement(List declarations, - Expression condition, Expression post, Statement body) { + @Nullable Expression condition, @Nullable Expression post, Statement body) { super(ExpressionType.For, Void.TYPE); assert declarations != null; assert body != null; @@ -56,7 +58,7 @@ public ForStatement(List declarations, return shuttle.visit(this, decls1, condition1, post1, body1); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -76,7 +78,7 @@ public R accept(Visitor visitor) { writer.append(") ").append(Blocks.toBlock(body)); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FunctionExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FunctionExpression.java index a5680fdf51db..d8a252577478 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FunctionExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/FunctionExpression.java @@ -22,6 +22,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.lang.reflect.Type; @@ -38,8 +40,8 @@ */ public final class FunctionExpression> extends LambdaExpression { - public final F function; - public final BlockStatement body; + public final @Nullable F function; + public final @Nullable BlockStatement body; public final List parameterList; private F dynamicFunction; /** @@ -47,7 +49,7 @@ public final class FunctionExpression> */ private int hash; - private FunctionExpression(Class type, F function, BlockStatement body, + private FunctionExpression(Class type, @Nullable F function, @Nullable BlockStatement body, List parameterList) { super(ExpressionType.Lambda, type); assert type != null : "type should not be null"; @@ -74,7 +76,7 @@ public FunctionExpression(Class type, BlockStatement body, return shuttle.visit(this, body); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -227,7 +229,7 @@ private Method getAbstractMethod() { return null; } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/GotoStatement.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/GotoStatement.java index 4c00e62f70cc..3e911212d304 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/GotoStatement.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/GotoStatement.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.util.Objects; /** @@ -24,11 +26,11 @@ */ public class GotoStatement extends Statement { public final GotoExpressionKind kind; - public final LabelTarget labelTarget; - public final Expression expression; + public final @Nullable LabelTarget labelTarget; + public final @Nullable Expression expression; - GotoStatement(GotoExpressionKind kind, LabelTarget labelTarget, - Expression expression) { + GotoStatement(GotoExpressionKind kind, @Nullable LabelTarget labelTarget, + @Nullable Expression expression) { super(ExpressionType.Goto, expression == null ? Void.TYPE : expression.getType()); assert kind != null : "kind should not be null"; @@ -61,7 +63,7 @@ public class GotoStatement extends Statement { return shuttle.visit(this, expression1); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -88,7 +90,7 @@ public R accept(Visitor visitor) { writer.append(';').newlineAndIndent(); } - @Override public Object evaluate(Evaluator evaluator) { + @Override public @Nullable Object evaluate(Evaluator evaluator) { switch (kind) { case Return: case Sequence: @@ -100,7 +102,7 @@ public R accept(Visitor visitor) { } } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/IndexExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/IndexExpression.java index 0f1c909f7220..a89294f52019 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/IndexExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/IndexExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.util.List; import java.util.Objects; @@ -43,7 +45,7 @@ public IndexExpression(Expression array, List indexExpressions) { return shuttle.visit(this, array, indexExpressions); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -52,7 +54,7 @@ public R accept(Visitor visitor) { writer.list("[", ", ", "]", indexExpressions); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/InvocationExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/InvocationExpression.java index aa83443aa022..dedd1a00d3b5 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/InvocationExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/InvocationExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * Represents an expression that applies a delegate or lambda expression to a * list of argument expressions. @@ -29,7 +31,7 @@ public InvocationExpression(ExpressionType nodeType, Class type) { return shuttle.visit(this); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/LabelStatement.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/LabelStatement.java index 38a5d279892c..1411a2cf48ad 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/LabelStatement.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/LabelStatement.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.util.Objects; /** @@ -37,11 +39,11 @@ public LabelStatement(Expression defaultValue, ExpressionType nodeType) { return shuttle.visit(this); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/LabelTarget.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/LabelTarget.java index 49cbb4d03b6b..16679ab02343 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/LabelTarget.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/LabelTarget.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.util.Objects; /** @@ -28,7 +30,7 @@ public LabelTarget(String name) { this.name = name; } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/LambdaExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/LambdaExpression.java index ee4386d40d41..4d4bbdd757bd 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/LambdaExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/LambdaExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * Describes a lambda expression. This captures a block of code that is similar * to a Java method body. @@ -29,7 +31,7 @@ public LambdaExpression(ExpressionType nodeType, Class type) { return shuttle.visit(this); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ListInitExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ListInitExpression.java index 59e2e4cc6b0c..3750cc164aca 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ListInitExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ListInitExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * Represents a constructor call that has a collection initializer. */ @@ -28,7 +30,7 @@ public ListInitExpression(ExpressionType nodeType, Class type) { return shuttle.visit(this); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MemberExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MemberExpression.java index d746ea19e583..606c5660957e 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MemberExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MemberExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.Objects; @@ -24,14 +26,14 @@ * Represents accessing a field or property. */ public class MemberExpression extends Expression { - public final Expression expression; + public final @Nullable Expression expression; public final PseudoField field; public MemberExpression(Expression expression, Field field) { this(expression, Types.field(field)); } - public MemberExpression(Expression expression, PseudoField field) { + public MemberExpression(@Nullable Expression expression, PseudoField field) { super(ExpressionType.MemberAccess, field.getType()); assert field != null : "field should not be null"; assert expression != null || Modifier.isStatic(field.getModifiers()) @@ -48,11 +50,11 @@ public MemberExpression(Expression expression, PseudoField field) { return shuttle.visit(this, expression1); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } - public Object evaluate(Evaluator evaluator) { + @Override public @Nullable Object evaluate(Evaluator evaluator) { final Object o = expression == null ? null : expression.evaluate(evaluator); @@ -76,7 +78,7 @@ public Object evaluate(Evaluator evaluator) { writer.append('.').append(field.getName()); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MemberInitExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MemberInitExpression.java index 1757660ad636..74222cb70c82 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MemberInitExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MemberInitExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * Represents calling a constructor and initializing one or more members of the * new object. @@ -29,7 +31,7 @@ public MemberInitExpression() { return shuttle.visit(this); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MethodCallExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MethodCallExpression.java index 5601d0c065df..9114ffe68ae0 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MethodCallExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MethodCallExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -28,7 +30,7 @@ */ public class MethodCallExpression extends Expression { public final Method method; - public final Expression targetExpression; // null for call to static method + public final @Nullable Expression targetExpression; // null for call to static method public final List expressions; /** * Cache the hash code for the expression @@ -36,7 +38,7 @@ public class MethodCallExpression extends Expression { private int hash; MethodCallExpression(Type returnType, Method method, - Expression targetExpression, List expressions) { + @Nullable Expression targetExpression, List expressions) { super(ExpressionType.Call, returnType); assert expressions != null : "expressions should not be null"; assert method != null : "method should not be null"; @@ -48,7 +50,7 @@ public class MethodCallExpression extends Expression { this.expressions = expressions; } - MethodCallExpression(Method method, Expression targetExpression, + MethodCallExpression(Method method, @Nullable Expression targetExpression, List expressions) { this(method.getReturnType(), method, targetExpression, expressions); } @@ -62,11 +64,11 @@ public class MethodCallExpression extends Expression { return shuttle.visit(this, targetExpression, expressions); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } - @Override public Object evaluate(Evaluator evaluator) { + @Override public @Nullable Object evaluate(Evaluator evaluator) { final Object target; if (targetExpression == null) { target = null; @@ -107,7 +109,7 @@ public R accept(Visitor visitor) { writer.append(')'); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MethodDeclaration.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MethodDeclaration.java index e67fa6bb207f..c4346a83d335 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MethodDeclaration.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/MethodDeclaration.java @@ -18,6 +18,8 @@ import com.google.common.collect.Lists; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Modifier; import java.lang.reflect.Type; import java.util.List; @@ -53,7 +55,7 @@ public MethodDeclaration(int modifier, String name, Type resultType, return shuttle.visit(this, body); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -74,7 +76,7 @@ public void accept(ExpressionWriter writer) { writer.newlineAndIndent(); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/NewArrayExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/NewArrayExpression.java index ab39215d6dd6..dbef24d053e7 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/NewArrayExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/NewArrayExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Type; import java.util.List; import java.util.Objects; @@ -26,15 +28,15 @@ */ public class NewArrayExpression extends Expression { public final int dimension; - public final Expression bound; - public final List expressions; + public final @Nullable Expression bound; + public final @Nullable List expressions; /** * Cache the hash code for the expression */ private int hash; - public NewArrayExpression(Type type, int dimension, Expression bound, - List expressions) { + public NewArrayExpression(Type type, int dimension, @Nullable Expression bound, + @Nullable List expressions) { super(ExpressionType.NewArrayInit, Types.arrayType(type, dimension)); this.dimension = dimension; this.bound = bound; @@ -51,7 +53,7 @@ public NewArrayExpression(Type type, int dimension, Expression bound, return shuttle.visit(this, dimension, bound, expressions); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -69,7 +71,7 @@ public R accept(Visitor visitor) { } } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/NewExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/NewExpression.java index 25a48fc241d9..5fd9cfffee93 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/NewExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/NewExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Type; import java.util.List; import java.util.Objects; @@ -29,14 +31,14 @@ public class NewExpression extends Expression { public final Type type; public final List arguments; - public final List memberDeclarations; + public final @Nullable List memberDeclarations; /** * Cache the hash code for the expression */ private int hash; public NewExpression(Type type, List arguments, - List memberDeclarations) { + @Nullable List memberDeclarations) { super(ExpressionType.New, type); this.type = type; this.arguments = arguments; @@ -52,7 +54,7 @@ public NewExpression(Type type, List arguments, return shuttle.visit(this, arguments, memberDeclarations); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -63,7 +65,7 @@ public R accept(Visitor visitor) { } } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/OptimizeShuttle.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/OptimizeShuttle.java index 92c65b49c7f7..3897530cb181 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/OptimizeShuttle.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/OptimizeShuttle.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -381,7 +383,7 @@ private boolean isConstantNull(Expression expression) { * Returns whether an expression always evaluates to true or false. * Assumes that expression has already been optimized. */ - private static Boolean always(Expression x) { + private static @Nullable Boolean always(Expression x) { if (x.equals(FALSE_EXPR) || x.equals(BOXED_FALSE_EXPR)) { return Boolean.FALSE; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ParameterExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ParameterExpression.java index fb7eaf2d22d3..0195d1838f9a 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ParameterExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ParameterExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Modifier; import java.lang.reflect.Type; import java.util.concurrent.atomic.AtomicInteger; @@ -47,11 +49,11 @@ public ParameterExpression(int modifier, Type type, String name) { return shuttle.visit(this); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } - public Object evaluate(Evaluator evaluator) { + @Override public @Nullable Object evaluate(Evaluator evaluator) { return evaluator.peek(this); } @@ -69,7 +71,7 @@ String declString(Type type) { + " " + name; } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { return this == o; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Primitive.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Primitive.java index 03a70f834692..223cf0d96553 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Primitive.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Primitive.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Array; import java.lang.reflect.Field; import java.lang.reflect.Type; @@ -54,30 +56,30 @@ public enum Primitive { VOID(Void.TYPE, Void.class, 3, null, null, null, null, null, -1), OTHER(null, null, 4, null, null, null, null, null, -1); - public final Class primitiveClass; - public final Class boxClass; - public final String primitiveName; // e.g. "int" - public final String boxName; + public final @Nullable Class primitiveClass; + public final @Nullable Class boxClass; + public final @Nullable String primitiveName; // e.g. "int" + public final @Nullable String boxName; private final int family; /** The default value of this primitive class. This is the value * taken by uninitialized fields, for instance; 0 for {@code int}, false for * {@code boolean}, etc. */ - public final Object defaultValue; + public final @Nullable Object defaultValue; /** The minimum value of this primitive class. */ - public final Object min; + public final @Nullable Object min; /** The largest value that is less than zero. Null if not applicable for this * type. */ - public final Object maxNegative; + public final @Nullable Object maxNegative; /** The smallest value that is greater than zero. Null if not applicable for * this type. */ - public final Object minPositive; + public final @Nullable Object minPositive; /** The maximum value of this primitive class. */ - public final Object max; + public final @Nullable Object max; /** The size of a value of this type, in bits. Null if not applicable for this * type. */ @@ -98,9 +100,9 @@ public enum Primitive { } } - Primitive(Class primitiveClass, Class boxClass, int family, - Object defaultValue, Object min, Object maxNegative, Object minPositive, - Object max, int size) { + Primitive(@Nullable Class primitiveClass, @Nullable Class boxClass, int family, + @Nullable Object defaultValue, @Nullable Object min, @Nullable Object maxNegative, + @Nullable Object minPositive, @Nullable Object max, int size) { this.primitiveClass = primitiveClass; this.family = family; this.primitiveName = @@ -123,7 +125,7 @@ public enum Primitive { * of(Long.class) and of(String.class) return * {@code null}. */ - public static Primitive of(Type type) { + public static @Nullable Primitive of(Type type) { //noinspection SuspiciousMethodCalls return PRIMITIVE_MAP.get(type); } @@ -134,7 +136,7 @@ public static Primitive of(Type type) { *

For example, ofBox(java.util.Long.class) * returns {@link #LONG}. */ - public static Primitive ofBox(Type type) { + public static @Nullable Primitive ofBox(Type type) { //noinspection SuspiciousMethodCalls return BOX_MAP.get(type); } @@ -145,7 +147,7 @@ public static Primitive ofBox(Type type) { *

For example, ofBoxOr(Long.class) and * ofBoxOr(long.class) both return {@link #LONG}. */ - public static Primitive ofBoxOr(Type type) { + public static @Nullable Primitive ofBoxOr(Type type) { Primitive primitive = of(type); if (primitive == null) { primitive = ofBox(type); @@ -696,7 +698,7 @@ public void send(Field field, Object o, Sink sink) /** * Gets an item from an array. */ - public Object arrayItem(Object dataSet, int ordinal) { + public @Nullable Object arrayItem(Object dataSet, int ordinal) { // Plain old Array.get doesn't cut it when you have an array of // Integer values but you want to read Short values. Array.getShort // does the right thing. @@ -804,7 +806,7 @@ public void arrayItem(Object dataSet, int ordinal, Sink sink) { * @param resultSet Result set * @param i Ordinal of column (1-based, per JDBC) */ - public Object jdbcGet(ResultSet resultSet, int i) throws SQLException { + public @Nullable Object jdbcGet(ResultSet resultSet, int i) throws SQLException { switch (this) { case BOOLEAN: return resultSet.getBoolean(i); @@ -976,7 +978,7 @@ public interface Sink { void set(double v); - void set(Object v); + void set(@Nullable Object v); } /** @@ -999,7 +1001,7 @@ public interface Source { double getDouble(); - Object getObject(); + @Nullable Object getObject(); } /** What kind of type? */ diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ReflectedPseudoField.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ReflectedPseudoField.java index 4a713bcd1992..a077daecc6a9 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ReflectedPseudoField.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ReflectedPseudoField.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Field; import java.lang.reflect.Type; @@ -42,7 +44,7 @@ public int getModifiers() { return field.getModifiers(); } - public Object get(Object o) throws IllegalAccessException { + public @Nullable Object get(Object o) throws IllegalAccessException { return field.get(o); } @@ -50,7 +52,7 @@ public Class getDeclaringClass() { return field.getDeclaringClass(); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Shuttle.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Shuttle.java index 52806c0a3bca..e464113a5d46 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Shuttle.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Shuttle.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.util.List; import java.util.Objects; @@ -78,8 +80,8 @@ public Shuttle preVisit(ForStatement forStatement) { } public ForStatement visit(ForStatement forStatement, - List declarations, Expression condition, - Expression post, Statement body) { + List declarations, @Nullable Expression condition, + @Nullable Expression post, Statement body) { return declarations.equals(forStatement.declarations) && condition == forStatement.condition && post == forStatement.post @@ -216,7 +218,7 @@ public Shuttle preVisit(MemberExpression memberExpression) { } public Expression visit(MemberExpression memberExpression, - Expression expression) { + @Nullable Expression expression) { return memberExpression.expression == expression ? memberExpression : Expressions.field(expression, memberExpression.field); diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/SwitchStatement.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/SwitchStatement.java index 2ebcdc1bd8dd..658348512b9b 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/SwitchStatement.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/SwitchStatement.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * Represents a control expression that handles multiple selections by passing * control to {@link SwitchCase}. @@ -29,7 +31,7 @@ public SwitchStatement(ExpressionType nodeType) { return shuttle.visit(this); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TernaryExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TernaryExpression.java index 00ef60c370f7..4f5ef4f35a05 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TernaryExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TernaryExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Type; import java.util.Objects; @@ -46,7 +48,7 @@ public class TernaryExpression extends Expression { return shuttle.visit(this, expression0, expression1, expression2); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -61,7 +63,7 @@ void accept(ExpressionWriter writer, int lprec, int rprec) { expression2.accept(writer, nodeType.rprec, rprec); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ThrowStatement.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ThrowStatement.java index 0cd427d70d0e..7155e986a8f5 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ThrowStatement.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/ThrowStatement.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.util.Objects; /** @@ -35,7 +37,7 @@ public ThrowStatement(Expression expression) { return shuttle.visit(this, expression); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -43,7 +45,7 @@ public R accept(Visitor visitor) { writer.append("throw ").append(expression).append(';').newlineAndIndent(); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TryStatement.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TryStatement.java index 0ee3d7a96b12..1bba5ca7b24f 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TryStatement.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TryStatement.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -50,7 +52,7 @@ public TryStatement(Statement body, List catchBlocks, return shuttle.visit(this, body1, catchBlocks1, fynally1); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -67,7 +69,7 @@ public R accept(Visitor visitor) { } } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TypeBinaryExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TypeBinaryExpression.java index 967c228849c9..08b2844d0bbf 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TypeBinaryExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/TypeBinaryExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Type; import java.util.Objects; @@ -40,7 +42,7 @@ public TypeBinaryExpression(ExpressionType nodeType, Expression expression, return shuttle.visit(this, expression); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -53,7 +55,7 @@ void accept(ExpressionWriter writer, int lprec, int rprec) { writer.append(type); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Types.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Types.java index a449a46a925c..26c879e0ff5e 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Types.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Types.java @@ -18,6 +18,8 @@ import org.apache.calcite.linq4j.Enumerator; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Array; import java.lang.reflect.Constructor; import java.lang.reflect.Field; @@ -60,7 +62,7 @@ public static Type of(Type type, Type... typeArguments) { * *

Returns null if the type is not one of these.

*/ - public static Type getElementType(Type type) { + public static @Nullable Type getElementType(Type type) { if (type instanceof ArrayType) { return ((ArrayType) type).getComponentType(); } @@ -167,7 +169,7 @@ public static Class[] toClassArray(Iterable arguments) { /** * Returns the component type of an array. */ - public static Type getComponentType(Type type) { + public static @Nullable Type getComponentType(Type type) { if (type instanceof Class) { return ((Class) type).getComponentType(); } @@ -526,10 +528,10 @@ public static Type stripGenerics(Type type) { static class ParameterizedTypeImpl implements ParameterizedType { private final Type rawType; private final List typeArguments; - private final Type ownerType; + private final @Nullable Type ownerType; ParameterizedTypeImpl(Type rawType, List typeArguments, - Type ownerType) { + @Nullable Type ownerType) { super(); this.rawType = rawType; this.typeArguments = typeArguments; @@ -563,7 +565,7 @@ public Type getRawType() { return rawType; } - public Type getOwnerType() { + public @Nullable Type getOwnerType() { return ownerType; } } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/UnaryExpression.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/UnaryExpression.java index d07e545aa816..2354ef81b8d3 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/UnaryExpression.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/UnaryExpression.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.lang.reflect.Type; import java.util.Objects; @@ -37,7 +39,7 @@ public class UnaryExpression extends Expression { return shuttle.visit(this, expression); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -59,7 +61,7 @@ void accept(ExpressionWriter writer, int lprec, int rprec) { } } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Visitor.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Visitor.java index 6063983227f4..ffb398014f60 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Visitor.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Visitor.java @@ -16,12 +16,14 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * Node visitor. * * @param Return type */ -public interface Visitor { +public interface Visitor<@Nullable R> { R visit(BinaryExpression binaryExpression); R visit(BlockStatement blockStatement); R visit(ClassDeclaration classDeclaration); diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/VisitorImpl.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/VisitorImpl.java index 8d8431f27757..31e858e6aafc 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/VisitorImpl.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/VisitorImpl.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.util.List; /** @@ -24,7 +26,7 @@ * * @param Return type */ -public class VisitorImpl implements Visitor { +public class VisitorImpl<@Nullable R> implements Visitor { public VisitorImpl() { super(); } diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/WhileStatement.java b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/WhileStatement.java index 76ab8b0f2860..29026d369cc2 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/tree/WhileStatement.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/WhileStatement.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.linq4j.tree; +import org.checkerframework.checker.nullness.qual.Nullable; + import java.util.Objects; /** @@ -40,7 +42,7 @@ public WhileStatement(Expression condition, Statement body) { return shuttle.visit(this, condition1, body1); } - public R accept(Visitor visitor) { + public <@Nullable R> R accept(Visitor visitor) { return visitor.visit(this); } @@ -49,7 +51,7 @@ public R accept(Visitor visitor) { Blocks.toBlock(body)); } - @Override public boolean equals(Object o) { + @Override public boolean equals(@Nullable Object o) { if (this == o) { return true; }