Search in sources :

Example 1 with LocationPathSteps

use of org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps in project yangtools by opendaylight.

the class SchemaInferenceStackTest method findDataSchemaNodeTest2.

@Test
public void findDataSchemaNodeTest2() {
    final QName myLeafInGrouping2 = QName.create(myModule.getQNameModule(), "my-leaf-in-gouping2");
    final PathExpression expr = mock(PathExpression.class);
    doReturn(true).when(expr).isAbsolute();
    doReturn(new LocationPathSteps(YangLocationPath.relative(YangXPathAxis.CHILD.asStep(myLeafInGrouping2)))).when(expr).getSteps();
    final GroupingDefinition grouping = getGroupingByName(myModule, "my-grouping");
    final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
    assertSame(grouping, stack.enterGrouping(grouping.getQName()));
    assertEquals(grouping.getDataChildByName(myLeafInGrouping2), stack.resolvePathExpression(expr));
}
Also used : PathExpression(org.opendaylight.yangtools.yang.model.api.PathExpression) QName(org.opendaylight.yangtools.yang.common.QName) LocationPathSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps) GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition) Test(org.junit.Test)

Example 2 with LocationPathSteps

use of org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps in project yangtools by opendaylight.

the class PathExpressionParserTest method testCurrentPredicateParsing.

@Test
public void testCurrentPredicateParsing() {
    final YangLocationPath path = ((LocationPathSteps) parser.parseExpression(ctx, "/device_types/device_type[type = current()/../type_text]/desc").getSteps()).getLocationPath();
    assertTrue(path.isAbsolute());
    path.getSteps();
    assertEquals(ImmutableList.of(YangXPathAxis.CHILD.asStep(UnresolvedQName.unqualified("device_types")), YangXPathAxis.CHILD.asStep(UnresolvedQName.unqualified("device_type"), ImmutableSet.of(YangBinaryOperator.EQUALS.exprWith(YangQNameExpr.of(UnresolvedQName.unqualified("type")), YangPathExpr.of(YangFunctionCallExpr.of(YangFunction.CURRENT.getIdentifier()), Relative.relative(YangXPathAxis.PARENT.asStep(), YangXPathAxis.CHILD.asStep(UnresolvedQName.unqualified("type_text"))))))), YangXPathAxis.CHILD.asStep(UnresolvedQName.unqualified("desc"))), path.getSteps());
}
Also used : YangLocationPath(org.opendaylight.yangtools.yang.xpath.api.YangLocationPath) LocationPathSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps) Test(org.junit.Test)

Example 3 with LocationPathSteps

use of org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps in project yangtools by opendaylight.

the class SchemaInferenceStackTest method findDataSchemaNodeTest.

@Test
public void findDataSchemaNodeTest() {
    final Module importedModule = context.findModule(XMLNamespace.of("uri:imported-module"), Revision.of("2014-10-07")).get();
    final QName myImportedContainer = QName.create(importedModule.getQNameModule(), "my-imported-container");
    final QName myImportedLeaf = QName.create(importedModule.getQNameModule(), "my-imported-leaf");
    final SchemaNode testNode = ((ContainerSchemaNode) importedModule.getDataChildByName(myImportedContainer)).getDataChildByName(myImportedLeaf);
    final PathExpression expr = mock(PathExpression.class);
    doReturn(true).when(expr).isAbsolute();
    doReturn(new LocationPathSteps(YangLocationPath.absolute(YangXPathAxis.CHILD.asStep(myImportedContainer), YangXPathAxis.CHILD.asStep(myImportedLeaf)))).when(expr).getSteps();
    assertEquals(testNode, SchemaInferenceStack.of(context).resolvePathExpression(expr));
}
Also used : ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) PathExpression(org.opendaylight.yangtools.yang.model.api.PathExpression) QName(org.opendaylight.yangtools.yang.common.QName) LocationPathSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps) Module(org.opendaylight.yangtools.yang.model.api.Module) Test(org.junit.Test)

Example 4 with LocationPathSteps

use of org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps in project yangtools by opendaylight.

the class YT1060Test method before.

@Before
public void before() {
    context = YangParserTestUtils.parseYangResourceDirectory("/yt1060");
    final Module module = context.findModule(CONT.getModule()).get();
    final ContainerSchemaNode cont = (ContainerSchemaNode) module.findDataChildByName(CONT).get();
    final LeafSchemaNode leaf1 = (LeafSchemaNode) cont.findDataChildByName(LEAF1).get();
    path = ((LeafrefTypeDefinition) leaf1.getType()).getPathStatement();
    // Quick checks before we get to the point
    final Steps pathSteps = path.getSteps();
    assertThat(pathSteps, isA(LocationPathSteps.class));
    final YangLocationPath locationPath = ((LocationPathSteps) pathSteps).getLocationPath();
    assertTrue(locationPath.isAbsolute());
    final ImmutableList<Step> steps = locationPath.getSteps();
    assertEquals(2, steps.size());
    steps.forEach(step -> assertThat(step, isA(ResolvedQNameStep.class)));
}
Also used : Steps(org.opendaylight.yangtools.yang.model.api.PathExpression.Steps) LocationPathSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) LocationPathSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps) YangLocationPath(org.opendaylight.yangtools.yang.xpath.api.YangLocationPath) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) ResolvedQNameStep(org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.ResolvedQNameStep) Step(org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.Step) Module(org.opendaylight.yangtools.yang.model.api.Module) Before(org.junit.Before)

Example 5 with LocationPathSteps

use of org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps in project yangtools by opendaylight.

the class PathExpressionParser method parseExpression.

PathExpression parseExpression(final StmtContext<?, ?, ?> ctx, final String pathArg) {
    final LeafRefPathLexer lexer = new LeafRefPathLexer(CharStreams.fromString(pathArg));
    final LeafRefPathParser parser = new LeafRefPathParser(new CommonTokenStream(lexer));
    final Path_argContext path = SourceExceptionParser.parse(lexer, parser, parser::path_arg, ctx.sourceReference());
    final ParseTree childPath = path.getChild(0);
    final Steps steps;
    if (childPath instanceof Path_strContext) {
        steps = new LocationPathSteps(parsePathStr(ctx, pathArg, (Path_strContext) childPath));
    } else if (childPath instanceof Deref_exprContext) {
        final Deref_exprContext deref = (Deref_exprContext) childPath;
        steps = new DerefSteps(parseRelative(ctx, pathArg, getChild(deref, 0, Deref_function_invocationContext.class).getChild(Relative_pathContext.class, 0)), parseRelative(ctx, pathArg, getChild(deref, deref.getChildCount() - 1, Relative_pathContext.class)));
    } else {
        throw new IllegalStateException("Unsupported child " + childPath);
    }
    return new ParsedPathExpression(steps, pathArg);
}
Also used : LocationPathSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps) Steps(org.opendaylight.yangtools.yang.model.api.PathExpression.Steps) DerefSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.DerefSteps) Path_strContext(org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser.Path_strContext) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) LocationPathSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps) DerefSteps(org.opendaylight.yangtools.yang.model.api.PathExpression.DerefSteps) Deref_function_invocationContext(org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser.Deref_function_invocationContext) Path_argContext(org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser.Path_argContext) LeafRefPathLexer(org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathLexer) LeafRefPathParser(org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser) Deref_exprContext(org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser.Deref_exprContext) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

LocationPathSteps (org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps)5 Test (org.junit.Test)3 QName (org.opendaylight.yangtools.yang.common.QName)2 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)2 Module (org.opendaylight.yangtools.yang.model.api.Module)2 PathExpression (org.opendaylight.yangtools.yang.model.api.PathExpression)2 Steps (org.opendaylight.yangtools.yang.model.api.PathExpression.Steps)2 YangLocationPath (org.opendaylight.yangtools.yang.xpath.api.YangLocationPath)2 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1 Before (org.junit.Before)1 GroupingDefinition (org.opendaylight.yangtools.yang.model.api.GroupingDefinition)1 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)1 DerefSteps (org.opendaylight.yangtools.yang.model.api.PathExpression.DerefSteps)1 SchemaNode (org.opendaylight.yangtools.yang.model.api.SchemaNode)1 LeafRefPathLexer (org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathLexer)1 LeafRefPathParser (org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser)1 Deref_exprContext (org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser.Deref_exprContext)1 Deref_function_invocationContext (org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser.Deref_function_invocationContext)1 Path_argContext (org.opendaylight.yangtools.yang.parser.antlr.LeafRefPathParser.Path_argContext)1