/* * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type; import javax.annotation.Nonnull; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement; import org.opendaylight.yangtools.yang.model.api.type.RangeRestrictedTypeDefinition; import org.opendaylight.yangtools.yang.model.util.type.InvalidRangeConstraintException; import org.opendaylight.yangtools.yang.model.util.type.RangeRestrictedTypeBuilder; import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase; import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.range.RangeEffectiveStatementImpl; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; final class IntegralTypeEffectiveStatementImpl, N extends Number & Comparable> extends DeclaredEffectiveStatementBase implements TypeEffectiveStatement { private final T typeDefinition; IntegralTypeEffectiveStatementImpl( final StmtContext> ctx, final RangeRestrictedTypeBuilder builder) { super(ctx); for (EffectiveStatement stmt : effectiveSubstatements()) { if (stmt instanceof RangeEffectiveStatementImpl) { final RangeEffectiveStatementImpl rangeStmt = (RangeEffectiveStatementImpl)stmt; builder.setRangeConstraint(rangeStmt, rangeStmt.argument()); } if (stmt instanceof UnknownSchemaNode) { builder.addUnknownSchemaNode((UnknownSchemaNode)stmt); } } try { typeDefinition = builder.build(); } catch (InvalidRangeConstraintException e) { throw new SourceException(ctx.getStatementSourceReference(), e, "Invalid range constraint: %s", e.getOffendingRanges()); } } @Nonnull @Override public T getTypeDefinition() { return typeDefinition; } }