aboutsummaryrefslogtreecommitdiff
path: root/java/com
diff options
context:
space:
mode:
authorcushon <cushon@google.com>2018-08-22 11:36:55 -0700
committerLiam Miller-Cushon <cushon@google.com>2018-09-09 16:48:30 -0700
commit6fc009c4a2f610d58b5c41772be1f6d6bbe62b66 (patch)
tree0e116a592b330877393d8ed24ed1df974901ecb5 /java/com
parent04ebb17e593bb1e2484aa755c54e79e0f84258c1 (diff)
downloadturbine-6fc009c4a2f610d58b5c41772be1f6d6bbe62b66.tar.gz
Use java.util.Optional instead of guava's Optional
MOE_MIGRATED_REVID=209800977
Diffstat (limited to 'java/com')
-rw-r--r--java/com/google/turbine/binder/Binder.java5
-rw-r--r--java/com/google/turbine/binder/CompUnitPreprocessor.java4
-rw-r--r--java/com/google/turbine/binder/ConstEvaluator.java2
-rw-r--r--java/com/google/turbine/binder/HierarchyBinder.java2
-rw-r--r--java/com/google/turbine/binder/ModuleBinder.java4
-rw-r--r--java/com/google/turbine/binder/TypeBinder.java2
-rw-r--r--java/com/google/turbine/deps/Dependencies.java2
-rw-r--r--java/com/google/turbine/main/Main.java4
-rw-r--r--java/com/google/turbine/options/TurbineOptions.java12
-rw-r--r--java/com/google/turbine/parse/ConstExpressionParser.java5
-rw-r--r--java/com/google/turbine/parse/Parser.java44
-rw-r--r--java/com/google/turbine/tree/Tree.java2
12 files changed, 43 insertions, 45 deletions
diff --git a/java/com/google/turbine/binder/Binder.java b/java/com/google/turbine/binder/Binder.java
index d4b151f..e1fbafb 100644
--- a/java/com/google/turbine/binder/Binder.java
+++ b/java/com/google/turbine/binder/Binder.java
@@ -16,8 +16,6 @@
package com.google.turbine.binder;
-
-import com.google.common.base.Optional;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -62,6 +60,7 @@ import com.google.turbine.tree.Tree.CompUnit;
import com.google.turbine.tree.Tree.ModDecl;
import com.google.turbine.type.Type;
import java.util.List;
+import java.util.Optional;
/** The entry point for analysis. */
public class Binder {
@@ -262,7 +261,7 @@ public class Binder {
if (info != null) {
return new ModuleInfo(
info.module().moduleName(),
- moduleVersion.orNull(),
+ moduleVersion.orElse(null),
/* flags= */ 0,
/* annos= */ ImmutableList.of(),
/* requires= */ ImmutableList.of(),
diff --git a/java/com/google/turbine/binder/CompUnitPreprocessor.java b/java/com/google/turbine/binder/CompUnitPreprocessor.java
index 121b18d..f33e62b 100644
--- a/java/com/google/turbine/binder/CompUnitPreprocessor.java
+++ b/java/com/google/turbine/binder/CompUnitPreprocessor.java
@@ -17,7 +17,6 @@
package com.google.turbine.binder;
import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -38,6 +37,7 @@ import com.google.turbine.tree.Tree.TyDecl;
import com.google.turbine.tree.TurbineModifier;
import java.util.HashSet;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
/**
@@ -215,7 +215,7 @@ public class CompUnitPreprocessor {
pkgDecl.annos(),
"package-info",
ImmutableList.of(),
- Optional.absent(),
+ Optional.empty(),
ImmutableList.of(),
ImmutableList.of(),
TurbineTyKind.INTERFACE);
diff --git a/java/com/google/turbine/binder/ConstEvaluator.java b/java/com/google/turbine/binder/ConstEvaluator.java
index 7e79919..e1409b1 100644
--- a/java/com/google/turbine/binder/ConstEvaluator.java
+++ b/java/com/google/turbine/binder/ConstEvaluator.java
@@ -194,7 +194,7 @@ public strictfp class ConstEvaluator {
*/
private ClassSymbol resolveClass(ClassTy classTy) {
ArrayDeque<String> flat = new ArrayDeque<>();
- for (ClassTy curr = classTy; curr != null; curr = curr.base().orNull()) {
+ for (ClassTy curr = classTy; curr != null; curr = curr.base().orElse(null)) {
flat.addFirst(curr.name());
}
LookupResult result = scope.lookup(new LookupKey(flat));
diff --git a/java/com/google/turbine/binder/HierarchyBinder.java b/java/com/google/turbine/binder/HierarchyBinder.java
index 2545c17..f7fa7b0 100644
--- a/java/com/google/turbine/binder/HierarchyBinder.java
+++ b/java/com/google/turbine/binder/HierarchyBinder.java
@@ -111,7 +111,7 @@ public class HierarchyBinder {
// flatten a left-recursive qualified type name to its component simple names
// e.g. Foo<Bar>.Baz -> ["Foo", "Bar"]
ArrayDeque<String> flat = new ArrayDeque<>();
- for (Tree.ClassTy curr = ty; curr != null; curr = curr.base().orNull()) {
+ for (Tree.ClassTy curr = ty; curr != null; curr = curr.base().orElse(null)) {
flat.addFirst(curr.name());
}
// Resolve the base symbol in the qualified name.
diff --git a/java/com/google/turbine/binder/ModuleBinder.java b/java/com/google/turbine/binder/ModuleBinder.java
index 312ec45..257bd9a 100644
--- a/java/com/google/turbine/binder/ModuleBinder.java
+++ b/java/com/google/turbine/binder/ModuleBinder.java
@@ -19,7 +19,6 @@ package com.google.turbine.binder;
import static com.google.common.base.Verify.verifyNotNull;
import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.turbine.binder.bound.ModuleInfo;
@@ -51,6 +50,7 @@ import com.google.turbine.tree.Tree.ModRequires;
import com.google.turbine.tree.Tree.ModUses;
import com.google.turbine.tree.TurbineModifier;
import com.google.turbine.type.AnnoInfo;
+import java.util.Optional;
/** Binding pass for modules. */
public class ModuleBinder {
@@ -149,7 +149,7 @@ public class ModuleBinder {
return new SourceModuleInfo(
module.module().moduleName(),
- moduleVersion.orNull(),
+ moduleVersion.orElse(null),
flags,
annos,
requires.build(),
diff --git a/java/com/google/turbine/binder/TypeBinder.java b/java/com/google/turbine/binder/TypeBinder.java
index e0546ac..d5b0a4c 100644
--- a/java/com/google/turbine/binder/TypeBinder.java
+++ b/java/com/google/turbine/binder/TypeBinder.java
@@ -620,7 +620,7 @@ public class TypeBinder {
ArrayList<Tree.ClassTy> flat;
{
ArrayDeque<Tree.ClassTy> builder = new ArrayDeque<>();
- for (Tree.ClassTy curr = t; curr != null; curr = curr.base().orNull()) {
+ for (Tree.ClassTy curr = t; curr != null; curr = curr.base().orElse(null)) {
builder.addFirst(curr);
}
flat = new ArrayList<>(builder);
diff --git a/java/com/google/turbine/deps/Dependencies.java b/java/com/google/turbine/deps/Dependencies.java
index a3c654e..f76efe7 100644
--- a/java/com/google/turbine/deps/Dependencies.java
+++ b/java/com/google/turbine/deps/Dependencies.java
@@ -16,7 +16,6 @@
package com.google.turbine.deps;
-import com.google.common.base.Optional;
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
@@ -40,6 +39,7 @@ import java.nio.file.Paths;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
+import java.util.Optional;
import java.util.Set;
/** Support for Bazel jdeps dependency output. */
diff --git a/java/com/google/turbine/main/Main.java b/java/com/google/turbine/main/Main.java
index 31a36c4..1ed5233 100644
--- a/java/com/google/turbine/main/Main.java
+++ b/java/com/google/turbine/main/Main.java
@@ -18,7 +18,6 @@ package com.google.turbine.main;
import static java.nio.charset.StandardCharsets.UTF_8;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.hash.Hashing;
import com.google.turbine.binder.Binder;
@@ -50,6 +49,7 @@ import java.time.ZoneId;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
+import java.util.Optional;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -93,7 +93,7 @@ public class Main {
ClassPath classpath = ClassPathBinder.bindClasspath(toPaths(reducedClasspath));
BindingResult bound =
- Binder.bind(units, classpath, bootclasspath, /* moduleVersion=*/ Optional.absent());
+ Binder.bind(units, classpath, bootclasspath, /* moduleVersion=*/ Optional.empty());
// TODO(cushon): parallelize
Lowered lowered = Lower.lowerAll(bound.units(), bound.modules(), bound.classPathEnv());
diff --git a/java/com/google/turbine/options/TurbineOptions.java b/java/com/google/turbine/options/TurbineOptions.java
index 7dd118e..5e52335 100644
--- a/java/com/google/turbine/options/TurbineOptions.java
+++ b/java/com/google/turbine/options/TurbineOptions.java
@@ -18,9 +18,9 @@ package com.google.turbine.options;
import static com.google.common.base.Preconditions.checkNotNull;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
+import java.util.Optional;
import org.checkerframework.checker.nullness.qual.Nullable;
/** Header compilation options. */
@@ -65,16 +65,16 @@ public class TurbineOptions {
this.output = checkNotNull(output, "output must not be null");
this.classPath = checkNotNull(classPath, "classPath must not be null");
this.bootClassPath = checkNotNull(bootClassPath, "bootClassPath must not be null");
- this.release = Optional.fromNullable(release);
- this.system = Optional.fromNullable(system);
+ this.release = Optional.ofNullable(release);
+ this.system = Optional.ofNullable(system);
this.sources = checkNotNull(sources, "sources must not be null");
this.processorPath = checkNotNull(processorPath, "processorPath must not be null");
this.processors = checkNotNull(processors, "processors must not be null");
this.sourceJars = checkNotNull(sourceJars, "sourceJars must not be null");
- this.outputDeps = Optional.fromNullable(outputDeps);
+ this.outputDeps = Optional.ofNullable(outputDeps);
this.directJars = checkNotNull(directJars, "directJars must not be null");
- this.targetLabel = Optional.fromNullable(targetLabel);
- this.injectingRuleKind = Optional.fromNullable(injectingRuleKind);
+ this.targetLabel = Optional.ofNullable(targetLabel);
+ this.injectingRuleKind = Optional.ofNullable(injectingRuleKind);
this.depsArtifacts = checkNotNull(depsArtifacts, "depsArtifacts must not be null");
this.javacFallback = javacFallback;
this.javacOpts = checkNotNull(javacOpts, "javacOpts must not be null");
diff --git a/java/com/google/turbine/parse/ConstExpressionParser.java b/java/com/google/turbine/parse/ConstExpressionParser.java
index 51f3128..557438f 100644
--- a/java/com/google/turbine/parse/ConstExpressionParser.java
+++ b/java/com/google/turbine/parse/ConstExpressionParser.java
@@ -18,7 +18,6 @@ package com.google.turbine.parse;
import static com.google.common.collect.Iterables.getOnlyElement;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CheckReturnValue;
import com.google.turbine.diag.TurbineError;
@@ -30,6 +29,7 @@ import com.google.turbine.tree.Tree.ClassLiteral;
import com.google.turbine.tree.Tree.ClassTy;
import com.google.turbine.tree.Tree.Expression;
import com.google.turbine.tree.TurbineOperatorKind;
+import java.util.Optional;
import org.checkerframework.checker.nullness.qual.Nullable;
/** A parser for compile-time constant expressions. */
@@ -233,8 +233,7 @@ public class ConstExpressionParser {
private static ClassTy asClassTy(int pos, ImmutableList<String> names) {
ClassTy cty = null;
for (String bit : names) {
- cty =
- new ClassTy(pos, Optional.fromNullable(cty), bit, ImmutableList.of(), ImmutableList.of());
+ cty = new ClassTy(pos, Optional.ofNullable(cty), bit, ImmutableList.of(), ImmutableList.of());
}
return cty;
}
diff --git a/java/com/google/turbine/parse/Parser.java b/java/com/google/turbine/parse/Parser.java
index 752b2a5..bd909dd 100644
--- a/java/com/google/turbine/parse/Parser.java
+++ b/java/com/google/turbine/parse/Parser.java
@@ -26,7 +26,6 @@ import static com.google.turbine.tree.TurbineModifier.PROTECTED;
import static com.google.turbine.tree.TurbineModifier.PUBLIC;
import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.CheckReturnValue;
@@ -63,6 +62,7 @@ import java.util.ArrayDeque;
import java.util.Deque;
import java.util.EnumSet;
import java.util.List;
+import java.util.Optional;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
@@ -95,8 +95,8 @@ public class Parser {
// TODO(cushon): consider enforcing package, import, and declaration order
// and make it bug-compatible with javac:
// http://mail.openjdk.java.net/pipermail/compiler-dev/2013-August/006968.html
- Optional<PkgDecl> pkg = Optional.absent();
- Optional<ModDecl> mod = Optional.absent();
+ Optional<PkgDecl> pkg = Optional.empty();
+ Optional<ModDecl> mod = Optional.empty();
EnumSet<TurbineModifier> access = EnumSet.noneOf(TurbineModifier.class);
ImmutableList.Builder<ImportDecl> imports = ImmutableList.builder();
ImmutableList.Builder<TyDecl> decls = ImmutableList.builder();
@@ -238,7 +238,7 @@ public class Parser {
annos,
name,
typarams,
- Optional.<ClassTy>absent(),
+ Optional.<ClassTy>empty(),
interfaces.build(),
members,
TurbineTyKind.INTERFACE);
@@ -257,7 +257,7 @@ public class Parser {
annos,
name,
ImmutableList.<TyParam>of(),
- Optional.<ClassTy>absent(),
+ Optional.<ClassTy>empty(),
ImmutableList.<ClassTy>of(),
members,
TurbineTyKind.ANNOTATION);
@@ -284,7 +284,7 @@ public class Parser {
annos,
name,
ImmutableList.<TyParam>of(),
- Optional.<ClassTy>absent(),
+ Optional.<ClassTy>empty(),
interfaces.build(),
members,
TurbineTyKind.ENUM);
@@ -444,12 +444,12 @@ public class Parser {
annos.build(),
new ClassTy(
position,
- Optional.<ClassTy>absent(),
+ Optional.<ClassTy>empty(),
enumName,
ImmutableList.<Type>of(),
ImmutableList.of()),
name,
- Optional.<Expression>absent()));
+ Optional.<Expression>empty()));
annos = ImmutableList.builder();
break;
}
@@ -500,7 +500,7 @@ public class Parser {
annos,
name,
tyParams,
- Optional.fromNullable(xtnds),
+ Optional.ofNullable(xtnds),
interfaces.build(),
members,
TurbineTyKind.CLASS);
@@ -672,7 +672,7 @@ public class Parser {
result =
new ClassTy(
position,
- Optional.<ClassTy>absent(),
+ Optional.<ClassTy>empty(),
ident,
ImmutableList.<Type>of(),
ImmutableList.of());
@@ -686,7 +686,7 @@ public class Parser {
result =
new ClassTy(
position,
- Optional.<ClassTy>absent(),
+ Optional.<ClassTy>empty(),
ident,
ImmutableList.<Type>of(),
ImmutableList.of());
@@ -697,7 +697,7 @@ public class Parser {
{
result =
new ClassTy(
- position, Optional.<ClassTy>absent(), ident, tyargs(), ImmutableList.of());
+ position, Optional.<ClassTy>empty(), ident, tyargs(), ImmutableList.of());
result = maybeDims(maybeAnnos(), result);
break;
}
@@ -705,7 +705,7 @@ public class Parser {
result =
new ClassTy(
position,
- Optional.<ClassTy>absent(),
+ Optional.<ClassTy>empty(),
ident,
ImmutableList.<Type>of(),
ImmutableList.of());
@@ -810,7 +810,7 @@ public class Parser {
if (init != null && init.kind() == Tree.Kind.ARRAY_INIT) {
init = null;
}
- result.add(new VarDecl(pos, access, annos, ty, name, Optional.fromNullable(init)));
+ result.add(new VarDecl(pos, access, annos, ty, name, Optional.ofNullable(init)));
}
eat(Token.SEMI);
return result.build();
@@ -870,11 +870,11 @@ public class Parser {
access,
annos,
typaram,
- Optional.<Tree>fromNullable(result),
+ Optional.<Tree>ofNullable(result),
name,
formals.build(),
exceptions.build(),
- Optional.fromNullable(defaultValue));
+ Optional.ofNullable(defaultValue));
}
/**
@@ -955,7 +955,7 @@ public class Parser {
name = identOrThis();
}
ty = extraDims(ty);
- return new VarDecl(position, access, annos.build(), ty, name, Optional.<Expression>absent());
+ return new VarDecl(position, access, annos.build(), ty, name, Optional.<Expression>empty());
}
private String identOrThis() {
@@ -1064,7 +1064,7 @@ public class Parser {
if (token == Token.LT) {
tyargs = tyargs();
}
- ty = new ClassTy(pos, Optional.fromNullable(ty), name, tyargs, typeAnnos);
+ ty = new ClassTy(pos, Optional.ofNullable(ty), name, tyargs, typeAnnos);
typeAnnos = null;
} while (maybe(Token.DOT));
return ty;
@@ -1085,25 +1085,25 @@ public class Parser {
next();
Type upper = referenceType(maybeAnnos());
acc.add(
- new WildTy(position, typeAnnos, Optional.of(upper), Optional.<Type>absent()));
+ new WildTy(position, typeAnnos, Optional.of(upper), Optional.<Type>empty()));
break;
case SUPER:
next();
Type lower = referenceType(maybeAnnos());
acc.add(
- new WildTy(position, typeAnnos, Optional.<Type>absent(), Optional.of(lower)));
+ new WildTy(position, typeAnnos, Optional.<Type>empty(), Optional.of(lower)));
break;
case COMMA:
acc.add(
new WildTy(
- position, typeAnnos, Optional.<Type>absent(), Optional.<Type>absent()));
+ position, typeAnnos, Optional.<Type>empty(), Optional.<Type>empty()));
continue OUTER;
case GT:
case GTGT:
case GTGTGT:
acc.add(
new WildTy(
- position, typeAnnos, Optional.<Type>absent(), Optional.<Type>absent()));
+ position, typeAnnos, Optional.<Type>empty(), Optional.<Type>empty()));
break OUTER;
default:
throw error(token);
diff --git a/java/com/google/turbine/tree/Tree.java b/java/com/google/turbine/tree/Tree.java
index a84c776..7f7d476 100644
--- a/java/com/google/turbine/tree/Tree.java
+++ b/java/com/google/turbine/tree/Tree.java
@@ -16,13 +16,13 @@
package com.google.turbine.tree;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.turbine.diag.SourceFile;
import com.google.turbine.model.Const;
import com.google.turbine.model.TurbineConstantTypeKind;
import com.google.turbine.model.TurbineTyKind;
+import java.util.Optional;
import java.util.Set;
/** An AST node. */