@Override
final T buildType() {
+ final List<LengthConstraint> baseLengths = findLenghts();
+
if (lengthAlternatives == null || lengthAlternatives.isEmpty()) {
- return buildType(ImmutableList.<LengthConstraint>of());
+ return buildType(baseLengths);
}
- final List<LengthConstraint> baseLengths = findLenghts();
-
// Run through alternatives and resolve them against the base type
final List<LengthConstraint> resolvedLengths = ensureResolvedLengths(lengthAlternatives, baseLengths);
// Now verify if new ranges are strict subset of base ranges
for (LengthConstraint c : typedLengths) {
- Preconditions.checkArgument(lengthCovered(baseLengths, c),
- "Range constraint %s is not a subset of parent constraints %s", c, baseLengths);
+ if (!lengthCovered(baseLengths, c)) {
+ throw new InvalidLengthConstraintException(c, "Length constraint %s is not a subset of parent constraints %s",
+ c, baseLengths);
+ }
}
return buildType(typedLengths);