import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableBiMap;
-import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Relative;
import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
private static final Pattern PATH_ABS = Pattern.compile("/[^/].*");
@RegEx
private static final String YANG_XPATH_FUNCTIONS_STRING =
- "(re-match|deref|derived-from(-or-self)?|enum-value|bit-is-set)(\\()";
+ "(re-match|deref|derived-from(-or-self)?|enum-value|bit-is-set)([ \t\r\n]*)(\\()";
private static final Pattern YANG_XPATH_FUNCTIONS_PATTERN = Pattern.compile(YANG_XPATH_FUNCTIONS_STRING);
+ private static final Pattern ESCAPED_DQUOT = Pattern.compile("\\\"", Pattern.LITERAL);
+ private static final Pattern ESCAPED_BACKSLASH = Pattern.compile("\\\\", Pattern.LITERAL);
+ private static final Pattern ESCAPED_LF = Pattern.compile("\\n", Pattern.LITERAL);
+ private static final Pattern ESCAPED_TAB = Pattern.compile("\\t", Pattern.LITERAL);
private static final ThreadLocal<XPathFactory> XPATH_FACTORY = new ThreadLocal<XPathFactory>() {
@Override
}
final Set<SchemaNodeIdentifier.Relative> keyNodes = new HashSet<>();
-
for (final String keyToken : keyTokens) {
-
- final SchemaNodeIdentifier.Relative keyNode = (Relative) SchemaNodeIdentifier.Relative.create(false,
- StmtContextUtils.qnameFromArgument(ctx, keyToken));
- keyNodes.add(keyNode);
+ keyNodes.add(SchemaNodeIdentifier.SAME.createChild(StmtContextUtils.qnameFromArgument(ctx, keyToken)));
}
return keyNodes;
}
- static Collection<SchemaNodeIdentifier.Relative> parseUniqueConstraintArgument(final StmtContext<?, ?, ?> ctx,
- final String argumentValue) {
- final Set<SchemaNodeIdentifier.Relative> uniqueConstraintNodes = new HashSet<>();
- for (final String uniqueArgToken : SPACE_SPLITTER.split(argumentValue)) {
- final SchemaNodeIdentifier nodeIdentifier = Utils.nodeIdentifierFromPath(ctx, uniqueArgToken);
- SourceException.throwIf(nodeIdentifier.isAbsolute(), ctx.getStatementSourceReference(),
- "Unique statement argument '%s' contains schema node identifier '%s' "
- + "which is not in the descendant node identifier form.", argumentValue, uniqueArgToken);
- uniqueConstraintNodes.add((SchemaNodeIdentifier.Relative) nodeIdentifier);
- }
- return ImmutableSet.copyOf(uniqueConstraintNodes);
- }
-
private static String trimSingleLastSlashFromXPath(final String path) {
return path.endsWith("/") ? path.substring(0, path.length() - 1) : path;
}
- static RevisionAwareXPath parseXPath(final StmtContext<?, ?, ?> ctx, final String path) {
+ public static RevisionAwareXPath parseXPath(final StmtContext<?, ?, ?> ctx, final String path) {
final XPath xPath = XPATH_FACTORY.get().newXPath();
xPath.setNamespaceContext(StmtNamespaceContext.create(ctx,
ImmutableBiMap.of(RFC6020_YANG_NAMESPACE.toString(), YANG_XPATH_FUNCTIONS_PREFIX)));
return identifier;
}
- static SchemaNodeIdentifier nodeIdentifierFromPath(final StmtContext<?, ?, ?> ctx, final String path) {
+ @SuppressWarnings("checkstyle:illegalCatch")
+ public static SchemaNodeIdentifier nodeIdentifierFromPath(final StmtContext<?, ?, ?> ctx, final String path) {
// FIXME: is the path trimming really necessary??
final List<QName> qNames = new ArrayList<>();
for (final String nodeName : SLASH_SPLITTER.split(trimSingleLastSlashFromXPath(path))) {
* in the inner string and trim the result.
*/
checkDoubleQuotedString(innerStr, yangVersion, ref);
- sb.append(innerStr.replace("\\\"", "\"").replace("\\\\", "\\").replace("\\n", "\n")
- .replace("\\t", "\t"));
+ sb.append(ESCAPED_TAB.matcher(
+ ESCAPED_LF.matcher(
+ ESCAPED_BACKSLASH.matcher(
+ ESCAPED_DQUOT.matcher(innerStr).replaceAll("\\\""))
+ .replaceAll("\\\\"))
+ .replaceAll("\\\n"))
+ .replaceAll("\\\t"));
} else if (firstChar == '\'' && lastChar == '\'') {
/*
* According to RFC6020 a single quote character cannot occur in
node);
}
- static @Nonnull Boolean parseBoolean(final StmtContext<?, ?, ?> ctx, final String input) {
+ public static @Nonnull Boolean parseBoolean(final StmtContext<?, ?, ?> ctx, final String input) {
if ("true".equals(input)) {
return Boolean.TRUE;
} else if ("false".equals(input)) {
}
}
- static String internBoolean(final String input) {
+ public static String internBoolean(final String input) {
if ("true".equals(input)) {
return "true";
} else if ("false".equals(input)) {