@Override public SchemaPath getPath() { return schemaNode.getPath(); }
@Override public QName apply(final SchemaNode rpcDefinition) { return rpcDefinition.getQName(); } };
@Override void addCodegenInformation(final GeneratedTypeBuilderBase<?> genType, final Module module, final SchemaNode node) { YangSourceDefinition.of(module, node).ifPresent(genType::setYangSourceDefinition); TypeComments.description(node).ifPresent(genType::addComment); node.getDescription().ifPresent(genType::setDescription); node.getReference().ifPresent(genType::setReference); }
/** * Resolve path argument name for {@code node}. * * <p>The name can contain also prefix which consists of module name followed by colon. The module * prefix is presented if namespace of {@code node} and its parent is different. In other cases * only name of {@code node} is returned. * * @return name of {@code node} */ public static String resolvePathArgumentsName(final SchemaNode node, final SchemaContext schemaContext) { Iterable<QName> schemaPath = node.getPath().getPathTowardsRoot(); Iterator<QName> it = schemaPath.iterator(); QName nodeQName = it.next(); QName parentQName = null; if (it.hasNext()) { parentQName = it.next(); } if (isEqualNamespaceAndRevision(parentQName, nodeQName)) { return node.getQName().getLocalName(); } else { return resolveFullNameFromNode(node, schemaContext); } }
checkArgument(schemaNode != null, "Data Schema Node cannot be NULL."); checkArgument(packageName != null, "Package Name for Generated Type cannot be NULL."); checkArgument(schemaNode.getQName() != null, "QName for Data Schema Node cannot be NULL."); final String schemaNodeName = schemaNode.getQName().getLocalName(); checkArgument(schemaNodeName != null, "Local Name of QName for Data Schema Node cannot be NULL."); qnameConstant(newType, BindingMapping.QNAME_STATIC_FIELD_NAME, schemaNode.getQName()); newType.addComment(schemaNode.getDescription()); newType.setDescription(createDescription(schemaNode, newType.getFullyQualifiedName())); newType.setReference(schemaNode.getReference()); newType.setSchemaPath(schemaNode.getPath().getPathFromRoot()); newType.setModuleName(module.getName());
/** * Find "proper" qname of unknown node in case it comes from a grouping */ private static QName findQNameFromGrouping(final DataNodeContainer subtree, final SchemaContext ctx, final UnknownSchemaNode unknownSchemaNode, final String localIdentityName) { QName identityQName = null; for (UsesNode usesNode : subtree.getUses()) { SchemaNode dataChildByName = SchemaContextUtil.findDataSchemaNode(ctx, usesNode.getGroupingPath()); Module m = SchemaContextUtil.findParentModule(ctx, dataChildByName); List<UnknownSchemaNode> unknownSchemaNodes = dataChildByName.getUnknownSchemaNodes(); if(Collections2.transform(unknownSchemaNodes, UNKNOWN_NODE_TO_STRING).contains(UNKNOWN_NODE_TO_STRING.apply(unknownSchemaNode))) { identityQName = QName.create(dataChildByName.getQName(), localIdentityName); } } return identityQName; }
private String createDescription(final SchemaNode schemaNode, final String fullyQualifiedName) { final StringBuilder sb = new StringBuilder(); final String formattedDescription = YangTemplate.formatToParagraph(schemaNode.getDescription(), 0); sb.append(NEW_LINE); sb.append("<i>"); sb.append(YangTemplate.formatSchemaPath(module.getName(), schemaNode.getPath().getPathFromRoot())); sb.append("</i>"); sb.append(NEW_LINE);
/** * Created a method signature builder as part of <code>interfaceBuilder</code>. The method signature builder is * created for the getter method of <code>schemaNodeName</code>. Also <code>comment</code> * and <code>returnType</code> information are added to the builder. * * @param interfaceBuilder generated type builder for which the getter method should be created * @param returnType type which represents the return type of the getter method * @param schemaNodeName string with schema node name. The name will be the part of the getter method name. * @param comment string with comment for the getter method * @param status status from yang file, for deprecated annotation * @return method signature builder which represents the getter method of <code>interfaceBuilder</code> */ private MethodSignatureBuilder constructGetter(final GeneratedTypeBuilder interfaceBuilder, final Type returnType, final SchemaNode node) { final MethodSignatureBuilder getMethod = interfaceBuilder.addMethod( getterMethodName(node.getQName().getLocalName(), returnType)); getMethod.setReturnType(returnType); annotateDeprecatedIfNecessary(node.getStatus(), getMethod); addComment(getMethod, node); return getMethod; }
@Override public Optional<String> getDescription() { return schemaNode.getDescription(); }
@Override public Optional<String> getReference() { return schemaNode.getReference(); }
@Override public Status getStatus() { return schemaNode.getStatus(); }
private static String getGetterName(final SchemaNode node, final TypeDefinition<?> typeDef) { final String suffix = JavaIdentifierNormalizer.normalizeSpecificIdentifier(node.getQName().getLocalName(), JavaIdentifier.CLASS); if (typeDef instanceof BooleanTypeDefinition && (typeDef.getPath().equals(node.getPath()) || typeDef.getBaseType() == null)) { return "is" + suffix; } return "get" + suffix; }
public static String convertToJavaName(final SchemaNode schemaNode, final boolean capitalizeFirstLetter) { for (UnknownSchemaNode unknownNode : schemaNode.getUnknownSchemaNodes()) { if (ConfigConstants.JAVA_NAME_PREFIX_EXTENSION_QNAME .equals(unknownNode.getNodeType())) { String value = unknownNode.getNodeParameter(); return convertToJavaName(value, capitalizeFirstLetter); } } return convertToJavaName(schemaNode.getQName().getLocalName(), capitalizeFirstLetter); }
@Override public Optional<String> getDescription() { return schemaNode.getDescription(); }
@Override public Optional<String> getReference() { return schemaNode.getReference(); }
@Override public Status getStatus() { return schemaNode.getStatus(); }
@Override public SchemaPath getPath() { return schemaNode.getPath(); }
@Override public QName apply(final SchemaNode input) { return input.getQName(); } };
checkArgument(schemaNode.getQName() != null, "QName for Data Schema Node cannot be NULL."); final String schemaNodeName = schemaNode.getQName().getLocalName(); checkArgument(schemaNodeName != null, "Local Name of QName for Data Schema Node cannot be NULL."); final Module module = findParentModule(schemaContext, schemaNode); qnameConstant(newType, JavaTypeName.create(BindingMapping.getRootPackageName(module.getQNameModule()), BindingMapping.MODULE_INFO_CLASS_NAME), schemaNode.getQName().getLocalName()); newType.setSchemaPath(schemaNode.getPath()); newType.setModuleName(module.getName());
for (SchemaNode refineNode : usesNode.getRefines().values()) { if (TYPE.equals(refineNode.getQName().getLocalName())){ checkState(refineNode.getUnknownSchemaNodes().size() == 1, "Unexpected unknown schema node size of " + refineNode); UnknownSchemaNode requiredIdentity = refineNode.getUnknownSchemaNodes().iterator().next(); checkState(ConfigConstants.REQUIRED_IDENTITY_EXTENSION_QNAME.equals(requiredIdentity.getNodeType()), "Unexpected language extension " + requiredIdentity);