From 906fae19c653e8872ecbaea33f152a13a0a8bf9e Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 3 Sep 2013 15:05:38 -0700 Subject: [PATCH] Fixed resolution problems in Code Generator Added sorting of modules by dependencies for code generator Fixed search for parent modules Change-Id: I9017e03937050487476eed73dafc72376b8bc4e5 Signed-off-by: Tony Tkacik --- .../generator/impl/BindingGeneratorImpl.xtend | 55 ++++--------- .../binding/yang/types/TypeProviderImpl.java | 2 +- .../impl/BitAndUnionTOEnclosingTest.java | 16 ++-- .../impl/ChoiceCaseGenTypesTest.java | 4 +- .../generator/impl/GenEnumResolvingTest.java | 6 +- .../sal/binding/generator/impl/UsesTest.java | 50 +++++------ .../generator/util/BindingGeneratorUtil.java | 12 +-- .../yang/model/api/SchemaContext.java | 4 +- .../yang/model/util/SchemaContextUtil.xtend | 82 ++++++++++--------- .../yang/parser/impl/SchemaContextImpl.java | 17 +++- .../impl/YangParserWithContextTest.java | 2 +- 11 files changed, 123 insertions(+), 127 deletions(-) diff --git a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend index 5b3bbb28e2..0e9e944eec 100644 --- a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend +++ b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend @@ -62,7 +62,7 @@ import static extension org.opendaylight.yangtools.binding.generator.util.Types. import static org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil.*; import static org.opendaylight.yangtools.binding.generator.util.BindingTypes.*; import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.*; - +import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort public class BindingGeneratorImpl implements BindingGenerator { @@ -134,27 +134,7 @@ public class BindingGeneratorImpl implements BindingGenerator { schemaContext = context; typeProvider = new TypeProviderImpl(context); val Set modules = context.modules; - genTypeBuilders = new HashMap(); - for (module : modules) { - - generatedTypes.addAll(allGroupingsToGenTypes(module)); - - if (false == module.childNodes.isEmpty()) { - generatedTypes.add(moduleToDataType(module)); - } - generatedTypes.addAll(allTypeDefinitionsToGenTypes(module)); - generatedTypes.addAll(allContainersToGenTypes(module)); - generatedTypes.addAll(allListsToGenTypes(module)); - generatedTypes.addAll(allChoicesToGenTypes(module)); - generatedTypes.addAll(allRPCMethodsToGenType(module)); - generatedTypes.addAll(allNotificationsToGenType(module)); - generatedTypes.addAll(allIdentitiesToGenTypes(module, context)); - } - for (module : modules) { - generatedTypes.addAll(allAugmentsToGenTypes(module)); - - } - return generatedTypes; + return generateTypes(context,modules); } /** @@ -190,20 +170,20 @@ public class BindingGeneratorImpl implements BindingGenerator { checkState(context.modules !== null,"Schema Context does not contain defined modules."); checkArgument(modules !== null,"Set of Modules cannot be NULL."); - val List filteredGenTypes = new ArrayList(); + val List filteredGenTypes = new ArrayList(); + schemaContext = context; typeProvider = new TypeProviderImpl(context); - val Set contextModules = context.modules; + val contextModules = ModuleDependencySort.sort(context.modules); genTypeBuilders = new HashMap(); for (contextModule : contextModules) { val List generatedTypes = new ArrayList(); - + generatedTypes.addAll(allTypeDefinitionsToGenTypes(contextModule)); generatedTypes.addAll(allGroupingsToGenTypes(contextModule)); if (false == contextModule.childNodes.isEmpty()) { generatedTypes.add(moduleToDataType(contextModule)); } - generatedTypes.addAll(allTypeDefinitionsToGenTypes(contextModule)); generatedTypes.addAll(allContainersToGenTypes(contextModule)); generatedTypes.addAll(allListsToGenTypes(contextModule)); generatedTypes.addAll(allChoicesToGenTypes(contextModule)); @@ -246,7 +226,6 @@ public class BindingGeneratorImpl implements BindingGenerator { checkArgument(module.name !== null,"Module name cannot be NULL."); val Set> typeDefinitions = module.typeDefinitions; checkState(typeDefinitions !== null,'''Type Definitions for module «module.name» cannot be NULL.'''); - val List generatedTypes = new ArrayList(); for ( TypeDefinition typedef : typeDefinitions) { @@ -881,18 +860,18 @@ public class BindingGeneratorImpl implements BindingGenerator { // and DataObject interface!!! val targetPath = augSchema.targetPath; val targetSchemaNode = findDataSchemaNode(schemaContext, targetPath); - var targetType = yangToJavaMapping.get(targetSchemaNode.path); - if(targetType == null) { - // FIXME: augmentation should be added as last, all types should already be generated - // and have assigned Java Types, - val targetModule = findParentModule(schemaContext, targetSchemaNode); - val targetBasePackage = moduleNamespaceToPackageName(targetModule); - val typePackage = packageNameForGeneratedType(targetBasePackage, targetSchemaNode.getPath()); - val targetSchemaNodeName = targetSchemaNode.getQName().getLocalName(); - val typeName = parseToClassName(targetSchemaNodeName); - targetType = new ReferencedTypeImpl(typePackage,typeName); - } if (targetSchemaNode !== null) { + var targetType = yangToJavaMapping.get(targetSchemaNode.path); + if(targetType == null) { + // FIXME: augmentation should be added as last, all types should already be generated + // and have assigned Java Types, + val targetModule = findParentModule(schemaContext, targetSchemaNode); + val targetBasePackage = moduleNamespaceToPackageName(targetModule); + val typePackage = packageNameForGeneratedType(targetBasePackage, targetSchemaNode.getPath()); + val targetSchemaNodeName = targetSchemaNode.getQName().getLocalName(); + val typeName = parseToClassName(targetSchemaNodeName); + targetType = new ReferencedTypeImpl(typePackage,typeName); + } val augChildNodes = augSchema.childNodes; if (!(targetSchemaNode instanceof ChoiceNode)) { val augTypeBuilder = addRawAugmentGenTypeDefinition(augmentPackageName, diff --git a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java index 50b637b538..8bd0c51e64 100644 --- a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java +++ b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java @@ -255,7 +255,7 @@ public final class TypeProviderImpl implements TypeProvider { */ private Type provideTypeForIdentityref(IdentityrefTypeDefinition idref) { QName baseIdQName = idref.getIdentity(); - Module module = schemaContext.findModuleByNamespace(baseIdQName.getNamespace()); + Module module = schemaContext.findModuleByNamespaceAndRevision(baseIdQName.getNamespace(),baseIdQName.getRevision()); IdentitySchemaNode identity = null; for (IdentitySchemaNode id : module.getIdentities()) { if (id.getQName().equals(baseIdQName)) { diff --git a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BitAndUnionTOEnclosingTest.java b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BitAndUnionTOEnclosingTest.java index c815934efd..83eb4155c9 100644 --- a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BitAndUnionTOEnclosingTest.java +++ b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BitAndUnionTOEnclosingTest.java @@ -90,7 +90,7 @@ public class BitAndUnionTOEnclosingTest { assertNotNull("Lf TO wasn't found.", lfLeaf); assertEquals("Lf TO has incorrect number of occurences.", 1, lfLeafCounter); assertEquals("Lf has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer", + "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer", lfLeaf.getPackageName()); assertEquals("Lf generated TO has incorrect number of properties", 2, lfLeaf.getProperties().size()); @@ -101,7 +101,7 @@ public class BitAndUnionTOEnclosingTest { assertNotNull("Lf1 TO wasn't found.", lf1Leaf); assertEquals("Lf1 TO has incorrect number of occurences.", 1, lf1LeafCounter); assertEquals("Lf1 has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer", + "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer", lf1Leaf.getPackageName()); assertEquals("Lf generated TO has incorrect number of properties", 4, lf1Leaf.getProperties().size()); @@ -114,7 +114,7 @@ public class BitAndUnionTOEnclosingTest { assertNotNull("Lf2 TO wasn't found.", lf2Leaf); assertEquals("Lf2 TO has incorrect number of occurences.", 1, lf2LeafCounter); assertEquals("Lf2 has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer", + "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer", lf2Leaf.getPackageName()); assertEquals("Lf generated TO has incorrect number of properties", 2, lf2Leaf.getProperties().size()); @@ -144,7 +144,7 @@ public class BitAndUnionTOEnclosingTest { assertNotNull("TypeUnion TO wasn't found.", typeUnionTypedef); assertEquals("TypeUnion TO has incorrect number of occurences.", 1, typeUnionTypedefCounter); assertEquals("TypeUnion has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626", typeUnionTypedef.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626", typeUnionTypedef.getPackageName()); assertEquals("TypeUnion generated TO has incorrect number of properties", 2, typeUnionTypedef.getProperties() .size()); @@ -174,7 +174,7 @@ public class BitAndUnionTOEnclosingTest { assertEquals("TypeUnion1 TO has incorrect number of occurences.", 1, typeUnion1Counter); assertEquals("TypeUnion1 has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626", typeUnion1.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626", typeUnion1.getPackageName()); assertEquals("TypeUnion1 generated TO has incorrect number of properties", 4, typeUnion1.getProperties().size()); @@ -187,7 +187,7 @@ public class BitAndUnionTOEnclosingTest { assertEquals("TypeUnion2 TO has incorrect number of occurences.", 1, typeUnion2Counter); assertEquals("TypeUnion2 has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626", typeUnion2.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626", typeUnion2.getPackageName()); assertEquals("TypeUnion2 generated TO has incorrect number of properties", 2, typeUnion2.getProperties().size()); containsAttributes(typeUnion2, true, true, true, new NameTypePattern("string", "String")); @@ -218,10 +218,10 @@ public class BitAndUnionTOEnclosingTest { assertNotNull("UnionLeaf TO wasn't found.", unionLeaf); assertEquals("BitLeaf has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer", + "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer", bitLeaf.getPackageName()); assertEquals("UnionLeaf has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer", + "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer", bitLeaf.getPackageName()); List propertiesBitLeaf = bitLeaf.getProperties(); diff --git a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ChoiceCaseGenTypesTest.java b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ChoiceCaseGenTypesTest.java index 28d818f89e..3068f46fe6 100644 --- a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ChoiceCaseGenTypesTest.java +++ b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ChoiceCaseGenTypesTest.java @@ -80,7 +80,7 @@ public class ChoiceCaseGenTypesTest { assertFalse("genTypes is empty", genTypes.isEmpty()); // test for file choice-monitoring - String pcgPref = "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.choice.monitoring.rev201371.netconf.state.datastores.datastore.locks"; + String pcgPref = "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.choice.monitoring.rev130701.netconf.state.datastores.datastore.locks"; GeneratedType genType = null; checkGeneratedType(genTypes, "LockType", pcgPref); // choice @@ -126,7 +126,7 @@ public class ChoiceCaseGenTypesTest { // test for file augment-monitoring // augment // "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type" - pcgPref = "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.augment.monitoring.rev201371"; + pcgPref = "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.augment.monitoring.rev130701"; genType = null; genType = checkGeneratedType(genTypes, "AutonomousLock", pcgPref diff --git a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenEnumResolvingTest.java b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenEnumResolvingTest.java index e9ed3a982f..b4e0b0484d 100644 --- a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenEnumResolvingTest.java +++ b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenEnumResolvingTest.java @@ -169,7 +169,7 @@ public class GenEnumResolvingTest { GeneratedType genInterface = null; for (final Type type : genTypes) { if (type instanceof GeneratedType) { - if (type.getPackageName().equals("org.opendaylight.yang.gen.v1.urn.model._abstract.topology.rev201328.topology.interfaces") + if (type.getPackageName().equals("org.opendaylight.yang.gen.v1.urn.model._abstract.topology.rev130208.topology.interfaces") && type.getName().equals("Interface")) { genInterface = (GeneratedType) type; } @@ -198,13 +198,13 @@ public class GenEnumResolvingTest { assertTrue("Expected LinkUpDownTrapEnable of type ReferencedTypeImpl", linkUpDownTrapEnable instanceof ReferencedTypeImpl); assertEquals(linkUpDownTrapEnable.getPackageName(), - "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev20121115.interfaces.Interface"); + "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev121115.interfaces.Interface"); assertNotNull("Expected Referenced Enum OperStatus, but was NULL!", operStatus); assertTrue("Expected OperStatus of type ReferencedTypeImpl", operStatus instanceof ReferencedTypeImpl); assertEquals(operStatus.getPackageName(), - "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev20121115.interfaces.Interface"); + "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev121115.interfaces.Interface"); } } diff --git a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/UsesTest.java b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/UsesTest.java index 0c57435d3e..ca67d8054b 100644 --- a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/UsesTest.java +++ b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/UsesTest.java @@ -71,17 +71,17 @@ public class UsesTest { assertNotNull("Generated type for grouping-U wasn't generated.", groupingU); assertEquals("GroupingU interface generated more than one time.", 1, groupingUCounter); assertEquals("GroupingU is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev2013718", groupingU.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev130718", groupingU.getPackageName()); assertNotNull("Generated type for grouping-V wasn't generated.", groupingV); assertEquals("GroupingV interface generated more than one time.", 1, groupingVCounter); assertEquals("GroupingV is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev2013718", groupingV.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev130718", groupingV.getPackageName()); assertNotNull("Generated type for grouping-X wasn't generated.", groupingX); assertEquals("GroupingX interface generated more than one time.", 1, groupingXCounter); assertEquals("GroupingX is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev2013718", groupingX.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev130718", groupingX.getPackageName()); containsInterface("GroupingV", groupingU); containsInterface("GroupingX", groupingU); @@ -122,13 +122,13 @@ public class UsesTest { assertEquals("Case C interface generated more than one time.", 1, caseCCounter); assertEquals( "Case C is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.uses._case.rev2013718.container.with.choicetest.choice.test", + "org.opendaylight.yang.gen.v1.urn.grouping.uses._case.rev130718.container.with.choicetest.choice.test", caseC.getPackageName()); assertNotNull("Generated type for grouping-case-test wasn't generated.", groupingCaseTest); assertEquals("GroupingCaseTest interface generated more than one time.", 1, groupingCaseTestCounter); assertEquals("GroupingCaseTest is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.uses._case.rev2013718", groupingCaseTest.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.grouping.uses._case.rev130718", groupingCaseTest.getPackageName()); containsInterface("GroupingCaseTest", caseC); assertTrue("Case C shouldn't contain any method.", caseC.getMethodDefinitions().isEmpty()); @@ -172,13 +172,13 @@ public class UsesTest { assertEquals("GroupingContainerTest interface - incorrect number of occurences", 1, groupingContainerTestCounter); assertEquals("GroupingContainerTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.container.rev2013718", + "org.opendaylight.yang.gen.v1.urn.grouping.uses.container.rev130718", groupingContainerTest.getPackageName()); assertNotNull("Generated type for container-test wasn't generated", containerTest); assertEquals("ContainerTest interface - incorrect number of occurences", 1, containerTestCount); assertEquals("ContainerTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.container.rev2013718", containerTest.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.grouping.uses.container.rev130718", containerTest.getPackageName()); containsInterface("GroupingContainerTest", containerTest); @@ -225,13 +225,13 @@ public class UsesTest { assertNotNull("Generated type for grouping-grouping-test wasn't generated", groupingGroupingTest); assertEquals("GroupingGroupingTest interface - incorrect number of occurences", 1, groupingGroupingTestCounter); assertEquals("GroupingGroupingTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.grouping.rev2013718", + "org.opendaylight.yang.gen.v1.urn.grouping.uses.grouping.rev130718", groupingGroupingTest.getPackageName()); assertNotNull("Generated type for grouping-test wasn't generated", groupingTest); assertEquals("GroupingTest interface - incorrect number of occurences", 1, groupingTestCount); assertEquals("GroupingTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.grouping.rev2013718", groupingTest.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.grouping.uses.grouping.rev130718", groupingTest.getPackageName()); containsInterface("GroupingGroupingTest", groupingTest); @@ -287,24 +287,24 @@ public class UsesTest { assertNotNull("Generated type for grouping-list-test wasn't generated", groupingListTest); assertEquals("GroupingListTest interface - incorrect number of occurences", 1, groupingListTestCounter); assertEquals("GroupingListTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev2013718", groupingListTest.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev130718", groupingListTest.getPackageName()); assertNotNull("Generated type for list-test wasn't generated", listTest); assertEquals("ListTest interface - incorrect number of occurences", 1, listTestCounter); assertEquals("ListTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev2013718", listTest.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev130718", listTest.getPackageName()); assertNotNull("Generated type for container-grouping-list-test wasn't generated", containerGroupingListTest); assertEquals("ContainerGroupingListTest interface - incorrect number of occurences", 1, containerGroupingListTestCounter); assertEquals("ContainerGroupingListTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev2013718.grouping.list.test", + "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev130718.grouping.list.test", containerGroupingListTest.getPackageName()); assertNotNull("Generated type for list-grouping-list-test wasn't generated", listGroupingListTest); assertEquals("ListGroupingListTest interface - incorrect number of occurences", 1, listGroupingListTestCounter); assertEquals("ListGroupingListTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev2013718.grouping.list.test", + "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev130718.grouping.list.test", listGroupingListTest.getPackageName()); containsInterface("GroupingListTest", listTest); @@ -360,13 +360,13 @@ public class UsesTest { assertNotNull("Generated type for grouping-list-test wasn't generated", groupingModulTest); assertEquals("GroupingModulTest interface - incorrect number of occurences", 1, groupingModulTestCounter); assertEquals("GroupingModulTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.modul.rev2013718", groupingModulTest.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.grouping.uses.modul.rev130718", groupingModulTest.getPackageName()); assertNotNull("Generated type for modul wasn't generated", groupingUsesModulData); assertEquals("GroupingUsesModulData interface - incorrect number of occurences", 1, groupingUsesModulDataCounter); assertEquals("GroupingUsesModulData isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.modul.rev2013718", + "org.opendaylight.yang.gen.v1.urn.grouping.uses.modul.rev130718", groupingUsesModulData.getPackageName()); containsInterface("GroupingModulTest", groupingUsesModulData); @@ -428,29 +428,29 @@ public class UsesTest { assertNotNull("Generated type for RPC test input wasn't generated", rpcTestInput); assertEquals("RpcTestInput interface - incorrect number of occurences", 1, rpcTestInputCounter); assertEquals("RpcTestInput isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev2013718", rpcTestInput.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev130718", rpcTestInput.getPackageName()); assertNotNull("Generated type for RPC test output wasn't generated", rpcTestOutput); assertEquals("RpcTestOutput interface - incorrect number of occurences", 1, rpcTestOutputCounter); assertEquals("RpcTestOutput isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev2013718", rpcTestOutput.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev130718", rpcTestOutput.getPackageName()); assertNotNull("Generated type for grouping-rpc-input-test wasn't generated", groupingRpcInputTest); assertEquals("RpcTestOutput interface - incorrect number of occurences", 1, groupingRpcInputTestCounter); assertEquals("GroupingRpcInputTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev2013718", groupingRpcInputTest.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev130718", groupingRpcInputTest.getPackageName()); assertNotNull("Generated type for grouping-rpc-output-test wasn't generated", groupingRpcOutputTest); assertEquals("RpcTestOutput interface - incorrect number of occurences", 1, groupingRpcOutputTestCounter); assertEquals("GroupingRpcOutputTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev2013718", groupingRpcOutputTest.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev130718", groupingRpcOutputTest.getPackageName()); assertNotNull("Generated type for container-grouping-rpc-input-test wasn't generated", containerGroupingRpcInputTest); assertEquals("ContainerGroupingRpcInputTest interface - incorrect number of occurences", 1, containerGroupingRpcInputTestCounter); assertEquals("ContainerGroupingRpcInputTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev2013718.grouping.rpc.input.test", + "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev130718.grouping.rpc.input.test", containerGroupingRpcInputTest.getPackageName()); containsInterface("GroupingRpcInputTest", rpcTestInput); @@ -506,12 +506,12 @@ public class UsesTest { assertNotNull("Generated type for augment /container-augment wasn't generated.", containerAugment1); assertEquals("ContainerAugment1 interface generated more than one time.", 1, containerAugment1Counter); assertEquals("ContainerAugment1 is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.augment.rev2013718", containerAugment1.getPackageName()); + "org.opendaylight.yang.gen.v1.urn.grouping.uses.augment.rev130718", containerAugment1.getPackageName()); assertNotNull("Generated type for grouping-augment-test wasn't generated.", groupingAugmentTest); assertEquals("GroupingAugmentTest interface generated more than one time.", 1, groupingAugmentTestCounter); assertEquals("groupingAugmentTest is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.augment.rev2013718", + "org.opendaylight.yang.gen.v1.urn.grouping.uses.augment.rev130718", groupingAugmentTest.getPackageName()); containsInterface("GroupingAugmentTest", containerAugment1); @@ -565,14 +565,14 @@ public class UsesTest { assertNotNull("Generated type for notification-test wasn't generated.", notificationTest); assertEquals("NotificationTest interface generated more than one time.", 1, notificationTestCounter); assertEquals("NotificationTest is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev2013718", + "org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev130718", notificationTest.getPackageName()); assertNotNull("Generated type for grouping-notification-test wasn't generated.", groupingNotificationTest); assertEquals("GroupingNotificationTest interface generated more than one time.", 1, groupingNotificationTestCounter); assertEquals("groupingNotificationTest is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev2013718", + "org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev130718", groupingNotificationTest.getPackageName()); assertNotNull("Generated type for container-grouping-notification-test wasn't generated.", @@ -580,7 +580,7 @@ public class UsesTest { assertEquals("ContainerGroupingNotificationTest interface generated more than one time.", 1, containerGroupingNotificationTestCounter); assertEquals("ContainerGroupingNotificationTest is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev2013718.grouping.notification.test", + "org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev130718.grouping.notification.test", containerGroupingNotificationTest.getPackageName()); containsInterface("GroupingNotificationTest", notificationTest); diff --git a/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java b/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java index 3a0d74c8c4..77259cabce 100644 --- a/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java +++ b/code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java @@ -1,5 +1,7 @@ package org.opendaylight.yangtools.binding.generator.util; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Calendar; import java.util.HashSet; @@ -21,6 +23,8 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition; */ public final class BindingGeneratorUtil { + private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyMMdd"); + /** * Array of strings values which represents JAVA reserved words. */ @@ -143,7 +147,6 @@ public final class BindingGeneratorUtil { public static String moduleNamespaceToPackageName(final Module module) { final StringBuilder packageNameBuilder = new StringBuilder(); - final Calendar calendar = Calendar.getInstance(); if (module.getRevision() == null) { throw new IllegalArgumentException("Module " + module.getName() + " does not specify revision date!"); } @@ -167,12 +170,9 @@ public final class BindingGeneratorUtil { namespace = namespace.replace("=", "."); packageNameBuilder.append(namespace); - calendar.setTime(module.getRevision()); packageNameBuilder.append(".rev"); - packageNameBuilder.append(calendar.get(Calendar.YEAR)); - packageNameBuilder.append((calendar.get(Calendar.MONTH) + 1)); - packageNameBuilder.append(calendar.get(Calendar.DAY_OF_MONTH)); - + packageNameBuilder.append(DATE_FORMAT.format(module.getRevision())); + return validateJavaPackage(packageNameBuilder.toString()); } diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java index 1555bbb38f..b273c76081 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java @@ -88,5 +88,7 @@ public interface SchemaContext { * @return module instance which has namespace equal to the * namespace or null in other cases */ - Module findModuleByNamespace(final URI namespace); + Set findModuleByNamespace(final URI namespace); + + Module findModuleByNamespaceAndRevision(final URI namespace,final Date revision); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.xtend b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.xtend index 67374b354e..765cef8b9f 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.xtend +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.xtend @@ -29,6 +29,7 @@ import org.opendaylight.yangtools.yang.model.api.RpcDefinition import org.opendaylight.yangtools.yang.model.api.NotificationDefinition import java.io.ObjectOutputStream.PutField import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode +import java.util.Date /** * The Schema Context Util contains support methods for searching through Schema Context modules for specified schema @@ -60,10 +61,10 @@ public class SchemaContextUtil { * null if the Node is not present. */ public static def SchemaNode findDataSchemaNode( SchemaContext context, SchemaPath schemaPath) { - if (context == null) { + if (context === null) { throw new IllegalArgumentException("Schema Context reference cannot be NULL!"); } - if (schemaPath == null) { + if (schemaPath === null) { throw new IllegalArgumentException("Schema Path reference cannot be NULL"); } val prefixedPath = (schemaPath.getPath()); @@ -99,13 +100,13 @@ public class SchemaContextUtil { */ public static def SchemaNode findDataSchemaNode( SchemaContext context, Module module, RevisionAwareXPath nonCondXPath) { - if (context == null) { + if (context === null) { throw new IllegalArgumentException("Schema Context reference cannot be NULL!"); } - if (module == null) { + if (module === null) { throw new IllegalArgumentException("Module reference cannot be NULL!"); } - if (nonCondXPath == null) { + if (nonCondXPath === null) { throw new IllegalArgumentException("Non Conditional Revision Aware XPath cannot be NULL!"); } @@ -159,16 +160,16 @@ public class SchemaContextUtil { */ public static def SchemaNode findDataSchemaNodeForRelativeXPath( SchemaContext context, Module module, SchemaNode actualSchemaNode, RevisionAwareXPath relativeXPath) { - if (context == null) { + if (context === null) { throw new IllegalArgumentException("Schema Context reference cannot be NULL!"); } - if (module == null) { + if (module === null) { throw new IllegalArgumentException("Module reference cannot be NULL!"); } - if (actualSchemaNode == null) { + if (actualSchemaNode === null) { throw new IllegalArgumentException("Actual Schema Node reference cannot be NULL!"); } - if (relativeXPath == null) { + if (relativeXPath === null) { throw new IllegalArgumentException("Non Conditional Revision Aware XPath cannot be NULL!"); } if (relativeXPath.isAbsolute()) { @@ -201,26 +202,26 @@ public class SchemaContextUtil { * the method will returns null */ public static def Module findParentModule( SchemaContext context, SchemaNode schemaNode) { - if (context == null) { + if (context === null) { throw new IllegalArgumentException("Schema Context reference cannot be NULL!"); } - if (schemaNode == null) { + if (schemaNode === null) { throw new IllegalArgumentException("Schema Node cannot be NULL!"); } val schemaPath = schemaNode.getPath(); - if (schemaPath == null) { + if (schemaPath === null) { throw new IllegalStateException("Schema Path for Schema Node is not " + "set properly (Schema Path is NULL)"); } - val qnamedPath = schemaPath.getPath(); - if (qnamedPath == null || qnamedPath.isEmpty()) { + val qnamedPath = schemaPath.path; + if (qnamedPath === null || qnamedPath.empty) { throw new IllegalStateException("Schema Path contains invalid state of path parts." + "The Schema Path MUST contain at least ONE QName which defines namespace and Local name" + "of path."); } val qname = qnamedPath.get(qnamedPath.size() - 1); - return context.findModuleByNamespace(qname.getNamespace()); + return context.findModuleByNamespaceAndRevision(qname.namespace,qname.revision); } /** @@ -242,16 +243,16 @@ public class SchemaContextUtil { */ private static def SchemaNode findSchemaNodeForGivenPath( SchemaContext context, Module module, Queue qnamedPath) { - if (context == null) { + if (context === null) { throw new IllegalArgumentException("Schema Context reference cannot be NULL!"); } - if (module == null) { + if (module === null) { throw new IllegalArgumentException("Module reference cannot be NULL!"); } - if (module.getNamespace() == null) { + if (module.getNamespace() === null) { throw new IllegalArgumentException("Namespace for Module cannot contains NULL reference!"); } - if (qnamedPath == null || qnamedPath.isEmpty()) { + if (qnamedPath === null || qnamedPath.isEmpty()) { throw new IllegalStateException("Schema Path contains invalid state of path parts." + "The Schema Path MUST contain at least ONE QName which defines namespace and Local name" + "of path."); @@ -265,15 +266,16 @@ public class SchemaContextUtil { while ((nextNode != null) && !qnamedPath.isEmpty()) { childNodeQName = qnamedPath.peek(); if (childNodeQName != null) { - val URI childNodeNamespace = childNodeQName.getNamespace(); - schemaNode = nextNode.getDataChildByName(childNodeQName.getLocalName()); - if(schemaNode == null && nextNode instanceof Module) { + if(schemaNode === null && nextNode instanceof Module) { schemaNode = (nextNode as Module).getNotificationByName(childNodeQName); } - if(schemaNode == null && nextNode instanceof Module) { + if(schemaNode === null && nextNode instanceof Module) { } + val URI childNamespace = childNodeQName.getNamespace(); + val Date childRevision = childNodeQName.getRevision(); + if (schemaNode != null) { if (schemaNode instanceof ContainerSchemaNode) { nextNode = schemaNode as ContainerSchemaNode; @@ -290,8 +292,8 @@ public class SchemaContextUtil { } else { nextNode = null; } - } else if (!childNodeNamespace.equals(moduleNamespace)) { - val Module nextModule = context.findModuleByNamespace(childNodeNamespace); + } else if (!childNamespace.equals(moduleNamespace)) { + val Module nextModule = context.findModuleByNamespaceAndRevision(childNamespace,childRevision); schemaNode = findSchemaNodeForGivenPath(context, nextModule, qnamedPath); return schemaNode; } @@ -304,8 +306,8 @@ public class SchemaContextUtil { private static def SchemaNode findNodeInSchemaContext(SchemaContext context, List path) { val current = path.get(0); - val module = context.findModuleByNamespace(current.namespace); - if(module == null) return null; + val module = context.findModuleByNamespaceAndRevision(current.namespace,current.revision); + if(module === null) return null; return findNodeInModule(module,path); } @@ -418,13 +420,13 @@ public class SchemaContextUtil { */ private static def xpathToQNamePath( SchemaContext context, Module parentModule, String xpath) { - if (context == null) { + if (context === null) { throw new IllegalArgumentException("Schema Context reference cannot be NULL!"); } - if (parentModule == null) { + if (parentModule === null) { throw new IllegalArgumentException("Parent Module reference cannot be NULL!"); } - if (xpath == null) { + if (xpath === null) { throw new IllegalArgumentException("XPath string reference cannot be NULL!"); } @@ -460,13 +462,13 @@ public class SchemaContextUtil { */ private static def QName stringPathPartToQName( SchemaContext context, Module parentModule, String prefixedPathPart) { - if (context == null) { + if (context === null) { throw new IllegalArgumentException("Schema Context reference cannot be NULL!"); } - if (parentModule == null) { + if (parentModule === null) { throw new IllegalArgumentException("Parent Module reference cannot be NULL!"); } - if (prefixedPathPart == null) { + if (prefixedPathPart === null) { throw new IllegalArgumentException("Prefixed Path Part cannot be NULL!"); } @@ -502,13 +504,13 @@ public class SchemaContextUtil { * @return Module for given prefix in specified Schema Context if is present, otherwise returns null */ private static def Module resolveModuleForPrefix( SchemaContext context, Module module, String prefix) { - if (context == null) { + if (context === null) { throw new IllegalArgumentException("Schema Context reference cannot be NULL!"); } - if (module == null) { + if (module === null) { throw new IllegalArgumentException("Module reference cannot be NULL!"); } - if (prefix == null) { + if (prefix === null) { throw new IllegalArgumentException("Prefix string cannot be NULL!"); } @@ -537,20 +539,20 @@ public class SchemaContextUtil { private static def resolveRelativeXPath( SchemaContext context, Module module, RevisionAwareXPath relativeXPath, SchemaNode leafrefParentNode) { - if (context == null) { + if (context === null) { throw new IllegalArgumentException("Schema Context reference cannot be NULL!"); } - if (module == null) { + if (module === null) { throw new IllegalArgumentException("Module reference cannot be NULL!"); } - if (relativeXPath == null) { + if (relativeXPath === null) { throw new IllegalArgumentException("Non Conditional Revision Aware XPath cannot be NULL!"); } if (relativeXPath.isAbsolute()) { throw new IllegalArgumentException("Revision Aware XPath MUST be relative i.e. MUST contains ../, " + "for non relative Revision Aware XPath use findDataSchemaNode method!"); } - if (leafrefParentNode.getPath() == null) { + if (leafrefParentNode.getPath() === null) { throw new IllegalArgumentException("Schema Path reference for Leafref cannot be NULL!"); } val absolutePath = new LinkedList(); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextImpl.java index 3eb87a9214..2d1da1f833 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextImpl.java @@ -84,11 +84,24 @@ final class SchemaContextImpl implements SchemaContext { } @Override - public Module findModuleByNamespace(final URI namespace) { + public Set findModuleByNamespace(final URI namespace) { + final Set ret = new HashSet(); if (namespace != null) { for (final Module module : modules) { if (module.getNamespace().equals(namespace)) { - return module; + ret.add(module); + } + } + } + return ret; + } + + @Override + public Module findModuleByNamespaceAndRevision(URI namespace, Date revision) { + if (namespace != null) { + for (final Module module : modules) { + if (module.getNamespace().equals(namespace) && module.getRevision().equals(revision)) { + return(module); } } } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java index 4cab8d8da6..c2088ce271 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java @@ -105,7 +105,7 @@ public class YangParserWithContextTest { // suffix _g = defined in grouping from context // get grouping - Module contextModule = context.findModuleByNamespace(URI.create("urn:custom.nodes.test")); + Module contextModule = context.findModuleByNamespace(URI.create("urn:custom.nodes.test")).iterator().next(); assertNotNull(contextModule); Set groupings = contextModule.getGroupings(); assertEquals(1, groupings.size()); -- 2.36.6