aboutsummaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorLiam Miller-Cushon <cushon@google.com>2021-03-13 15:55:08 -0800
committerJavac Team <javac-team+copybara@google.com>2021-03-13 15:55:44 -0800
commit0adcd8e8e3ce2517558a919b44ba2c6ab7991503 (patch)
tree8322b48658ff1de05043277e09243440237ed564 /java
parent5db787b682fdbd3e61c2a4b3b5558396fe4b198c (diff)
downloadturbine-0adcd8e8e3ce2517558a919b44ba2c6ab7991503.tar.gz
Comply with nullness analysis
Startblock: unknown commit is submitted unknown commit is submitted unknown commit is submitted PiperOrigin-RevId: 362735853
Diffstat (limited to 'java')
-rw-r--r--java/com/google/turbine/binder/Processing.java21
-rw-r--r--java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java8
-rw-r--r--java/com/google/turbine/options/TurbineOptionsParser.java6
-rw-r--r--java/com/google/turbine/processing/TurbineAnnotationProxy.java6
-rw-r--r--java/com/google/turbine/processing/TurbineFiler.java3
5 files changed, 31 insertions, 13 deletions
diff --git a/java/com/google/turbine/binder/Processing.java b/java/com/google/turbine/binder/Processing.java
index f4700b3..d48b800 100644
--- a/java/com/google/turbine/binder/Processing.java
+++ b/java/com/google/turbine/binder/Processing.java
@@ -58,7 +58,6 @@ import java.nio.file.Paths;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -139,10 +138,8 @@ public class Processing {
}
}
- Map<Processor, SupportedAnnotationTypes> wanted = new HashMap<>();
- for (Processor processor : processorInfo.processors()) {
- wanted.put(processor, SupportedAnnotationTypes.create(processor));
- }
+ ImmutableMap<Processor, SupportedAnnotationTypes> wanted =
+ initializeSupportedAnnotationTypes(processorInfo);
Set<ClassSymbol> allSymbols = new HashSet<>();
@@ -162,9 +159,10 @@ public class Processing {
}
ImmutableSetMultimap<ClassSymbol, Symbol> allAnnotations = getAllAnnotations(env, syms);
TurbineRoundEnvironment roundEnv = null;
- for (Processor processor : processorInfo.processors()) {
+ for (Map.Entry<Processor, SupportedAnnotationTypes> e : wanted.entrySet()) {
+ Processor processor = e.getKey();
+ SupportedAnnotationTypes supportedAnnotationTypes = e.getValue();
Set<TypeElement> annotations = new HashSet<>();
- SupportedAnnotationTypes supportedAnnotationTypes = wanted.get(processor);
boolean run = supportedAnnotationTypes.everything() || toRun.contains(processor);
for (ClassSymbol a : allAnnotations.keys()) {
if (supportedAnnotationTypes.everything()
@@ -271,6 +269,15 @@ public class Processing {
return result;
}
+ private static ImmutableMap<Processor, SupportedAnnotationTypes>
+ initializeSupportedAnnotationTypes(ProcessorInfo processorInfo) {
+ ImmutableMap.Builder<Processor, SupportedAnnotationTypes> result = ImmutableMap.builder();
+ for (Processor processor : processorInfo.processors()) {
+ result.put(processor, SupportedAnnotationTypes.create(processor));
+ }
+ return result.build();
+ }
+
@AutoValue
abstract static class SupportedAnnotationTypes {
diff --git a/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java b/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java
index 8939780..a3be4f0 100644
--- a/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java
+++ b/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java
@@ -18,6 +18,7 @@ package com.google.turbine.binder.bytecode;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Verify.verify;
+import static java.util.Objects.requireNonNull;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
@@ -512,6 +513,9 @@ public class BytecodeBoundClass implements TypeBoundClass {
private static RetentionPolicy bindRetention(AnnotationInfo annotation) {
ElementValue val = annotation.elementValuePairs().get("value");
+ if (val == null) {
+ return null;
+ }
if (val.kind() != Kind.ENUM) {
return null;
}
@@ -525,6 +529,7 @@ public class BytecodeBoundClass implements TypeBoundClass {
private static ImmutableSet<TurbineElementType> bindTarget(AnnotationInfo annotation) {
ImmutableSet.Builder<TurbineElementType> result = ImmutableSet.builder();
ElementValue val = annotation.elementValuePairs().get("value");
+ requireNonNull(val);
switch (val.kind()) {
case ARRAY:
for (ElementValue element : ((ArrayValue) val).elements()) {
@@ -551,6 +556,9 @@ public class BytecodeBoundClass implements TypeBoundClass {
private static ClassSymbol bindRepeatable(AnnotationInfo annotation) {
ElementValue val = annotation.elementValuePairs().get("value");
+ if (val == null) {
+ return null;
+ }
switch (val.kind()) {
case CLASS:
String className = ((ConstTurbineClassValue) val).className();
diff --git a/java/com/google/turbine/options/TurbineOptionsParser.java b/java/com/google/turbine/options/TurbineOptionsParser.java
index f2bd5e0..e710bb7 100644
--- a/java/com/google/turbine/options/TurbineOptionsParser.java
+++ b/java/com/google/turbine/options/TurbineOptionsParser.java
@@ -203,7 +203,7 @@ public final class TurbineOptionsParser {
/** Returns the value of an option, or {@code null}. */
@Nullable
private static String readOne(Deque<String> argumentDeque) {
- if (argumentDeque.isEmpty() || argumentDeque.peekFirst().startsWith("-")) {
+ if (argumentDeque.isEmpty() || argumentDeque.getFirst().startsWith("-")) {
return null;
}
return argumentDeque.pollFirst();
@@ -212,7 +212,7 @@ public final class TurbineOptionsParser {
/** Returns a list of option values. */
private static ImmutableList<String> readList(Deque<String> argumentDeque) {
ImmutableList.Builder<String> result = ImmutableList.builder();
- while (!argumentDeque.isEmpty() && !argumentDeque.peekFirst().startsWith("--")) {
+ while (!argumentDeque.isEmpty() && !argumentDeque.getFirst().startsWith("--")) {
result.add(argumentDeque.pollFirst());
}
return result.build();
@@ -225,7 +225,7 @@ public final class TurbineOptionsParser {
private static ImmutableList<String> readJavacopts(Deque<String> argumentDeque) {
ImmutableList.Builder<String> result = ImmutableList.builder();
while (!argumentDeque.isEmpty()) {
- String arg = argumentDeque.pollFirst();
+ String arg = argumentDeque.removeFirst();
if (arg.equals("--")) {
return result.build();
}
diff --git a/java/com/google/turbine/processing/TurbineAnnotationProxy.java b/java/com/google/turbine/processing/TurbineAnnotationProxy.java
index c39f310..967ead9 100644
--- a/java/com/google/turbine/processing/TurbineAnnotationProxy.java
+++ b/java/com/google/turbine/processing/TurbineAnnotationProxy.java
@@ -17,6 +17,7 @@
package com.google.turbine.processing;
import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
import com.google.turbine.binder.bound.EnumConstantValue;
import com.google.turbine.binder.bound.TurbineAnnotationValue;
@@ -131,14 +132,15 @@ class TurbineAnnotationProxy implements InvocationHandler {
private static Object constArrayValue(
Class<?> returnType, ModelFactory factory, ClassLoader loader, ArrayInitValue value) {
- if (returnType.getComponentType().equals(Class.class)) {
+ Class<?> componentType = requireNonNull(returnType.getComponentType());
+ if (componentType.equals(Class.class)) {
List<TypeMirror> result = new ArrayList<>();
for (Const element : value.elements()) {
result.add(factory.asTypeMirror(((TurbineClassValue) element).type()));
}
throw new MirroredTypesException(result);
}
- Object result = Array.newInstance(returnType.getComponentType(), value.elements().size());
+ Object result = Array.newInstance(componentType, value.elements().size());
int idx = 0;
for (Const element : value.elements()) {
Object v = constValue(returnType, factory, loader, element);
diff --git a/java/com/google/turbine/processing/TurbineFiler.java b/java/com/google/turbine/processing/TurbineFiler.java
index 186eb7f..45cdc22 100644
--- a/java/com/google/turbine/processing/TurbineFiler.java
+++ b/java/com/google/turbine/processing/TurbineFiler.java
@@ -18,6 +18,7 @@ package com.google.turbine.processing;
import static com.google.common.base.Preconditions.checkArgument;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.Objects.requireNonNull;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
@@ -361,7 +362,7 @@ public class TurbineFiler implements Filer {
@Override
public URI toUri() {
try {
- return loader.getResource(path).toURI();
+ return requireNonNull(loader.getResource(path)).toURI();
} catch (URISyntaxException e) {
throw new AssertionError(e);
}