import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNodeForRelativeXPath;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findParentModule;
+import com.google.common.base.Optional;
import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
public static void addUnitsToGenTO(final GeneratedTOBuilder to, final String units) {
if (!Strings.isNullOrEmpty(units)) {
- to.addConstant(Types.STRING, "Units", "\"" + units + "\"");
+ to.addConstant(Types.STRING, "_UNITS", "\"" + units + "\"");
final GeneratedPropertyBuilder prop = new GeneratedPropertyBuilderImpl("UNITS");
prop.setReturnType(Types.STRING);
to.addToStringProperty(prop);
// a base type which holds these constraints.
if (typeDefinition instanceof DecimalTypeDefinition) {
final Type ret = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType
- (typeDefinition, parentNode, r, null);
+ (typeDefinition, parentNode, r, context);
if (ret != null) {
return ret;
}
}
if (returnType == null) {
returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(
- baseTypeDef, typeDefinition, r, null);
+ baseTypeDef, typeDefinition, r, context);
}
}
}
final RevisionAwareXPath xpath = leafrefType.getPathStatement();
final String strXPath = xpath.toString();
-
if (strXPath != null) {
if (strXPath.indexOf('[') == -1) {
- final Module module = findParentModule(schemaContext, parentNode);
+ final Module module;
+ final SchemaNode actualParentSchemaNode;
+ if ((parentNode instanceof DerivableSchemaNode) && ((DerivableSchemaNode) parentNode).isAddedByUses()) {
+ final Optional<? extends SchemaNode> originalNode = ((DerivableSchemaNode) parentNode).getOriginal();
+ Preconditions.checkArgument(originalNode.isPresent(), "originalNode can not be null.");
+ actualParentSchemaNode = originalNode.get();
+ module = findParentModule(schemaContext, originalNode.get());
+ } else {
+ actualParentSchemaNode = parentNode;
+ module = findParentModule(schemaContext, parentNode);
+ }
Preconditions.checkArgument(module != null, "Failed to find module for parent %s", parentNode);
final SchemaNode dataNode;
if (xpath.isAbsolute()) {
dataNode = findDataSchemaNode(schemaContext, module, xpath);
} else {
- dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath);
+ dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, actualParentSchemaNode, xpath);
}
Preconditions.checkArgument(dataNode != null, "Failed to find leafref target: %s in module %s (%s)",
strXPath, getParentModule(parentNode, schemaContext).getName(), parentNode.getQName().getModule());