diff options
author | 2017-10-13 23:40:31 +0200 | |
---|---|---|
committer | 2017-10-16 17:48:44 +0200 | |
commit | 0dcffc5af767c80cd3831e8d34161f5e5a039246 (patch) | |
tree | 4c2007628022ef979e43b62bd4f5c94d6c50db2c /src/main/java/com/google/devtools/build/lib/analysis | |
parent | f7d5010785c8118e0a28d296a6cabee94706293a (diff) |
Extract more RuleContext error-related methods into RuleErrorConsumer
This will make it easier to pass only error-handling functionality into support classes.
RELNOTES: None.
PiperOrigin-RevId: 172148072
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java | 75 |
1 files changed, 51 insertions, 24 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java index f94ac86ca3..e948dd31d8 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java @@ -311,18 +311,12 @@ public final class RuleContext extends TargetContext return attributes; } - /** - * Returns whether this instance is known to have errors at this point during analysis. Do not - * call this method after the initializationHook has returned. - */ + @Override public boolean hasErrors() { return getAnalysisEnvironment().hasErrors(); } - /** - * No-op if {@link #hasErrors} is false, throws {@link RuleErrorException} if it is true. - * This provides a convenience to early-exit of configured target creation if there are errors. - */ + @Override public void assertNoErrors() throws RuleErrorException { if (hasErrors()) { throw new RuleErrorException(); @@ -452,13 +446,8 @@ public final class RuleContext extends TargetContext reporter.ruleError(message); } - /** - * Convenience function to report non-attribute-specific errors in the current rule and then - * throw a {@link RuleErrorException}, immediately exiting the build invocation. Alternatively, - * invoke {@link #ruleError} instead to collect additional error information before ending the - * invocation. - */ - public void throwWithRuleError(String message) throws RuleErrorException { + @Override + public RuleErrorException throwWithRuleError(String message) throws RuleErrorException { reporter.ruleError(message); throw new RuleErrorException(); } @@ -484,15 +473,7 @@ public final class RuleContext extends TargetContext reporter.attributeError(attrName, message); } - /** - * Convenience function to report attribute-specific errors in the current rule, and then throw a - * {@link RuleErrorException}, immediately exiting the build invocation. Alternatively, invoke - * {@link #attributeError} instead to collect additional error information before ending the - * invocation. - * - * <p>If the name of the attribute starts with <code>$</code> - * it is replaced with a string <code>(an implicit dependency)</code>. - */ + @Override public RuleErrorException throwWithAttributeError(String attrName, String message) throws RuleErrorException { reporter.attributeError(attrName, message); @@ -1598,6 +1579,27 @@ public final class RuleContext extends TargetContext reporter.attributeWarning(attrName, message); } + @Override + public RuleErrorException throwWithRuleError(String message) throws RuleErrorException { + throw reporter.throwWithRuleError(message); + } + + @Override + public RuleErrorException throwWithAttributeError(String attrName, String message) + throws RuleErrorException { + throw reporter.throwWithAttributeError(attrName, message); + } + + @Override + public boolean hasErrors() { + return reporter.hasErrors(); + } + + @Override + public void assertNoErrors() throws RuleErrorException { + reporter.assertNoErrors(); + } + private String badPrerequisiteMessage(String targetKind, ConfiguredTarget prerequisite, String reason, boolean isWarning) { String msgPrefix = targetKind != null ? targetKind + " " : ""; @@ -1879,6 +1881,31 @@ public final class RuleContext extends TargetContext reportError(rule.getAttributeLocation(attrName), completeAttributeMessage(attrName, message)); } + @Override + public RuleErrorException throwWithRuleError(String message) throws RuleErrorException { + ruleError(message); + throw new RuleErrorException(); + } + + @Override + public RuleErrorException throwWithAttributeError(String attrName, String message) + throws RuleErrorException { + attributeError(attrName, message); + throw new RuleErrorException(); + } + + @Override + public boolean hasErrors() { + return env.hasErrors(); + } + + @Override + public void assertNoErrors() throws RuleErrorException { + if (hasErrors()) { + throw new RuleErrorException(); + } + } + public void reportWarning(Location location, String message) { env.getEventHandler().handle(Event.warn(location, message)); } |