aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/packages
diff options
context:
space:
mode:
authorGravatar Greg Estren <gregce@google.com>2017-02-14 21:30:29 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2017-02-15 10:04:56 +0000
commit564940d73ab135f2dd0573623b8934ed1cd7b9d1 (patch)
treeb886fabd6a057ef9c3d2e75fd2af6cfc9faf0f98 /src/main/java/com/google/devtools/build/lib/packages
parentf98361fe0f7af3d549838f940e4af32b73888755 (diff)
Remove type checking requirement from AttributeMap.has.
This overrides the traditional has(String name, Type<>T> type) with has(String name) and removes the type check outright from isConfigurable. Ideally we'd remove the old version in this same change. But there are enough uses of it that that's not a risk-free change and is safer as followup changes. -- PiperOrigin-RevId: 147513593 MOS_MIGRATED_REVID=147513593
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages')
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java12
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/AttributeMap.java21
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/DelegatingAttributeMapper.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/ImplicitOutputsFunction.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java4
6 files changed, 45 insertions, 23 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
index a7b55b22db..7837317afb 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
@@ -166,8 +166,9 @@ public abstract class AbstractAttributeMapper implements AttributeMap {
}
@Override
- public final <T> boolean isConfigurable(String attributeName, Type<T> type) {
- return getSelectorList(attributeName, type) != null;
+ public final boolean isConfigurable(String attributeName) {
+ Attribute attrDef = getAttributeDefinition(attributeName);
+ return attrDef == null ? false : getSelectorList(attributeName, attrDef.getType()) != null;
}
public static <T> boolean isConfigurable(Rule rule, String attributeName, Type<T> type) {
@@ -244,8 +245,13 @@ public abstract class AbstractAttributeMapper implements AttributeMap {
}
@Override
- public boolean has(String attrName, Type<?> type) {
+ public boolean has(String attrName) {
Attribute attribute = ruleClass.getAttributeByNameMaybe(attrName);
- return attribute != null && attribute.getType() == type;
+ return attribute != null;
+ }
+
+ @Override
+ public <T> boolean has(String attrName, Type<T> type) {
+ return getAttributeType(attrName) == type;
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java
index 17f8dad21c..e3a390e958 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java
@@ -16,7 +16,6 @@ package com.google.devtools.build.lib.packages;
import com.google.common.base.Verify;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@@ -460,8 +459,8 @@ public class AggregatingAttributeMapper extends AbstractAttributeMapper {
}
@Override
- public <T> boolean isConfigurable(String attributeName, Type<T> type) {
- return owner.isConfigurable(attributeName, type);
+ public boolean isConfigurable(String attributeName) {
+ return owner.isConfigurable(attributeName);
}
@Override
@@ -525,7 +524,12 @@ public class AggregatingAttributeMapper extends AbstractAttributeMapper {
}
@Override
- public boolean has(String attrName, Type<?> type) {
+ public boolean has(String attrName) {
+ return owner.has(attrName);
+ }
+
+ @Override
+ public <T> boolean has(String attrName, Type<T> type) {
return owner.has(attrName, type);
}
};
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AttributeMap.java b/src/main/java/com/google/devtools/build/lib/packages/AttributeMap.java
index 3e62f2947d..a573bf038a 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AttributeMap.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AttributeMap.java
@@ -39,6 +39,18 @@ public interface AttributeMap {
Label getLabel();
/**
+ * Returns true if an attribute with the given name exists.
+ */
+ boolean has(String attrName);
+
+ /**
+ * Returns true if an attribute with the given name exists with the given type.
+ *
+ * <p>Don't use this version unless you really care about the type.
+ */
+ <T> boolean has(String attrName, Type<T> type);
+
+ /**
* Returns the value of the named rule attribute, which must be of the given type. This may
* be null (for example, for an attribute with no default value that isn't explicitly set in
* the rule - see {@link Type#getDefaultValue}).
@@ -51,9 +63,9 @@ public interface AttributeMap {
/**
* Returns true if the given attribute is configurable for this rule instance, false
- * otherwise.
+ * if it isn't configurable or doesn't exist.
*/
- <T> boolean isConfigurable(String attributeName, Type<T> type);
+ boolean isConfigurable(String attributeName);
/**
* Returns the names of all attributes covered by this map.
@@ -115,9 +127,4 @@ public interface AttributeMap {
String getPackageDefaultDeprecation();
ImmutableList<String> getPackageDefaultCopts();
-
- /**
- * @return true if an attribute with the given name and type is present
- */
- boolean has(String attrName, Type<?> type);
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/DelegatingAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/DelegatingAttributeMapper.java
index e57476c551..3f0d2b0eef 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/DelegatingAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/DelegatingAttributeMapper.java
@@ -46,8 +46,8 @@ public class DelegatingAttributeMapper implements AttributeMap {
}
@Override
- public <T> boolean isConfigurable(String attributeName, Type<T> type) {
- return delegate.isConfigurable(attributeName, type);
+ public boolean isConfigurable(String attributeName) {
+ return delegate.isConfigurable(attributeName);
}
@Override
@@ -98,7 +98,12 @@ public class DelegatingAttributeMapper implements AttributeMap {
}
@Override
- public boolean has(String attrName, Type<?> type) {
+ public boolean has(String attrName) {
+ return delegate.has(attrName);
+ }
+
+ @Override
+ public <T> boolean has(String attrName, Type<T> type) {
return delegate.has(attrName, type);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/ImplicitOutputsFunction.java b/src/main/java/com/google/devtools/build/lib/packages/ImplicitOutputsFunction.java
index 89356a06f6..a2f0b6e4f6 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/ImplicitOutputsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/ImplicitOutputsFunction.java
@@ -89,7 +89,7 @@ public abstract class ImplicitOutputsFunction {
Type<?> attrType = map.getAttributeType(attrName);
// Don't include configurable attributes: we don't know which value they might take
// since we don't yet have a build configuration.
- if (!map.isConfigurable(attrName, attrType)) {
+ if (!map.isConfigurable(attrName)) {
Object value = map.get(attrName, attrType);
attrValues.put(attrName, value == null ? Runtime.NONE : value);
}
@@ -291,7 +291,9 @@ public abstract class ImplicitOutputsFunction {
}
Type<?> attrType = rule.getAttributeType(attrName);
- if (attrType == null) { return Collections.emptySet(); }
+ if (attrType == null) {
+ return Collections.emptySet();
+ }
// String attributes and lists are easy.
if (Type.STRING == attrType) {
return singleton(rule.get(attrName, Type.STRING));
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java
index cbe270238a..eedaae0747 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java
@@ -21,10 +21,8 @@ import com.google.devtools.build.lib.packages.BuildType.Selector;
import com.google.devtools.build.lib.packages.BuildType.SelectorList;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.util.Preconditions;
-
import java.util.Collection;
import java.util.List;
-
import javax.annotation.Nullable;
/**
@@ -69,7 +67,7 @@ public class RawAttributeMapper extends AbstractAttributeMapper {
@Nullable
public <T> Collection<T> getMergedValues(String attributeName, Type<List<T>> type) {
Preconditions.checkState(type instanceof Type.ListType);
- if (!isConfigurable(attributeName, type)) {
+ if (!isConfigurable(attributeName)) {
return get(attributeName, type);
}