import static com.google.common.base.Preconditions.checkState;
import static org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil.computeDefaultSUID;
import static org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil.packageNameForGeneratedType;
-import static org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil.parseToValidParamName;
import static org.opendaylight.yangtools.binding.generator.util.BindingTypes.DATA_OBJECT;
import static org.opendaylight.yangtools.binding.generator.util.BindingTypes.DATA_ROOT;
import static org.opendaylight.yangtools.binding.generator.util.BindingTypes.IDENTIFIABLE;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNode;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findNodeInSchemaContext;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findParentModule;
-
+import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
* <ul>
* <li>are generated from <code>context</code> schema nodes and</li>
* <li>are also part of some of the module in <code>modules</code>
- * set</li>.
+ * set.</li>
* </ul>
* @throws IllegalArgumentException
* <ul>
final Type type = ((TypeProviderImpl) typeProvider).generatedTypeForExtendedDefinitionType(typedef,
typedef);
if (type != null) {
- genCtx.get(module).addTypedefType(typedef.getPath(), type);
+ final ModuleContext ctx = genCtx.get(module);
+ ctx.addTypedefType(typedef.getPath(), type);
+ ctx.addTypeToSchema(type,typedef);
}
}
}
genCtx.get(module).addChildNodeType(node, genType);
groupingsToGenTypes(module, ((DataNodeContainer) node).getGroupings());
processUsesAugments((DataNodeContainer) node, module);
- if (node.isAddedByUses() || node.isAugmenting())
- genType.setSuitableForBoxing(false);
}
return genType;
}
- private boolean hasWhenOrMustConstraints(final SchemaNode node) {
- boolean hasWhenCondition;
- boolean hasMustConstraints;
-
- if (node instanceof ContainerSchemaNode) {
- ContainerSchemaNode contNode = (ContainerSchemaNode)node;
- hasWhenCondition = contNode.getConstraints().getWhenCondition() != null;
- hasMustConstraints = !isNullOrEmpty(contNode.getConstraints().getMustConstraints());
-
- if (hasWhenCondition || hasMustConstraints)
- return true;
- }
- return false;
- }
-
private void containerToGenType(final Module module, final String basePackageName,
final GeneratedTypeBuilder parent, final GeneratedTypeBuilder childOf, final ContainerSchemaNode node) {
final GeneratedTypeBuilder genType = processDataSchemaNode(module, basePackageName, childOf, node);
-
if (genType != null) {
constructGetter(parent, node.getQName().getLocalName(), node.getDescription(), genType);
resolveDataSchemaNodes(module, basePackageName, genType, genType, node.getChildNodes());
-
- final String parentName = parent.getName();
- final String childOfName = childOf.getName();
-
- if (parent != null && !parent.getName().contains("Data"))
- genType.setParentType(parent);
- genType.setSuitableForBoxing(hasOnlyOneChild(node) && !hasWhenOrMustConstraints(node));
-
- if (parentName.equals(childOfName))
- genType.setSuitableForBoxing(false);
}
}
- private boolean hasOnlyOneChild(final ContainerSchemaNode contNode) {
- if (!isNullOrEmpty(contNode.getChildNodes()) && contNode.getChildNodes().size() == 1)
- return true;
- return false;
- }
-
private void listToGenType(final Module module, final String basePackageName, final GeneratedTypeBuilder parent,
final GeneratedTypeBuilder childOf, final ListSchemaNode node) {
final GeneratedTypeBuilder genType = processDataSchemaNode(module, basePackageName, childOf, node);
-
if (genType != null) {
- if (!parent.getName().equals(childOf) && !parent.getName().contains("Data")) {
- genType.setParentType(parent);
- }
constructGetter(parent, node.getQName().getLocalName(), node.getDescription(), Types.listTypeFor(genType));
final List<String> listKeys = listKeys(node);
for (RpcDefinition rpc : rpcDefinitions) {
if (rpc != null) {
final String rpcName = BindingMapping.getClassName(rpc.getQName());
- final String rpcMethodName = parseToValidParamName(rpcName);
+ final String rpcMethodName = BindingMapping.getPropertyName(rpcName);
final String rpcComment = rpc.getDescription();
final MethodSignatureBuilder method = interfaceBuilder.addMethod(rpcMethodName);
final ContainerSchemaNode input = rpc.getInput();
throw new NullPointerException("Target type not yet generated: " + targetSchemaNode);
}
- if (!(targetSchemaNode instanceof ChoiceNode)) {
+ if (!(targetSchemaNode instanceof ChoiceSchemaNode)) {
String packageName = augmentPackageName;
final Type targetType = new ReferencedTypeImpl(targetTypeBuilder.getPackageName(),
targetTypeBuilder.getName());
} else {
generateTypesFromAugmentedChoiceCases(module, augmentPackageName, targetTypeBuilder.toInstance(),
- (ChoiceNode) targetSchemaNode, augSchema.getChildNodes());
+ (ChoiceSchemaNode) targetSchemaNode, augSchema.getChildNodes());
}
}
if (targetTypeBuilder == null) {
throw new NullPointerException("Target type not yet generated: " + targetSchemaNode);
}
- targetTypeBuilder.setSuitableForBoxing(false);
- if (!(targetSchemaNode instanceof ChoiceNode)) {
+ if (!(targetSchemaNode instanceof ChoiceSchemaNode)) {
String packageName = augmentPackageName;
if (usesNodeParent instanceof SchemaNode) {
packageName = packageNameForGeneratedType(augmentPackageName, ((SchemaNode) usesNodeParent).getPath(),
augSchema);
} else {
generateTypesFromAugmentedChoiceCases(module, augmentPackageName, targetTypeBuilder.toInstance(),
- (ChoiceNode) targetSchemaNode, augSchema.getChildNodes());
+ (ChoiceSchemaNode) targetSchemaNode, augSchema.getChildNodes());
}
}
// with same name and different namespace
if (result instanceof DataNodeContainer) {
result = ((DataNodeContainer) result).getDataChildByName(node.getLocalName());
- } else if (result instanceof ChoiceNode) {
- result = ((ChoiceNode) result).getCaseNodeByName(node.getLocalName());
+ } else if (result instanceof ChoiceSchemaNode) {
+ result = ((ChoiceSchemaNode) result).getCaseNodeByName(node.getLocalName());
}
}
if (result == null) {
containerToGenType(module, basePackageName, typeBuilder, childOf, (ContainerSchemaNode) node);
} else if (node instanceof ListSchemaNode) {
listToGenType(module, basePackageName, typeBuilder, childOf, (ListSchemaNode) node);
- } else if (node instanceof ChoiceNode) {
- choiceToGeneratedType(module, basePackageName, typeBuilder, (ChoiceNode) node);
+ } else if (node instanceof ChoiceSchemaNode) {
+ choiceToGeneratedType(module, basePackageName, typeBuilder, (ChoiceSchemaNode) node);
} else {
// TODO: anyxml not yet supported
LOG.debug("Unable to add schema node {} as method in {}: unsupported type of node.", node.getClass(),
* </ul>
*/
private void choiceToGeneratedType(final Module module, final String basePackageName,
- final GeneratedTypeBuilder parent, final ChoiceNode choiceNode) {
+ final GeneratedTypeBuilder parent, final ChoiceSchemaNode choiceNode) {
checkArgument(basePackageName != null, "Base Package Name cannot be NULL.");
checkArgument(choiceNode != null, "Choice Schema Node cannot be NULL.");
constructGetter(parent, choiceNode.getQName().getLocalName(), choiceNode.getDescription(),
choiceTypeBuilder);
choiceTypeBuilder.addImplementsType(typeForClass(DataContainer.class));
- choiceTypeBuilder.setParentType(parent);
genCtx.get(module).addChildNodeType(choiceNode, choiceTypeBuilder);
generateTypesFromChoiceCases(module, basePackageName, choiceTypeBuilder.toInstance(), choiceNode);
}
* </ul>
*/
private void generateTypesFromChoiceCases(final Module module, final String basePackageName,
- final Type refChoiceType, final ChoiceNode choiceNode) {
+ final Type refChoiceType, final ChoiceSchemaNode choiceNode) {
checkArgument(basePackageName != null, "Base Package Name cannot be NULL.");
checkArgument(refChoiceType != null, "Referenced Choice Type cannot be NULL.");
checkArgument(choiceNode != null, "ChoiceNode cannot be NULL.");
genCtx.get(module).addChoiceToCaseMapping(refChoiceType, caseTypeBuilder, caseNode);
final Iterable<DataSchemaNode> caseChildNodes = caseNode.getChildNodes();
if (caseChildNodes != null) {
- Object parentNode = null;
final SchemaPath nodeSp = choiceNode.getPath();
- parentNode = findDataSchemaNode(schemaContext, nodeSp.getParent());
+ final Object parentNode = findDataSchemaNode(schemaContext, nodeSp.getParent());
SchemaNode parent;
if (parentNode instanceof AugmentationSchema) {
final SchemaPath sp = choiceNode.getPath();
parent = findDataSchemaNode(schemaContext, sp.getParent());
}
+ Preconditions.checkState(parent != null, "Could not find Choice node parent "+choiceNode.getPath().getParent());
GeneratedTypeBuilder childOfType = findChildNodeByPath(parent.getPath());
if (childOfType == null) {
childOfType = findGroupingByPath(parent.getPath());
resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, caseChildNodes);
}
}
-
processUsesAugments(caseNode, module);
}
}
* </ul>
*/
private void generateTypesFromAugmentedChoiceCases(final Module module, final String basePackageName,
- final Type targetType, final ChoiceNode targetNode, final Iterable<DataSchemaNode> augmentedNodes) {
+ final Type targetType, final ChoiceSchemaNode targetNode, final Iterable<DataSchemaNode> augmentedNodes) {
checkArgument(basePackageName != null, "Base Package Name cannot be NULL.");
checkArgument(targetType != null, "Referenced Choice Type cannot be NULL.");
checkArgument(augmentedNodes != null, "Set of Choice Case Nodes cannot be NULL.");
}
final String leafName = leaf.getQName().getLocalName();
final String leafDesc = leaf.getDescription();
- final GeneratedPropertyBuilder propBuilder = toBuilder.addProperty(parseToValidParamName(leafName));
+ final GeneratedPropertyBuilder propBuilder = toBuilder.addProperty(BindingMapping.getPropertyName(leafName));
propBuilder.setReadOnly(isReadOnly);
propBuilder.setReturnType(returnType);
propBuilder.setComment(leafDesc);
* <code>schemaNode</code>.
*
* The new builder always implements
- * {@link org.opendaylight.yangtools.yang.binding.DataObject DataObject}.<br />
+ * {@link org.opendaylight.yangtools.yang.binding.DataObject DataObject}.<br>
* If <code>schemaNode</code> is instance of GroupingDefinition it also
* implements {@link org.opendaylight.yangtools.yang.binding.Augmentable
- * Augmentable}.<br />
+ * Augmentable}.<br>
* If <code>schemaNode</code> is instance of
* {@link org.opendaylight.yangtools.yang.model.api.DataNodeContainer
* DataNodeContainer} it can also implement nodes which are specified in
resolveLeafListSchemaNode(typeBuilder, (LeafListSchemaNode) schemaNode);
} else if (schemaNode instanceof ContainerSchemaNode) {
containerToGenType(module, basePackageName, typeBuilder, typeBuilder, (ContainerSchemaNode) schemaNode);
- } else if (schemaNode instanceof ChoiceNode) {
- choiceToGeneratedType(module, basePackageName, typeBuilder, (ChoiceNode) schemaNode);
+ } else if (schemaNode instanceof ChoiceSchemaNode) {
+ choiceToGeneratedType(module, basePackageName, typeBuilder, (ChoiceSchemaNode) schemaNode);
} else if (schemaNode instanceof ListSchemaNode) {
listToGenType(module, basePackageName, typeBuilder, typeBuilder, (ListSchemaNode) schemaNode);
}
}
final GeneratedPropertyBuilder genPropBuilder = resultTOBuilder.addProperty("value");
- genPropBuilder.setReturnType(Types.primitiveType("char[]", null));
+ genPropBuilder.setReturnType(Types.CHAR_ARRAY);
resultTOBuilder.addEqualsIdentity(genPropBuilder);
resultTOBuilder.addHashIdentity(genPropBuilder);
resultTOBuilder.addToStringProperty(genPropBuilder);
}
}
sb.append(NEW_LINE);
- sb.append("<br />(Source path: <i>");
+ sb.append("<br>(Source path: <i>");
sb.append(moduleSourcePath);
sb.append("</i>):");
sb.append(NEW_LINE);
if (verboseClassComments) {
final Module module = findParentModule(schemaContext, schemaNode);
final StringBuilder linkToBuilderClass = new StringBuilder();
- final StringBuilder linkToKeyClass = new StringBuilder();
final String[] namespace = Iterables.toArray(BSDOT_SPLITTER.split(fullyQualifiedName), String.class);
String className = namespace[namespace.length - 1];
if (hasBuilderClass(schemaNode)) {
linkToBuilderClass.append(className);
linkToBuilderClass.append("Builder");
-
- if (schemaNode instanceof ListSchemaNode) {
- linkToKeyClass.append(className);
- linkToKeyClass.append("Key");
- }
}
sb.append("<p>");
sb.append(module.getName());
sb.append("</b>");
sb.append(NEW_LINE);
- sb.append("<br />(Source path: <i>");
+ sb.append("<br>(Source path: <i>");
sb.append(module.getModuleSourcePath());
sb.append("</i>):");
sb.append(NEW_LINE);
sb.append(NEW_LINE);
sb.append("@see ");
sb.append(linkToBuilderClass);
+ sb.append(NEW_LINE);
if (schemaNode instanceof ListSchemaNode) {
- sb.append("@see ");
- sb.append(linkToKeyClass);
+ final List<QName> keyDef = ((ListSchemaNode)schemaNode).getKeyDefinition();
+ if (keyDef != null && !keyDef.isEmpty()) {
+ sb.append("@see ");
+ sb.append(className);
+ sb.append("Key");
+ }
+ sb.append(NEW_LINE);
}
- sb.append(NEW_LINE);
}
}
sb.append(module.getName());
sb.append("</b>");
sb.append(NEW_LINE);
- sb.append("<br />Source path: <i>");
+ sb.append("<br>Source path: <i>");
sb.append(module.getModuleSourcePath());
sb.append("</i>):");
sb.append(NEW_LINE);