X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=code-generator%2Fbinding-generator-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fsal%2Fbinding%2Fyang%2Ftypes%2FTypeProviderImpl.java;h=1b9abbc6520ac0341831258151f2a7007ab42627;hb=8457cb6ef2f2eeb59836cbfd561c8d0d7399229a;hp=e7f81b2af55d0b8ae33befc21104564d8495e93f;hpb=0583cd60749eea6a84ca4afb8fbc1edd04a57f93;p=yangtools.git
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 e7f81b2af5..1b9abbc652 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
@@ -41,12 +41,12 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
@@ -78,7 +78,7 @@ public final class TypeProviderImpl implements TypeProvider {
/**
* Creates new instance of class TypeProviderImpl
.
- *
+ *
* @param schemaContext
* contains the schema data red from YANG files
* @throws IllegalArgumentException
@@ -95,7 +95,7 @@ public final class TypeProviderImpl implements TypeProvider {
/**
* Puts refType
to map with key refTypePath
- *
+ *
* @param refTypePath
* schema path used as the map key
* @param refType
@@ -105,7 +105,7 @@ public final class TypeProviderImpl implements TypeProvider {
*
refTypePath
equal nullrefType
equal nulltype
to JAVA Type
.
- *
+ *
* @param type
* string with YANG name of type
* @returns JAVA Type
for YANG type type
@@ -133,7 +133,7 @@ public final class TypeProviderImpl implements TypeProvider {
/**
* Converts schema definition type typeDefinition
to JAVA
* Type
- *
+ *
* @param typeDefinition
* type definition which is converted to JAVA type
* @throws IllegalArgumentException
@@ -144,7 +144,7 @@ public final class TypeProviderImpl implements TypeProvider {
*
*/
@Override
- public Type javaTypeForSchemaDefinitionType(final TypeDefinition> typeDefinition) {
+ public Type javaTypeForSchemaDefinitionType(final TypeDefinition> typeDefinition, final SchemaNode parentNode) {
Type returnType = null;
Preconditions.checkArgument(typeDefinition != null, "Type Definition cannot be NULL!");
if (typeDefinition.getQName() == null) {
@@ -157,9 +157,9 @@ public final class TypeProviderImpl implements TypeProvider {
if (typeDefinition instanceof ExtendedType) {
returnType = javaTypeForExtendedType(typeDefinition);
} else {
- returnType = javaTypeForLeafrefOrIdentityRef(typeDefinition);
+ returnType = javaTypeForLeafrefOrIdentityRef(typeDefinition, parentNode);
if (returnType == null) {
- returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(typeDefinition);
+ returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(typeDefinition, parentNode);
}
}
// TODO: add throw exception when we will be able to resolve ALL yang
@@ -175,15 +175,15 @@ public final class TypeProviderImpl implements TypeProvider {
* Returns JAVA Type
for instances of the type
* LeafrefTypeDefinition
or
* IdentityrefTypeDefinition
.
- *
+ *
* @param typeDefinition
* type definition which is converted to JAVA Type
* @return JAVA Type
instance for typeDefinition
*/
- private Type javaTypeForLeafrefOrIdentityRef(TypeDefinition> typeDefinition) {
+ private Type javaTypeForLeafrefOrIdentityRef(TypeDefinition> typeDefinition, SchemaNode parentNode) {
if (typeDefinition instanceof LeafrefTypeDefinition) {
final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) typeDefinition;
- return provideTypeForLeafref(leafref);
+ return provideTypeForLeafref(leafref, parentNode);
} else if (typeDefinition instanceof IdentityrefTypeDefinition) {
final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition) typeDefinition;
return provideTypeForIdentityref(idref);
@@ -195,7 +195,7 @@ public final class TypeProviderImpl implements TypeProvider {
/**
* Returns JAVA Type
for instances of the type
* ExtendedType
.
- *
+ *
* @param typeDefinition
* type definition which is converted to JAVA Type
* @return JAVA Type
instance for typeDefinition
@@ -204,13 +204,13 @@ public final class TypeProviderImpl implements TypeProvider {
final String typedefName = typeDefinition.getQName().getLocalName();
final TypeDefinition> baseTypeDef = baseTypeDefForExtendedType(typeDefinition);
Type returnType = null;
- returnType = javaTypeForLeafrefOrIdentityRef(baseTypeDef);
+ returnType = javaTypeForLeafrefOrIdentityRef(baseTypeDef, typeDefinition);
if (returnType == null) {
if (baseTypeDef instanceof EnumTypeDefinition) {
final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) baseTypeDef;
- returnType = provideTypeForEnum(enumTypeDef, typedefName);
+ returnType = provideTypeForEnum(enumTypeDef, typedefName, typeDefinition);
} else {
- final Module module = findParentModuleForTypeDefinition(schemaContext, typeDefinition);
+ final Module module = findParentModule(schemaContext, typeDefinition);
if (module != null) {
final Mapidref
the JAVA
* type
.idref
has name Idn
* then returning type is {@code Class extends Idn>}
- *
+ *
* @param idref
* identityref type definition for which JAVA Type
* is sought
@@ -269,7 +269,7 @@ public final class TypeProviderImpl implements TypeProvider {
/**
* Converts typeDefinition
to concrete JAVA Type
.
- *
+ *
* @param typeDefinition
* type definition which should be converted to JAVA
* Type
@@ -282,7 +282,7 @@ public final class TypeProviderImpl implements TypeProvider {
* typeDefinition
extendTypeDef
. The method is
* recursivelly called until non ExtendedType
type is found.
- *
+ *
* @param extendTypeDef
* type definition for which is the base type definition sought
* @return type definition which is base type for extendTypeDef
@@ -333,10 +333,10 @@ public final class TypeProviderImpl implements TypeProvider {
/**
* Converts leafrefType
to JAVA Type
.
- *
+ *
* The path of leafrefType
is followed to find referenced node
* and its Type
is returned.
- *
+ *
* @param leafrefType
* leafref type definition for which is the type sought
* @return JAVA Type
of data schema node which is referenced in
@@ -346,9 +346,9 @@ public final class TypeProviderImpl implements TypeProvider {
* leafrefType
equal nullleafrefType
equal nulldataNode
is LeafSchemaNode
and if it
* so then checks if it is of type EnumTypeDefinition
.
- *
+ *
* @param dataNode
* data schema node for which is checked if it is leaf and if it
* is of enum type
@@ -410,7 +410,7 @@ public final class TypeProviderImpl implements TypeProvider {
/**
* Checks if dataNode
is LeafListSchemaNode
and if
* it so then checks if it is of type EnumTypeDefinition
.
- *
+ *
* @param dataNode
* data schema node for which is checked if it is leaflist and if
* it is of enum type
@@ -435,7 +435,7 @@ public final class TypeProviderImpl implements TypeProvider {
* Converts enumTypeDef
to
* {@link org.opendaylight.yangtools.sal.binding.model.api.Enumeration
* enumeration}.
- *
+ *
* @param enumTypeDef
* enumeration type definition which is converted to enumeration
* @param enumName
@@ -450,7 +450,7 @@ public final class TypeProviderImpl implements TypeProvider {
* enumTypeDef
equal nulltypeBuilder
. The enumeration data are
* taken from enumTypeDef
.
- *
+ *
* @param enumTypeDef
* enumeration type definition is source of enumeration data for
* typeBuilder
@@ -489,7 +489,7 @@ public final class TypeProviderImpl implements TypeProvider {
* enumTypeDef
equal nulltypeBuilder
equal nulldataNode
to JAVA Type
.
- *
+ *
* @param dataNode
* contains information about YANG type
* @return JAVA Type
representation of dataNode
@@ -520,10 +520,10 @@ public final class TypeProviderImpl implements TypeProvider {
if (dataNode != null) {
if (dataNode instanceof LeafSchemaNode) {
final LeafSchemaNode leaf = (LeafSchemaNode) dataNode;
- returnType = javaTypeForSchemaDefinitionType(leaf.getType());
+ returnType = javaTypeForSchemaDefinitionType(leaf.getType(), leaf);
} else if (dataNode instanceof LeafListSchemaNode) {
final LeafListSchemaNode leafList = (LeafListSchemaNode) dataNode;
- returnType = javaTypeForSchemaDefinitionType(leafList.getType());
+ returnType = javaTypeForSchemaDefinitionType(leafList.getType(), leafList);
}
}
return returnType;
@@ -532,7 +532,7 @@ public final class TypeProviderImpl implements TypeProvider {
/**
* Passes through all modules and through all its type definitions and
* convert it to generated types.
- *
+ *
* The modules are firstly sorted by mutual dependencies. The modules are
* sequentially passed. All type definitions of a module are at the
* beginning sorted so that type definition with less amount of references
@@ -541,7 +541,7 @@ public final class TypeProviderImpl implements TypeProvider {
* {@link TypeProviderImpl#genTypeDefsContextMap genTypeDefsContextMap}
* which map current module name to the map which maps type names to
* returned types (generated types).
- *
+ *
*/
private void resolveTypeDefsFromContext() {
final Settypedef
to generated TO with
* typeDefName
. Every union type from typedef
is
* added to generated TO builder as property.
- *
+ *
* @param basePackageName
* string with name of package to which the module belongs
* @param typedef
@@ -717,7 +717,7 @@ public final class TypeProviderImpl implements TypeProvider {
*
*/
public ListUnionType
.
- *
+ *
* In this case the new generated TO is created for union subtype (recursive
* call of method
* {@link #provideGeneratedTOBuilderForUnionTypeDef(String, TypeDefinition, String)
* provideGeneratedTOBuilderForUnionTypeDef} and in parent TO builder
* parentUnionGenTOBuilder
is created property which type is
* equal to new generated TO.
- *
+ *
* @param parentUnionGenTOBuilder
* generated TO builder to which is the property with the child
* union subtype added
@@ -795,10 +795,10 @@ public final class TypeProviderImpl implements TypeProvider {
* provideGeneratedTOBuildersForUnionTypeDef
method.
*/
private ListExtendedType
.
- *
+ *
* If TO for this type already exists it is used for the creation of the
* property in parentUnionGenTOBuilder
. In other case the base
* type is used for the property creation.
- *
+ *
* @param parentUnionGenTOBuilder
* generated TO builder in which new property is created
* @param unionSubtype
@@ -829,14 +829,14 @@ public final class TypeProviderImpl implements TypeProvider {
* list of strings with the regular expressions
*/
private void resolveExtendedSubtypeAsUnion(final GeneratedTOBuilder parentUnionGenTOBuilder,
- final ExtendedType unionSubtype, final String unionTypeName, final ListsearchedTypeDef
type
* definition in {@link #genTypeDefsContextMap genTypeDefsContextMap}
- *
+ *
* @param searchedTypeDef
* type definition for which is generatet TO sought
* @param searchedTypeName
@@ -858,8 +858,8 @@ public final class TypeProviderImpl implements TypeProvider {
* @return generated TO for searchedTypeDef
or
* null
it it doesn't exist
*/
- private Type findGenTO(final TypeDefinition> searchedTypeDef, final String searchedTypeName) {
- final Module typeModule = findParentModuleForTypeDefinition(schemaContext, searchedTypeDef);
+ private Type findGenTO(final TypeDefinition> searchedTypeDef, final String searchedTypeName, final SchemaNode parentNode) {
+ final Module typeModule = findParentModule(schemaContext, parentNode);
if (typeModule != null && typeModule.getName() != null) {
final MapgenTOBuilder
for
* newTypeDef
to {@link #genTypeDefsContextMap
* genTypeDefsContextMap} if the module for newTypeDef
exists
- *
+ *
* @param newTypeDef
* type definition for which is genTOBuilder
created
* @param genTOBuilder
* generated TO builder which is converted to generated TO and
* stored
*/
- private void storeGenTO(TypeDefinition> newTypeDef, GeneratedTOBuilder genTOBuilder) {
+ private void storeGenTO(TypeDefinition> newTypeDef, GeneratedTOBuilder genTOBuilder, SchemaNode parentNode) {
if (!(newTypeDef instanceof UnionType)) {
MappropertyName
and with type
* type
to unonGenTransObject
.
- *
+ *
* @param unionGenTransObject
* generated TO to which should be property added
* @param type
@@ -921,7 +921,7 @@ public final class TypeProviderImpl implements TypeProvider {
/**
* Converts typedef
to the generated TO builder.
- *
+ *
* @param basePackageName
* string with name of package to which the module belongs
* @param typedef
@@ -946,10 +946,10 @@ public final class TypeProviderImpl implements TypeProvider {
/**
* Converts typeDef
which should be of the type
* BitsTypeDefinition
to GeneratedTOBuilder
.
- *
+ *
* All the bits of the typeDef are added to returning generated TO as
* properties.
- *
+ *
* @param basePackageName
* string with name of package to which the module belongs
* @param typeDef
@@ -996,13 +996,13 @@ public final class TypeProviderImpl implements TypeProvider {
/**
* Converts the pattern constraints from typedef
to the list of
* the strings which represents these constraints.
- *
+ *
* @param typedef
* extended type in which are the pattern constraints sought
* @return list of strings which represents the constraint patterns
* @throws IllegalArgumentException
* if typedef
equals null
- *
+ *
*/
private ListgenTOBuilder
the constant which contains regular
* expressions from the regularExpressions
- *
+ *
* @param genTOBuilder
* generated TO builder to which are
* regular expressions
added
@@ -1056,11 +1056,11 @@ public final class TypeProviderImpl implements TypeProvider {
* innerExtendedType
, about the package name
* typedefName
and about the generated TO name
* typedefName
.
- *
+ *
* It is supposed that innerExtendedType
is already present in
* {@link TypeProviderImpl#genTypeDefsContextMap genTypeDefsContextMap} to
* be possible set it as extended type for the returning generated TO.
- *
+ *
* @param innerExtendedType
* extended type which is part of some other extended type
* @param basePackageName
@@ -1088,7 +1088,7 @@ public final class TypeProviderImpl implements TypeProvider {
final GeneratedTOBuilder genTOBuilder = new GeneratedTOBuilderImpl(basePackageName, classTypedefName);
Mapname
but
* integer suffix is incremented by one. If name
contains no
* number suffix then number 1 is added.
- *
+ *
* @param name
* string with name of augmented node
* @return string with the number suffix incremented by one (or 1 is added)