@Override final T buildType() { return buildType(lengthConstraint != null ? lengthConstraint : findLenghts()); }
private LengthConstraint findLenghts() { Optional<LengthConstraint> ret = Optional.empty(); T wlk = getBaseType(); while (wlk != null && !ret.isPresent()) { ret = wlk.getLengthConstraint(); wlk = wlk.getBaseType(); } return ret.orElse(typeLengthConstraints()); } }
final @NonNull List<ValueRange> ranges) throws InvalidLengthConstraintException { Preconditions.checkState(lengthConstraint == null, "Length constraint already defined as %s", lengthConstraint); final LengthConstraint baseLengths = findLenghts(); if (ranges.isEmpty()) { lengthConstraint = baseLengths; builder.add(Range.closed(resolveLength(c.lowerBound(), span), resolveLength(c.upperBound(), span))); touch();
BinaryTypeEffectiveStatementImpl( final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx, final BinaryTypeDefinition baseType) { super(ctx); final LengthRestrictedTypeBuilder<BinaryTypeDefinition> builder = RestrictedTypes.newBinaryBuilder(baseType, AbstractTypeStatementSupport.typeEffectiveSchemaPath(ctx)); for (EffectiveStatement<?, ?> stmt : effectiveSubstatements()) { if (stmt instanceof LengthEffectiveStatementImpl) { final LengthEffectiveStatementImpl length = (LengthEffectiveStatementImpl)stmt; try { builder.setLengthConstraint(length, length.argument()); } catch (IllegalStateException e) { throw new SourceException(ctx.getStatementSourceReference(), e, "Multiple length constraints encountered"); } catch (InvalidLengthConstraintException e) { throw new SourceException(ctx.getStatementSourceReference(), e, "Invalid length constraint %s", length.argument()); } } if (stmt instanceof UnknownSchemaNode) { builder.addUnknownSchemaNode((UnknownSchemaNode)stmt); } } typeDefinition = builder.build(); }
final @NonNull List<ValueRange> ranges) throws InvalidLengthConstraintException { Preconditions.checkState(lengthConstraint == null, "Length constraint already defined as %s", lengthConstraint); final LengthConstraint baseLengths = findLenghts(); if (ranges.isEmpty()) { lengthConstraint = baseLengths; builder.add(Range.closed(resolveLength(c.lowerBound(), span), resolveLength(c.upperBound(), span))); touch();
private LengthConstraint findLenghts() { Optional<LengthConstraint> ret = Optional.empty(); T wlk = getBaseType(); while (wlk != null && !ret.isPresent()) { ret = wlk.getLengthConstraint(); wlk = wlk.getBaseType(); } return ret.orElse(typeLengthConstraints()); } }
@Override final T buildType() { return buildType(lengthConstraint != null ? lengthConstraint : findLenghts()); }