Apply some `ReturnMissingNullable` fixes
PiperOrigin-RevId: 386487552
diff --git a/java/com/google/turbine/lower/Lower.java b/java/com/google/turbine/lower/Lower.java
index 1bcbf54..fa81d1d 100644
--- a/java/com/google/turbine/lower/Lower.java
+++ b/java/com/google/turbine/lower/Lower.java
@@ -505,6 +505,7 @@
return lowered.build();
}
+ @Nullable
private AnnotationInfo lowerAnnotation(AnnoInfo annotation) {
Boolean visible = isVisible(annotation.sym());
if (visible == null) {
diff --git a/java/com/google/turbine/lower/LowerSignature.java b/java/com/google/turbine/lower/LowerSignature.java
index eb35dc7..de20f63 100644
--- a/java/com/google/turbine/lower/LowerSignature.java
+++ b/java/com/google/turbine/lower/LowerSignature.java
@@ -46,6 +46,7 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
+import org.checkerframework.checker.nullness.qual.Nullable;
/** Translator from {@link Type}s to {@link Sig}natures. */
public class LowerSignature {
@@ -127,6 +128,7 @@
* Produces a method signature attribute for a generic method, or {@code null} if the signature is
* unnecessary.
*/
+ @Nullable
public String methodSignature(
Env<ClassSymbol, TypeBoundClass> env, TypeBoundClass.MethodInfo method, ClassSymbol sym) {
if (!needsMethodSig(sym, env, method)) {
@@ -194,6 +196,7 @@
* Produces a class signature attribute for a generic class, or {@code null} if the signature is
* unnecessary.
*/
+ @Nullable
public String classSignature(SourceTypeBoundClass info, Env<ClassSymbol, TypeBoundClass> env) {
if (!classNeedsSig(info)) {
return null;
@@ -211,6 +214,7 @@
/**
* A field signature, or {@code null} if the descriptor provides all necessary type information.
*/
+ @Nullable
public String fieldSignature(Type type) {
return needsSig(type) ? SigWriter.type(signature(type)) : null;
}
diff --git a/java/com/google/turbine/parse/ConstExpressionParser.java b/java/com/google/turbine/parse/ConstExpressionParser.java
index 372cf9d..4c131b5 100644
--- a/java/com/google/turbine/parse/ConstExpressionParser.java
+++ b/java/com/google/turbine/parse/ConstExpressionParser.java
@@ -25,6 +25,7 @@
import com.google.turbine.model.Const;
import com.google.turbine.model.TurbineConstantTypeKind;
import com.google.turbine.tree.Tree;
+import com.google.turbine.tree.Tree.AnnoExpr;
import com.google.turbine.tree.Tree.ClassLiteral;
import com.google.turbine.tree.Tree.ClassTy;
import com.google.turbine.tree.Tree.Expression;
@@ -46,6 +47,7 @@
this.position = position;
}
+ @Nullable
private static TurbineOperatorKind operator(Token token) {
switch (token) {
case ASSIGN:
@@ -96,7 +98,7 @@
}
}
- private Tree.@Nullable Expression primary(boolean negate) {
+ private @Nullable Expression primary(boolean negate) {
switch (token) {
case INT_LITERAL:
return finishLiteral(TurbineConstantTypeKind.INT, negate);
@@ -175,7 +177,7 @@
return finishClassLiteral(position, new Tree.PrimTy(position, ImmutableList.of(), type));
}
- private Tree.Expression maybeCast() {
+ private Expression maybeCast() {
eat();
switch (token) {
case BOOLEAN:
@@ -207,8 +209,9 @@
}
}
- private Tree.Expression notCast() {
- Tree.Expression expr = expression(null);
+ @Nullable
+ private Expression notCast() {
+ Expression expr = expression(null);
if (expr == null) {
return null;
}
@@ -251,7 +254,8 @@
position = lexer.position();
}
- private Tree.Expression arrayInitializer(int pos) {
+ @Nullable
+ private Expression arrayInitializer(int pos) {
if (token == Token.RBRACE) {
eat();
return new Tree.ArrayInit(pos, ImmutableList.<Tree.Expression>of());
@@ -264,7 +268,7 @@
eat();
break OUTER;
}
- Tree.Expression item = expression(null);
+ Expression item = expression(null);
if (item == null) {
return null;
}
@@ -284,7 +288,7 @@
}
/** Finish hex, decimal, octal, and binary integer literals (see JLS 3.10.1). */
- private Tree.Expression finishLiteral(TurbineConstantTypeKind kind, boolean negate) {
+ private Expression finishLiteral(TurbineConstantTypeKind kind, boolean negate) {
int pos = position;
String text = ident().value();
Const.Value value;
@@ -408,9 +412,10 @@
return r;
}
- private Tree.Expression unaryRest(TurbineOperatorKind op) {
+ @Nullable
+ private Expression unaryRest(TurbineOperatorKind op) {
boolean negate = op == TurbineOperatorKind.NEG;
- Tree.Expression expr = primary(negate);
+ Expression expr = primary(negate);
if (expr == null) {
return null;
}
@@ -427,7 +432,7 @@
return new Tree.Unary(position, expr, op);
}
- private Tree.@Nullable Expression qualIdent() {
+ private @Nullable Expression qualIdent() {
int pos = position;
ImmutableList.Builder<Ident> bits = ImmutableList.builder();
bits.add(ident());
@@ -457,6 +462,7 @@
return new Ident(lexer.position(), lexer.stringValue());
}
+ @Nullable
private Expression finishClassLiteral(int pos, Tree.Type type) {
while (token == Token.LBRACK) {
eat();
@@ -477,8 +483,9 @@
return new ClassLiteral(pos, type);
}
- public Tree.Expression expression() {
- Tree.Expression result = expression(null);
+ @Nullable
+ public Expression expression() {
+ Expression result = expression(null);
switch (token) {
case EOF:
case SEMI:
@@ -491,15 +498,17 @@
}
}
- private Tree.Expression expression(TurbineOperatorKind.Precedence prec) {
- Tree.Expression term1 = primary(false);
+ @Nullable
+ private Expression expression(TurbineOperatorKind.Precedence prec) {
+ Expression term1 = primary(false);
if (term1 == null) {
return null;
}
return expression(term1, prec);
}
- private Tree.Expression expression(Tree.Expression term1, TurbineOperatorKind.Precedence prec) {
+ @Nullable
+ private Expression expression(Expression term1, TurbineOperatorKind.Precedence prec) {
while (true) {
if (token == Token.EOF) {
return term1;
@@ -528,7 +537,8 @@
}
}
- private Tree.Expression assign(Tree.Expression term1, TurbineOperatorKind op) {
+ @Nullable
+ private Expression assign(Expression term1, TurbineOperatorKind op) {
if (!(term1 instanceof Tree.ConstVarName)) {
return null;
}
@@ -537,15 +547,16 @@
return null;
}
Ident name = getOnlyElement(names);
- Tree.Expression rhs = expression(op.prec());
+ Expression rhs = expression(op.prec());
if (rhs == null) {
return null;
}
return new Tree.Assign(term1.position(), name, rhs);
}
- private Tree.Expression ternary(Tree.Expression term1) {
- Tree.Expression thenExpr = expression(TurbineOperatorKind.Precedence.TERNARY);
+ @Nullable
+ private Expression ternary(Expression term1) {
+ Expression thenExpr = expression(TurbineOperatorKind.Precedence.TERNARY);
if (thenExpr == null) {
return null;
}
@@ -553,26 +564,27 @@
return null;
}
eat();
- Tree.Expression elseExpr = expression();
+ Expression elseExpr = expression();
if (elseExpr == null) {
return null;
}
return new Tree.Conditional(position, term1, thenExpr, elseExpr);
}
- private Tree.Expression castTail(TurbineConstantTypeKind ty) {
+ @Nullable
+ private Expression castTail(TurbineConstantTypeKind ty) {
if (token != Token.RPAREN) {
return null;
}
eat();
- Tree.Expression rhs = primary(false);
+ Expression rhs = primary(false);
if (rhs == null) {
return null;
}
return new Tree.TypeCast(position, new Tree.PrimTy(position, ImmutableList.of(), ty), rhs);
}
- private Tree.@Nullable AnnoExpr annotation() {
+ private @Nullable AnnoExpr annotation() {
if (token != Token.AT) {
throw new AssertionError();
}
@@ -588,7 +600,7 @@
eat();
while (token != Token.RPAREN) {
int argPos = position;
- Tree.Expression expression = expression();
+ Expression expression = expression();
if (expression == null) {
throw TurbineError.format(lexer.source(), argPos, ErrorKind.INVALID_ANNOTATION_ARGUMENT);
}
diff --git a/java/com/google/turbine/parse/StreamLexer.java b/java/com/google/turbine/parse/StreamLexer.java
index 991b5fd..cc51002 100644
--- a/java/com/google/turbine/parse/StreamLexer.java
+++ b/java/com/google/turbine/parse/StreamLexer.java
@@ -22,6 +22,7 @@
import com.google.turbine.diag.SourceFile;
import com.google.turbine.diag.TurbineError;
import com.google.turbine.diag.TurbineError.ErrorKind;
+import org.checkerframework.checker.nullness.qual.Nullable;
/** A {@link Lexer} that streams input from a {@link UnicodeEscapePreprocessor}. */
public class StreamLexer implements Lexer {
@@ -64,6 +65,7 @@
ch = reader.next();
}
+ @Nullable
@Override
public String javadoc() {
String result = javadoc;
diff --git a/java/com/google/turbine/types/Canonicalize.java b/java/com/google/turbine/types/Canonicalize.java
index f997648..b8fbe95 100644
--- a/java/com/google/turbine/types/Canonicalize.java
+++ b/java/com/google/turbine/types/Canonicalize.java
@@ -284,6 +284,7 @@
}
/** Instantiates a type argument using the given mapping. */
+ @Nullable
private static Type instantiate(Map<TyVarSymbol, Type> mapping, Type type) {
if (type == null) {
return null;