Skip to content

Commit

Permalink
Fix runtime type search
Browse files Browse the repository at this point in the history
When searching for children, we should be cognizant of the fact that we
might be looking at an inherited contract -- such as 'output' of an
'action' inherited through 'uses'. Extend the runtime search algorithm
to also look at previous() axis.

JIRA: MDSAL-824
Change-Id: Ic2f57b266825c6121f7bd6156a86112abff4b67a
Signed-off-by: Robert Varga <[email protected]>
  • Loading branch information
rovarga committed May 2, 2023
1 parent 1c22875 commit 53450b0
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,16 @@ private void processGenerator(final AugmentResolver resolver, final AbstractComp
}
}

// ... and groupings recursively last
// ... groupings recursively next ...
for (var grouping : parent.groupings()) {
final AbstractExplicitGenerator<S, ?> found = findChildGenerator(grouping, localName);
if (found != null) {
return found;
}
}

return null;
// ... and finally anything along instantiation axis ...
final var origParent = (AbstractCompositeGenerator<?, ?>) parent.previous();
return origParent == null ? null : findChildGenerator(origParent, localName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2023 PANTHEON.tech, s.r.o. 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.mdsal.binding.generator.impl;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;

import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
import org.opendaylight.mdsal.binding.runtime.api.ActionRuntimeType;
import org.opendaylight.mdsal.binding.runtime.api.ContainerRuntimeType;
import org.opendaylight.mdsal.binding.runtime.api.InputRuntimeType;
import org.opendaylight.mdsal.binding.runtime.api.ListRuntimeType;
import org.opendaylight.mdsal.binding.runtime.api.OutputRuntimeType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;

public class Mdsal824Test {
private static EffectiveModelContext CONTEXT;

@BeforeClass
public static void beforeClass() {
CONTEXT = YangParserTestUtils.parseYangResourceDirectory("/mdsal824");
}

@Test
public void testCompileTimeTypes() {
assertEquals(13, DefaultBindingGenerator.generateFor(CONTEXT).size());
}

@Test
public void testRunTimeTypes() {
final var types = BindingRuntimeTypesFactory.createTypes(CONTEXT);
final var barTop = types.schemaTreeChild(QName.create("bar", "bar-top"));
assertThat(barTop, instanceOf(ContainerRuntimeType.class));
final var barList = ((ContainerRuntimeType) barTop).schemaTreeChild(QName.create("bar", "bar-list"));
assertThat(barList, instanceOf(ListRuntimeType.class));
final var barAction = ((ListRuntimeType) barList).schemaTreeChild(QName.create("bar", "foo"));
assertThat(barAction, instanceOf(ActionRuntimeType.class));

final var barInput = ((ActionRuntimeType) barAction).schemaTreeChild(QName.create("bar", "input"));
assertThat(barInput, instanceOf(InputRuntimeType.class));
assertEquals(JavaTypeName.create("org.opendaylight.yang.gen.v1.foo.norev.act.grp", "FooInput"),
barInput.javaType().getIdentifier());

final var barOutput = ((ActionRuntimeType) barAction).schemaTreeChild(QName.create("bar", "output"));
assertThat(barOutput, instanceOf(OutputRuntimeType.class));
assertEquals(JavaTypeName.create("org.opendaylight.yang.gen.v1.foo.norev.act.grp", "FooOutput"),
barOutput.javaType().getIdentifier());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module bar {
yang-version 1.1;
namespace bar;
prefix bar;

import foo { prefix foo; }

grouping bar-grp {
list bar-list {
key key;
leaf key {
type string;
}

uses foo:uses-grp;
}
}

container bar-top {
uses bar-grp;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module foo {
yang-version 1.1;
namespace foo;
prefix foo;

grouping act-grp {
action foo {
output {
choice type {
mandatory true;
case some-type {
leaf some-type {
type string;
}
}
}
}
}
}

grouping uses-grp {
uses act-grp;
}
}

0 comments on commit 53450b0

Please sign in to comment.