Add method for raw access to attribute container contents
@@ -15,8 +15,10 @@ package com.google.devtools.build.lib.packages;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
import com.google.errorprone.annotations.CheckReturnValue;
import java.util.BitSet;
+import java.util.List;
import javax.annotation.Nullable;
/**
@@ -43,6 +45,13 @@ abstract class AttributeContainer {
@Nullable
abstract Object getAttributeValue(int attrIndex);
+ /**
+ * Returns attribute values as tracked by this instance. The indices of attribute values in the
+ * returned list are not guaranteed to be consistent with the other methods of this class. If this
+ * is important, which is generally the case, avoid this method.
+ */
+ abstract List<Object> getRawAttributeValues();
+
/**
* Updates the value of the attribute.
*
@@ -121,6 +130,12 @@ abstract class AttributeContainer {
return new Large(values, explicitAttrs);
}
}
+
+ @Override
+ List<Object> getRawAttributeValues() {
+ // Mutable copy since ImmutableList doesn't support null.
+ return Lists.newArrayList(values);
+ }
}
/** Frozen AttributeContainer based on compact array with indirect indexing. */
@@ -260,6 +275,12 @@ abstract class AttributeContainer {
int stateIndex = getStateIndex(state, 0, attrIndex, 0x7f);
return stateIndex < 0 ? null : values[stateIndex];
}
+
+ @Override
+ List<Object> getRawAttributeValues() {
+ // Mutable copy since ImmutableList doesn't support null.
+ return Lists.newArrayList(values);
+ }
}
/**
@@ -376,5 +397,11 @@ abstract class AttributeContainer {
int stateIndex = getStateIndex(state, p, attrIndex, 0xff);
return stateIndex < 0 ? null : values[stateIndex - p];
}
+
+ @Override
+ List<Object> getRawAttributeValues() {
+ // Mutable copy since ImmutableList doesn't support null.
+ return Lists.newArrayList(values);
+ }
}
}
