diff options
author | Michajlo Matijkiw <michajlo@google.com> | 2015-09-22 02:22:12 +0000 |
---|---|---|
committer | Laszlo Csomor <laszlocsomor@google.com> | 2015-09-22 17:06:48 +0000 |
commit | 2a7c802823a0bc59d2cb010962e250ee145c620c (patch) | |
tree | f75a613a60e341c7eb0ecf6400cbb978b91456f8 /src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupValue.java | |
parent | f0a5ac60547751b34b3c307a6a4e47f8c791a720 (diff) |
Roll back using labels rather than PathFragments for skylark loads.
RELNOTES:
--
MOS_MIGRATED_REVID=103606693
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupValue.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupValue.java | 94 |
1 files changed, 26 insertions, 68 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupValue.java index 29cc2e8f8a..65fa3f0a96 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupValue.java @@ -14,90 +14,48 @@ package com.google.devtools.build.lib.skyframe; -import com.google.common.base.Preconditions; -import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.cmdline.PackageIdentifier; import com.google.devtools.build.lib.syntax.BuildFileAST; import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.SkyValue; +import javax.annotation.Nullable; + /** - * A value that represents an AST file lookup result. There are two subclasses: one for the - * case where the file is found, and another for the case where the file is missing (but there - * are no other errors). + * A value that represents an AST file lookup result. */ -public abstract class ASTFileLookupValue implements SkyValue { - public abstract boolean lookupSuccessful(); - public abstract BuildFileAST getAST(); - public abstract String getErrorMsg(); - - /* - * If the file is found, this class encapsulates the parsed AST. - */ - private static class ASTLookupWithFile extends ASTFileLookupValue { - private final BuildFileAST ast; - - private ASTLookupWithFile(BuildFileAST ast) { - Preconditions.checkNotNull(ast); - this.ast = ast; - } +public class ASTFileLookupValue implements SkyValue { - @Override - public boolean lookupSuccessful() { - return true; - } + private static final ASTFileLookupValue NO_FILE = new ASTFileLookupValue(null); - @Override - public BuildFileAST getAST() { - return this.ast; - } + @Nullable private final BuildFileAST ast; - @Override - public String getErrorMsg() { - throw new IllegalStateException("can't retrieve error for successful lookup"); - } + private ASTFileLookupValue(@Nullable BuildFileAST ast) { + this.ast = ast; } - - /* - * If the file isn't found, this class encapsulates a message with the reason. - */ - private static class ASTLookupNoFile extends ASTFileLookupValue { - private final String errorMsg; - private ASTLookupNoFile(String errorMsg) { - this.errorMsg = Preconditions.checkNotNull(errorMsg); - } - - @Override - public boolean lookupSuccessful() { - return false; - } - - @Override - public BuildFileAST getAST() { - throw new IllegalStateException("can't retrieve AST for unsuccessful lookup"); - } - - @Override - public String getErrorMsg() { - return this.errorMsg; - } + public static ASTFileLookupValue noFile() { + return NO_FILE; } - static ASTFileLookupValue forBadPackage(Label fileLabel, String reason) { - return new ASTLookupNoFile( - String.format("Unable to load package for '%s': %s", fileLabel, reason)); + public static ASTFileLookupValue withFile(BuildFileAST ast) { + return new ASTFileLookupValue(ast); } - - static ASTFileLookupValue forBadFile(Label fileLabel) { - return new ASTLookupNoFile( - String.format("Unable to load file '%s': file doesn't exist or isn't a file", fileLabel)); + + /** + * Returns the original AST file. + */ + @Nullable public BuildFileAST getAST() { + return ast; } - - public static ASTFileLookupValue withFile(BuildFileAST ast) { - return new ASTLookupWithFile(ast); + + static SkyKey key(PackageIdentifier astFileIdentifier) { + return new SkyKey(SkyFunctions.AST_FILE_LOOKUP, astFileIdentifier); } - static SkyKey key(Label astFileLabel) { - return new SkyKey(SkyFunctions.AST_FILE_LOOKUP, astFileLabel); + static final class ASTLookupInputException extends Exception { + ASTLookupInputException(String msg) { + super(msg); + } } } |