From 93f4ace6f2a244f2056c37f2515cd00fea5f75ba Mon Sep 17 00:00:00 2001 From: Martin Vitez Date: Tue, 26 Aug 2014 13:48:28 +0200 Subject: [PATCH] BUG-869: reworked check for integer value. Change-Id: I65b34369eeb546cd8f1716b2b7adfd25232ddece Signed-off-by: Martin Vitez --- .../yang/parser/impl/ParserListenerUtils.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/ParserListenerUtils.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/ParserListenerUtils.java index 933ac6b6d4..83b56314cb 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/ParserListenerUtils.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/ParserListenerUtils.java @@ -11,17 +11,14 @@ import static com.google.common.base.Preconditions.checkState; import com.google.common.base.CharMatcher; import com.google.common.base.Optional; -import com.google.common.base.Preconditions; import com.google.common.base.Splitter; import com.google.common.collect.Lists; - import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; - import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.TerminalNode; @@ -183,13 +180,13 @@ public final class ParserListenerUtils { continue; } /* - * + * * It is safe not to check last argument to be same * grammars enforces that. - * + * * FIXME: Introduce proper escaping and translation of escaped * characters here. - * + * */ sb.append(quoteMatcher.removeFrom(str.substring(1, str.length()-1))); } @@ -378,7 +375,15 @@ public final class ParserListenerUtils { ParseTree child = ctx.getChild(i); if (child instanceof Value_stmtContext) { String valueStr = stringFromNode(child); - value = Integer.valueOf(valueStr); + try { + // yang enum value has same restrictions as JAVA Integer + value = Integer.valueOf(valueStr); + } catch (NumberFormatException e) { + String err = String + .format("Error on enum '%s': the enum value MUST be in the range from -2147483648 to 2147483647, but was: %s", + name, valueStr); + throw new YangParseException(moduleName, ctx.getStart().getLine(), err, e); + } } else if (child instanceof Description_stmtContext) { description = stringFromNode(child); } else if (child instanceof Reference_stmtContext) { @@ -391,10 +396,6 @@ public final class ParserListenerUtils { if (value == null) { value = highestValue + 1; } - if (value < -2147483648 || value > 2147483647) { - throw new YangParseException(moduleName, ctx.getStart().getLine(), "Error on enum '" + name - + "': the enum value MUST be in the range from -2147483648 to 2147483647, but was: " + value); - } EnumPairImpl result = new EnumPairImpl(); result.qname = path.getPathTowardsRoot().iterator().next(); -- 2.36.6