aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/AbstractClassEntryState.java
diff options
context:
space:
mode:
authorGravatar cnsun <cnsun@google.com>2018-02-06 10:57:49 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-06 10:59:37 -0800
commit33c419bb0952721f056f01a0374f9f2d238e98bd (patch)
tree2d85645b03699f85231cd28c8d9865058c9e3925 /src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/AbstractClassEntryState.java
parent11c59283ec83db0c62ad67e7f0ffbfb8a5183b06 (diff)
Add a new tool to check the deps of aar_import. This is the first cl of a
series. The following CLs will integrate this into bazel. RELNOTES:n/a. PiperOrigin-RevId: 184706507
Diffstat (limited to 'src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/AbstractClassEntryState.java')
-rw-r--r--src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/AbstractClassEntryState.java124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/AbstractClassEntryState.java b/src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/AbstractClassEntryState.java
new file mode 100644
index 0000000000..209bf83fcb
--- /dev/null
+++ b/src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/AbstractClassEntryState.java
@@ -0,0 +1,124 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.importdeps;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import com.google.auto.value.AutoValue;
+import com.google.common.collect.ImmutableList;
+import java.util.Optional;
+
+/**
+ * The state for a class entry used in {@link ClassCache}. A state can be
+ *
+ * <ul>
+ * <li>EXISTING: this class exists.
+ * <li>INCOMPLETE: this class exists, but at least one of its ancestor is missing.
+ * <li>MISSING: this class is missing on the classpath.
+ * </ul>
+ */
+public abstract class AbstractClassEntryState {
+
+ public boolean isMissingState() {
+ return this instanceof MissingState;
+ }
+
+ public MissingState asMissingState() {
+ throw new IllegalStateException("Not a missing state " + this);
+ }
+
+ public boolean isExistingState() {
+ return this instanceof ExistingState;
+ }
+
+ public ExistingState asExistingState() {
+ throw new IllegalStateException("Not an existing state " + this);
+ }
+
+ public boolean isIncompleteState() {
+ return this instanceof IncompleteState;
+ }
+
+ public IncompleteState asIncompleteState() {
+ throw new IllegalStateException("Not an incomplete state " + this);
+ }
+
+ public abstract Optional<ClassInfo> classInfo();
+
+ /** A state to indicate that a class exists. */
+ @AutoValue
+ public abstract static class ExistingState extends AbstractClassEntryState {
+
+ public static ExistingState create(ClassInfo classInfo) {
+ return new AutoValue_AbstractClassEntryState_ExistingState(Optional.of(classInfo));
+ }
+
+ @Override
+ public ExistingState asExistingState() {
+ return this;
+ }
+ }
+
+ /** A state to indicate that a class is missing. */
+ public static final class MissingState extends AbstractClassEntryState {
+
+ private static final MissingState SINGLETON = new MissingState();
+
+ public static MissingState singleton() {
+ return SINGLETON;
+ }
+
+ private MissingState() {}
+
+ @Override
+ public MissingState asMissingState() {
+ return this;
+ }
+
+ @Override
+ public Optional<ClassInfo> classInfo() {
+ return Optional.empty();
+ }
+ }
+
+ /**
+ * A state to indicate that a class is incomplete, that is, some ancesotor is missing on the
+ * classpath.
+ */
+ @AutoValue
+ public abstract static class IncompleteState extends AbstractClassEntryState {
+
+ public static IncompleteState create(
+ ClassInfo classInfo, ImmutableList<String> resolutionFailurePath) {
+ checkArgument(
+ !resolutionFailurePath.isEmpty(),
+ "The resolution path should contain at least one element, the missing ancestor. %s",
+ resolutionFailurePath);
+ return new AutoValue_AbstractClassEntryState_IncompleteState(
+ Optional.of(classInfo), resolutionFailurePath);
+ }
+
+ public abstract ImmutableList<String> getResolutionFailurePath();
+
+ public String getMissingAncestor() {
+ ImmutableList<String> path = getResolutionFailurePath();
+ return path.get(path.size() - 1);
+ }
+
+ @Override
+ public IncompleteState asIncompleteState() {
+ return this;
+ }
+ }
+}