import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
-
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL");
Preconditions.checkArgument(schemaPath != null, "Schema Path reference cannot be NULL");
- final List<QName> prefixedPath = (schemaPath.getPath());
+ final Iterable<QName> prefixedPath = schemaPath.getPathFromRoot();
if (prefixedPath == null) {
LOG.debug("Schema path {} has null path", schemaPath);
return null;
return findNodeInModule(module, path);
}
- public static GroupingDefinition findGrouping(final SchemaContext context, final Module module, final List<QName> path) {
- QName first = path.get(0);
+ public static GroupingDefinition findGrouping(final SchemaContext context, final Module module, final Iterable<QName> path) {
+ Iterator<QName> iterator = path.iterator();
+ QName first = iterator.next();
Module m = context.findModuleByNamespace(first.getNamespace()).iterator().next();
DataNodeContainer currentParent = m;
for (QName qname : path) {
}
private static DataSchemaNode findCorrectTargetFromGrouping(final DataSchemaNode node, final SchemaContext ctx) {
- if (node.getPath().getPath().size() != 1) {
+ if (Iterables.size(node.getPath().getPathTowardsRoot()) != 1) {
QName currentName = node.getQName();
// tmpPath is used to track level of nesting
List<QName> tmpPath = new ArrayList<>();
}
private static DataSchemaNode getResultFromUses(final UsesNode u, final String currentName, final SchemaContext ctx) {
- SchemaNode targetGrouping = findNodeInSchemaContext(ctx, u.getGroupingPath().getPathFromRoot());
-
+ SchemaNode targetGrouping = SchemaContextUtil.findNodeInSchemaContext(ctx, u.getGroupingPath()
+ .getPathFromRoot());
+ if (!(targetGrouping instanceof GroupingDefinition)) {
+ targetGrouping = findGrouping(ctx, getParentModule(targetGrouping, ctx), u.getGroupingPath()
+ .getPathFromRoot());
+ }
Preconditions.checkArgument(targetGrouping instanceof GroupingDefinition,
"Failed to generate code for augment in %s", u);
GroupingDefinition gr = (GroupingDefinition) targetGrouping;
++colCount;
}
- final ImmutableList<QName> relative = ImmutableList.copyOf(
+ final Iterable<QName> parent = leafrefParentNode.getPath().getPathFromRoot();
+ return Iterables.concat(Iterables.limit(parent, Iterables.size(parent) - colCount),
Iterables.transform(Iterables.skip(xpaths, colCount), new Function<String, QName>() {
@Override
public QName apply(final String input) {
return stringPathPartToQName(context, module, input);
}
}));
- final Iterable<QName> parent = leafrefParentNode.getPath().getPathFromRoot();
- return Iterables.concat(Iterables.limit(parent, Iterables.size(parent) - colCount), relative);
}
}