}
@SuppressWarnings("unchecked")
- public static <AT,DT extends DeclaredStatement<AT>> Collection<StmtContext<AT, DT, ?>> findAllDeclaredSubstatement(
+ public static <AT, DT extends DeclaredStatement<AT>> Collection<StmtContext<AT, DT, ?>> findAllDeclaredSubstatements(
final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType) {
ImmutableList.Builder<StmtContext<AT, DT, ?>> listBuilder = ImmutableList.builder();
for (StmtContext<?, ?, ?> subStmtContext : stmtContext.declaredSubstatements()) {
- if (producesDeclared(subStmtContext,declaredType)) {
+ if (producesDeclared(subStmtContext, declaredType)) {
listBuilder.add((StmtContext<AT, DT, ?>) subStmtContext);
}
}
return listBuilder.build();
}
+ @SuppressWarnings("unchecked")
+ public static <AT, DT extends DeclaredStatement<AT>> Collection<StmtContext<AT, DT, ?>> findAllEffectiveSubstatements(
+ final StmtContext<?, ?, ?> stmtContext, final Class<DT> type) {
+ ImmutableList.Builder<StmtContext<AT, DT, ?>> listBuilder = ImmutableList.builder();
+ for (StmtContext<?, ?, ?> subStmtContext : stmtContext.effectiveSubstatements()) {
+ if (producesDeclared(subStmtContext, type)) {
+ listBuilder.add((StmtContext<AT, DT, ?>) subStmtContext);
+ }
+ }
+ return listBuilder.build();
+ }
+
+ public static <AT, DT extends DeclaredStatement<AT>> Collection<StmtContext<AT, DT, ?>> findAllSubstatements(
+ final StmtContext<?, ?, ?> stmtContext, final Class<DT> type) {
+ ImmutableList.Builder<StmtContext<AT, DT, ?>> listBuilder = ImmutableList.builder();
+ listBuilder.addAll(findAllDeclaredSubstatements(stmtContext, type));
+ listBuilder.addAll(findAllEffectiveSubstatements(stmtContext, type));
+ return listBuilder.build();
+ }
+
@SuppressWarnings("unchecked")
public static <AT,DT extends DeclaredStatement<AT>> StmtContext<AT, ?, ?> findFirstEffectiveSubstatement(
final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType) {
import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public final class GroupingUtils {
+ private static final Logger LOG = LoggerFactory.getLogger(GroupingUtils.class);
+
private GroupingUtils() {
throw new UnsupportedOperationException();
}
StatementContextBase<?, ?, ?> refineTargetNodeCtx = Utils.findNode(usesParentCtx, refineTargetNodeIdentifier);
Preconditions.checkArgument(refineTargetNodeCtx != null, "Refine target node %s not found. At %s",
refineTargetNodeIdentifier, refineCtx.getStatementSourceReference());
+ if (StmtContextUtils.isUnknownStatement(refineTargetNodeCtx)) {
+ LOG.warn("Refine node '{}' in uses '{}' has target node unknown statement '{}'. Refine has been skipped. At line: {}",
+ refineCtx.getStatementArgument(), refineCtx.getParentContext().getStatementArgument(), refineTargetNodeCtx.getStatementArgument(),
+ refineCtx.getStatementSourceReference());
+ refineCtx.addAsEffectOfStatement(refineTargetNodeCtx);
+ return;
+ }
addOrReplaceNodes(refineCtx, refineTargetNodeCtx);
refineCtx.addAsEffectOfStatement(refineTargetNodeCtx);
final StatementContextBase<?, ?, ?> refineTargetNodeCtx) {
StatementDefinition refineSubstatementDef = refineSubstatementCtx.getPublicDefinition();
- StatementDefinition refineTargetNodeDef = refineTargetNodeCtx.getPublicDefinition();
SourceException.throwIf(!isSupportedRefineTarget(refineSubstatementCtx, refineTargetNodeCtx),
refineSubstatementCtx.getStatementSourceReference(),
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+import java.util.Collection;
import java.util.Iterator;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
+import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedNamespaceBehaviour;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
class SchemaNodeIdentifierBuildNamespace extends
DerivedNamespaceBehaviour<SchemaNodeIdentifier, StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>, QName, SchemaNodeIdentifierBuildNamespace, ChildSchemaNodes<?, ?>>
throw new UnsupportedOperationException("Direct access to namespace is not supported");
}
+ @SuppressWarnings("unchecked")
@Override
public StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>> getFrom(NamespaceStorageNode storage, SchemaNodeIdentifier key) {
return null;
}
}
- StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>> current = (StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>) lookupStartStorage.getFromLocalStorage(ChildSchemaNodes.class, iterator.next());
- while(current != null && iterator.hasNext()) {
- current = (StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>) current.getFromNamespace(ChildSchemaNodes.class, iterator.next());
+ QName nextPath = iterator.next();
+ StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>> current = (StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>) lookupStartStorage
+ .getFromLocalStorage(ChildSchemaNodes.class, nextPath);
+ if(current == null && lookupStartStorage instanceof StmtContext<?, ?, ?>) {
+ return tryToFindUnknownStatement(nextPath.getLocalName(), (Mutable<?, ?, EffectiveStatement<?, ?>>) lookupStartStorage);
+ }
+ while (current != null && iterator.hasNext()) {
+ nextPath = iterator.next();
+ StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>> nextNodeCtx = (StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>) current
+ .getFromNamespace(ChildSchemaNodes.class, nextPath);
+ if (nextNodeCtx == null) {
+ return tryToFindUnknownStatement(nextPath.getLocalName(), current);
+ } else {
+ current = nextNodeCtx;
+ }
}
return current;
}
+ @SuppressWarnings("unchecked")
+ private Mutable<?, ?, EffectiveStatement<?, ?>> tryToFindUnknownStatement(final String localName,
+ final Mutable<?, ?, EffectiveStatement<?, ?>> current) {
+ Collection<StmtContext<?, ?, ?>> unknownSubstatements = StmtContextUtils.findAllSubstatements(current,
+ UnknownStatement.class);
+ for (StmtContext<?, ?, ?> unknownSubstatement : unknownSubstatements) {
+ if(unknownSubstatement.rawStatementArgument().equals(localName)) {
+ return (Mutable<?, ?, EffectiveStatement<?, ?>>) unknownSubstatement;
+ }
+ }
+ return null;
+ }
+
@Override
public QName getSignificantKey(SchemaNodeIdentifier key) {
return key.getLastComponent();
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. 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.stmt.test;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+public class Bug5059 {
+ @Test
+ public void test() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
+ SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5059");
+ assertNotNull(context);
+ }
+}
--- /dev/null
+module foo {
+ namespace "foo";
+ prefix foo;
+
+ revision 2016-01-25 {
+ description "test";
+ }
+
+ grouping my-grouping {
+ container my-container {
+ foo:e2 "e2";
+ }
+ foo:e1 "e1";
+ }
+
+ container root {
+ uses my-grouping {
+ refine e1 {
+ description "new description for e1";
+ }
+ refine my-container/e2 {
+ description "new description for e2";
+ }
+ }
+ }
+
+ extension e1 {
+ argument name;
+ }
+ extension e2 {
+ argument name;
+ }
+}