// Original definition may live in a different module, make sure we account for that
final ModuleContext origContext = moduleContext(
orig.getPath().getPathFromRoot().iterator().next().getModule());
- input = origContext.getChildNode(orig.getInput().getPath()).build();
- output = origContext.getChildNode(orig.getOutput().getPath()).build();
+ input = context.addAliasType(origContext, orig.getInput(), action.getInput());
+ output = context.addAliasType(origContext, orig.getOutput(), action.getOutput());
} else {
input = actionContainer(context, RPC_INPUT, action.getInput(), inGrouping);
output = actionContainer(context, RPC_OUTPUT, action.getOutput(), inGrouping);
throw new IllegalArgumentException("augment target not found: " + targetPath);
}
- GeneratedTypeBuilder targetTypeBuilder = findChildNodeByPath(targetSchemaNode.getPath());
- if (targetTypeBuilder == null) {
- targetTypeBuilder = findCaseByPath(targetSchemaNode.getPath());
- }
- if (targetTypeBuilder == null) {
- throw new IllegalStateException("Target type not yet generated: " + targetSchemaNode);
+ if (targetSchemaNode instanceof ChoiceSchemaNode) {
+ final GeneratedTypeBuilder builder = findChildNodeByPath(targetSchemaNode.getPath());
+ checkState(builder != null, "Choice target type not generated for %s", targetSchemaNode);
+ generateTypesFromAugmentedChoiceCases(context, builder.build(), (ChoiceSchemaNode) targetSchemaNode,
+ augSchema.getChildNodes(), null, false);
+ return;
}
- if (!(targetSchemaNode instanceof ChoiceSchemaNode)) {
- final Type targetType = new ReferencedTypeImpl(targetTypeBuilder.getIdentifier());
- addRawAugmentGenTypeDefinition(context, targetType, augSchema, false);
-
+ final JavaTypeName targetName;
+ if (targetSchemaNode instanceof CaseSchemaNode) {
+ final GeneratedTypeBuilder builder = findCaseByPath(targetSchemaNode.getPath());
+ checkState(builder != null, "Case target type not generated for %s", targetSchemaNode);
+ targetName = builder.getIdentifier();
} else {
- generateTypesFromAugmentedChoiceCases(context, targetTypeBuilder.build(),
- (ChoiceSchemaNode) targetSchemaNode, augSchema.getChildNodes(), null, false);
+ final GeneratedTypeBuilder builder = findChildNodeByPath(targetSchemaNode.getPath());
+ if (builder == null) {
+ targetName = findAliasByPath(targetSchemaNode.getPath());
+ checkState(targetName != null, "Target type not yet generated: %s", targetSchemaNode);
+ } else {
+ targetName = builder.getIdentifier();
+ }
}
+
+ addRawAugmentGenTypeDefinition(context, new ReferencedTypeImpl(targetName), augSchema, false);
}
private void usesAugmentationToGenTypes(final ModuleContext context, final AugmentationSchemaNode augSchema,
return builder;
}
+ private JavaTypeName findAliasByPath(final SchemaPath path) {
+ for (final ModuleContext ctx : genCtx.values()) {
+ final JavaTypeName result = ctx.getAlias(path);
+ if (result != null) {
+ return result;
+ }
+ }
+ return null;
+ }
+
private GeneratedTypeBuilder findChildNodeByPath(final SchemaPath path) {
for (final ModuleContext ctx : genCtx.values()) {
final GeneratedTypeBuilder result = ctx.getChildNode(path);
*/
package org.opendaylight.mdsal.binding.generator.impl;
+import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.BiMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
import org.opendaylight.mdsal.binding.model.api.Type;
import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTOBuilder;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
private final List<GeneratedTypeBuilder> augmentations = new ArrayList<>();
private final Multimap<Type, Type> choiceToCases = HashMultimap.create();
private final Set<GeneratedTypeBuilder> topLevelNodes = new HashSet<>();
+ private final Map<SchemaPath, JavaTypeName> aliases = new HashMap<>();
private final Map<Type, WithStatus> typeToSchema = new HashMap<>();
private final List<GeneratedTOBuilder> genTOs = new ArrayList<>();
private final Map<SchemaPath, Type> innerTypes = new HashMap<>();
genTOs.add(builder);
}
+ @NonNull GeneratedType addAliasType(final ModuleContext sourceContext, final ContainerSchemaNode source,
+ final ContainerSchemaNode alias) {
+ final GeneratedTypeBuilder builder = sourceContext.getChildNode(source.getPath());
+ checkState(builder != null, "Could not find builder for %s", source);
+
+ final JavaTypeName id = builder.getIdentifier();
+ final SchemaPath path = alias.getPath();
+ final JavaTypeName prev = aliases.putIfAbsent(path, id);
+ checkState(prev == null, "Type aliasing conflict on %s: %s vs %s", path, prev, id);
+
+ return builder.build();
+ }
+
+ @Nullable JavaTypeName getAlias(final SchemaPath path) {
+ return aliases.get(path);
+ }
+
public void addChildNodeType(final SchemaNode def, final GeneratedTypeBuilder builder) {
checkNamingConflict(def, builder.getIdentifier());
childNodes.put(def.getPath(), builder);
--- /dev/null
+/*
+ * Copyright (c) 2020 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.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public class Mdsal517Test extends AbstractOpaqueTest {
+ @Test
+ public void generateAnydataTest() {
+ final List<Type> types = new BindingGeneratorImpl().generateTypes(
+ YangParserTestUtils.parseYangResourceDirectory("/mdsal-517"));
+ assertNotNull(types);
+ assertEquals(7, types.size());
+ }
+}
--- /dev/null
+module bar {
+ yang-version 1.1;
+ namespace "bar";
+ prefix bar;
+
+ import foo {
+ prefix foo;
+ }
+
+ augment "/foo:foo-cont/foo:foo-act/foo:input" {
+ description
+ "An augmentation of a action input of module a";
+ leaf b-aug-leaf {
+ type empty;
+ }
+ }
+}
--- /dev/null
+module foo {
+ yang-version 1.1;
+ namespace "foo";
+ prefix foo;
+
+ grouping foo-grp {
+ action foo-act {
+ input {
+ leaf foo-action-input-leaf {
+ type empty;
+ }
+ }
+ }
+ }
+
+ container foo-cont {
+ uses foo:foo-grp;
+ }
+}