Re-organize YANG snippet generation and comment confusion 54/68254/4
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 14 Feb 2018 13:06:02 +0000 (14:06 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 15 Feb 2018 10:55:11 +0000 (11:55 +0100)
This is a follow-up cleanup on the previous patch, which has created
an unnecessary interface and tunneling contract. We instead record
the details of why a class was generated, capturing comments correctly
in GeneratedType.comment. mdsal-binding-java-api-generator is then
taught to use this information correctly and generate the YANG snippet
as it sees fit.

Change-Id: I25580c6310d05007fea63e04d70cd12d5c6f9ace
JIRA: MDSAL-301
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
25 files changed:
binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/mdsal/binding/maven/api/gen/plugin/CodeGeneratorImpl.java
binding/mdsal-binding-generator-api/src/main/java/org/opendaylight/mdsal/binding/generator/spi/YangTextSnippetProvider.java [deleted file]
binding/mdsal-binding-generator-api/src/main/java/org/opendaylight/mdsal/binding/model/api/GeneratedProperty.java
binding/mdsal-binding-generator-api/src/main/java/org/opendaylight/mdsal/binding/model/api/GeneratedType.java
binding/mdsal-binding-generator-api/src/main/java/org/opendaylight/mdsal/binding/model/api/TypeComment.java [new file with mode: 0644]
binding/mdsal-binding-generator-api/src/main/java/org/opendaylight/mdsal/binding/model/api/YangSourceDefinition.java [new file with mode: 0644]
binding/mdsal-binding-generator-api/src/main/java/org/opendaylight/mdsal/binding/model/api/type/builder/GeneratedTypeBuilderBase.java
binding/mdsal-binding-generator-api/src/main/java/org/opendaylight/mdsal/binding/model/api/type/builder/TypeMemberBuilder.java
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/BindingGeneratorImpl.java
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/VerboseCommentGenerator.java [deleted file]
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/BindingRuntimeContext.java
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/yang/types/TypeProviderImpl.java
binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/ReplaceAllIllegalCharsTest.java [deleted file]
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/model/util/BindingGeneratorUtil.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/model/util/TypeComments.java [new file with mode: 0644]
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/model/util/generated/type/builder/AbstractGeneratedType.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/model/util/generated/type/builder/AbstractGeneratedTypeBuilder.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/model/util/generated/type/builder/EnumerationBuilderImpl.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/model/util/generated/type/builder/GeneratedTypeBuilderImpl.java
binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/mdsal/binding/model/util/BindingGeneratorUtilTest.java
binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/mdsal/binding/model/util/generated/type/builder/GeneratedTypeBuilderTest.java
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/BaseTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/YangTemplate.xtend
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/test/BaseCompilationTest.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/test/ClassCodeGeneratorTest.java

index 6df6d52fbd7ad3caeafd2a97af18323063117432..2f7175a315e9cb601d5f9465c99507b111dde8cb 100644 (file)
@@ -25,11 +25,9 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.function.Function;
 import org.apache.maven.project.MavenProject;
-import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
 import org.opendaylight.mdsal.binding.generator.impl.BindingGeneratorImpl;
 import org.opendaylight.mdsal.binding.java.api.generator.GeneratorJavaFile;
 import org.opendaylight.mdsal.binding.java.api.generator.YangModuleInfoTemplate;
-import org.opendaylight.mdsal.binding.java.api.generator.YangTemplate;
 import org.opendaylight.mdsal.binding.model.api.Type;
 import org.opendaylight.mdsal.binding.model.util.BindingGeneratorUtil;
 import org.opendaylight.yangtools.yang.binding.BindingMapping;
@@ -60,8 +58,7 @@ public final class CodeGeneratorImpl implements BasicCodeGenerator, BuildContext
 
         outputBaseDir = outputDir == null ? getDefaultOutputBaseDir() : outputDir;
 
-        final BindingGenerator bindingGenerator = new BindingGeneratorImpl(YangTemplate.getInstance());
-        final List<Type> types = bindingGenerator.generateTypes(context, yangModules);
+        final List<Type> types = new BindingGeneratorImpl().generateTypes(context, yangModules);
         final GeneratorJavaFile generator = new GeneratorJavaFile(buildContext, types);
 
         File persistentSourcesDir = null;
diff --git a/binding/mdsal-binding-generator-api/src/main/java/org/opendaylight/mdsal/binding/generator/spi/YangTextSnippetProvider.java b/binding/mdsal-binding-generator-api/src/main/java/org/opendaylight/mdsal/binding/generator/spi/YangTextSnippetProvider.java
deleted file mode 100644 (file)
index cded73d..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.generator.spi;
-
-import com.google.common.annotations.Beta;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-
-/**
- * SPI interface for plugging YANG snippet generation into a BindingGenerator.
- */
-@Beta
-@NonNullByDefault
-public interface YangTextSnippetProvider {
-    /**
-     * Generate a YANG snippet for specified SchemaNode.
-     *
-     * @param schemaNode SchemaNode for which to generate a snippet
-     * @return YANG snippet
-     */
-    String generateYangSnippet(SchemaNode schemaNode);
-
-    /**
-     * Generate a YANG snippet for specified Module.
-     *
-     * @param module Module for which to generate a snippet
-     * @return YANG snippet
-     */
-    String generateYangSnippet(Module module);
-}
index 34b4732a4782c7d69791b8b8ef3555e2ddf8fefd..4a9ddb30bd2170fb1c200a44b9fea8411b788b39 100644 (file)
@@ -20,11 +20,11 @@ public interface GeneratedProperty extends TypeMember {
     String getValue();
 
     /**
-     * Returns <code>true</code> if the property si declared as read-only. <br>
+     * Returns <code>true</code> if the property is declared as read-only. <br>
      * If the property has flag <code>isReadOnly == true</code> the property
      * SHOULD be generated as getter only.
      *
-     * @return <code>true</code> if the property si declared as read-only.
+     * @return <code>true</code> if the property is declared as read-only.
      */
     boolean isReadOnly();
 }
index aedbc37d94418cd206c7b0067b4f304be9b2b143..0f0bd8684effa2c33e57b69d057be13712c32673 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.mdsal.binding.model.api;
 
 import java.util.List;
+import java.util.Optional;
 
 /**
  * Every Java interface has to be specified with:
@@ -49,7 +50,7 @@ public interface GeneratedType extends Type, DocumentedType {
      *
      * @return comment string associated with Generated Type.
      */
-    String getComment();
+    TypeComment getComment();
 
     /**
      * Returns List of annotation definitions associated with generated type.
@@ -113,4 +114,10 @@ public interface GeneratedType extends Type, DocumentedType {
      */
     List<GeneratedProperty> getProperties();
 
+    /**
+     * Returns the YANG definition of this type, if available.
+     *
+     * @return YANG source definition, or empty when unavailable.
+     */
+    Optional<YangSourceDefinition> getYangSourceDefinition();
 }
diff --git a/binding/mdsal-binding-generator-api/src/main/java/org/opendaylight/mdsal/binding/model/api/TypeComment.java b/binding/mdsal-binding-generator-api/src/main/java/org/opendaylight/mdsal/binding/model/api/TypeComment.java
new file mode 100644 (file)
index 0000000..c7ec9fa
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.model.api;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * Dedicated type for holding a class comment. It exposes a javadoc-encoded string.
+ *
+ * @author Robert Varga
+ */
+@Beta
+@FunctionalInterface
+@NonNullByDefault
+public interface TypeComment {
+
+    /**
+     * Return a javadoc snippet. This snippet is guaranteed to be safe for direct inclusion in a Java block comment.
+     *
+     * @return Javadoc snippet.
+     */
+    String getJavadoc();
+}
diff --git a/binding/mdsal-binding-generator-api/src/main/java/org/opendaylight/mdsal/binding/model/api/YangSourceDefinition.java b/binding/mdsal-binding-generator-api/src/main/java/org/opendaylight/mdsal/binding/model/api/YangSourceDefinition.java
new file mode 100644 (file)
index 0000000..c2b3293
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.model.api;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.List;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+
+/**
+ * DTO capturing the YANG source definition which lead to a {@link GeneratedType} being emitted.
+ *
+ * @author Robert Varga
+ */
+@Beta
+@NonNullByDefault
+public abstract class YangSourceDefinition {
+    public static final class Multiple extends YangSourceDefinition {
+        private final List<? extends SchemaNode> nodes;
+
+        Multiple(final Module module, final Collection<? extends SchemaNode> nodes) {
+            super(module);
+            this.nodes = ImmutableList.copyOf(nodes);
+        }
+
+        /**
+         * Return the defining SchemaNodes.
+         *
+         * @return defining SchemaNodes, guaranteed to be non-empty
+         */
+        public List<? extends SchemaNode> getNodes() {
+            return nodes;
+        }
+    }
+
+    public static final class Single extends YangSourceDefinition {
+        private final DocumentedNode node;
+
+        Single(final Module module, final DocumentedNode node) {
+            super(module);
+            this.node = requireNonNull(node);
+        }
+
+        public DocumentedNode getNode() {
+            return node;
+        }
+    }
+
+    private final Module module;
+
+    private YangSourceDefinition(final Module module) {
+        this.module = requireNonNull(module);
+    }
+
+    public static YangSourceDefinition of(final Module module) {
+        return new Single(module, module);
+    }
+
+    public static YangSourceDefinition of(final Module module, final SchemaNode node) {
+        return new Single(module, node);
+    }
+
+    public static YangSourceDefinition of(final Module module, final Collection<? extends SchemaNode> nodes) {
+        checkArgument(!nodes.isEmpty());
+        return new Multiple(module, nodes);
+    }
+
+    /**
+     * Return the defining YANG module.
+     *
+     * @return Defining YANG module.
+     */
+    public final Module getModule() {
+        return module;
+    }
+}
index bf1272028940bab58f6caa8d305e245042e36998..f7ebe0bc793ba91b5670d11cf00e54bd980e164a 100644 (file)
@@ -8,8 +8,12 @@
 package org.opendaylight.mdsal.binding.model.api.type.builder;
 
 import java.util.List;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.model.api.Constant;
 import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.mdsal.binding.model.api.TypeComment;
+import org.opendaylight.mdsal.binding.model.api.YangSourceDefinition;
 import org.opendaylight.yangtools.yang.common.QName;
 
 public interface GeneratedTypeBuilderBase<T extends GeneratedTypeBuilderBase<T>> extends Type {
@@ -52,13 +56,13 @@ public interface GeneratedTypeBuilderBase<T extends GeneratedTypeBuilderBase<T>>
 
     /**
      * Adds String definition of comment into Method Signature definition. <br>
-     * The comment String MUST NOT contain anny comment specific chars (i.e.
+     * The comment String MUST NOT contain any comment specific chars (i.e.
      * "/**" or "//") just plain String text description.
      *
      * @param comment
      *            Comment String.
      */
-    T addComment(String comment);
+    T addComment(TypeComment comment);
 
     /**
      * The method creates new AnnotationTypeBuilder containing specified package
@@ -158,6 +162,13 @@ public interface GeneratedTypeBuilderBase<T extends GeneratedTypeBuilderBase<T>>
 
     List<GeneratedPropertyBuilder> getProperties();
 
+    /**
+     * Returns the YANG definition of this type, if available.
+     *
+     * @return YANG source definition, or empty when unavailable.
+     */
+    Optional<YangSourceDefinition> getYangSourceDefinition();
+
     /**
      * Add new Generated Property definition for Generated Transfer Object
      * Builder and returns Generated Property Builder for specifying Property. <br>
@@ -218,4 +229,10 @@ public interface GeneratedTypeBuilderBase<T extends GeneratedTypeBuilderBase<T>>
      */
     void setReference(String reference);
 
+    /**
+     * Set the YANG source definition.
+     *
+     * @param definition YANG source definition, must not be null
+     */
+    void setYangSourceDefinition(@NonNull YangSourceDefinition definition);
 }
index 32542ad2b73e948c5fdeea00fb104dcb0875e6b2..050a4131da3f0ab2582953192adcb45aedb8ee57 100644 (file)
@@ -56,7 +56,7 @@ public interface TypeMemberBuilder<T extends TypeMemberBuilder<T>> {
 
     /**
      * Adds String definition of comment into Method Signature definition. <br>
-     * The comment String MUST NOT contain anny comment specific chars (i.e.
+     * The comment String MUST NOT contain any comment specific chars (i.e.
      * "/**" or "//") just plain String text description.
      *
      * @param comment
index 72388f4d57722b6afdaeb12e27556c80c51d3d4c..21433b0313b5796f04a0ccfdbad603627c8ab7c5 100644 (file)
@@ -28,10 +28,8 @@ import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findD
 import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findNodeInSchemaContext;
 import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findParentModule;
 
-import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
 import java.util.ArrayList;
@@ -43,10 +41,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
-import java.util.regex.Pattern;
 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
 import org.opendaylight.mdsal.binding.generator.spi.TypeProvider;
-import org.opendaylight.mdsal.binding.generator.spi.YangTextSnippetProvider;
 import org.opendaylight.mdsal.binding.model.api.AccessModifier;
 import org.opendaylight.mdsal.binding.model.api.Constant;
 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
@@ -54,6 +50,7 @@ import org.opendaylight.mdsal.binding.model.api.GeneratedType;
 import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
 import org.opendaylight.mdsal.binding.model.api.Restrictions;
 import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.mdsal.binding.model.api.YangSourceDefinition;
 import org.opendaylight.mdsal.binding.model.api.type.builder.AnnotationTypeBuilder;
 import org.opendaylight.mdsal.binding.model.api.type.builder.EnumBuilder;
 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder;
@@ -63,8 +60,8 @@ import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilde
 import org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder;
 import org.opendaylight.mdsal.binding.model.util.BindingGeneratorUtil;
 import org.opendaylight.mdsal.binding.model.util.BindingTypes;
-import org.opendaylight.mdsal.binding.model.util.FormattingUtils;
 import org.opendaylight.mdsal.binding.model.util.ReferencedTypeImpl;
+import org.opendaylight.mdsal.binding.model.util.TypeComments;
 import org.opendaylight.mdsal.binding.model.util.Types;
 import org.opendaylight.mdsal.binding.model.util.generated.type.builder.GeneratedPropertyBuilderImpl;
 import org.opendaylight.mdsal.binding.model.util.generated.type.builder.GeneratedTOBuilderImpl;
@@ -117,8 +114,6 @@ import org.slf4j.LoggerFactory;
 public class BindingGeneratorImpl implements BindingGenerator {
     private static final Logger LOG = LoggerFactory.getLogger(BindingGeneratorImpl.class);
     private static final Splitter COLON_SPLITTER = Splitter.on(':');
-    private static final Splitter BSDOT_SPLITTER = Splitter.on("\\.");
-    private static final char NEW_LINE = '\n';
 
     /**
      * Comparator based on augment target path.
@@ -151,15 +146,8 @@ public class BindingGeneratorImpl implements BindingGenerator {
      */
     private static final String YANG_EXT_NAMESPACE = "urn:opendaylight:yang:extension:yang-ext";
 
-    private static final Pattern UNICODE_CHAR_PATTERN = Pattern.compile("\\\\+u");
-
     private final Map<Module, ModuleContext> genCtx = new HashMap<>();
-
-    /**
-     * When set to non-null, generated classes will include javadoc comments which are useful for users, generated
-     * using specified generator.
-     */
-    private final VerboseCommentGenerator verboseCommentGenerator;
+    private final boolean fullTypes;
 
     /**
      * Outer key represents the package name. Outer value represents map of all
@@ -180,20 +168,12 @@ public class BindingGeneratorImpl implements BindingGenerator {
      */
     private SchemaContext schemaContext;
 
-    /**
-     * Create a new binding generator, which does not generate verbose class comments.
-     */
     public BindingGeneratorImpl() {
-        verboseCommentGenerator = null;
+        this(false);
     }
 
-    /**
-     * Create a new binding generator.
-     *
-     * @param snippetProvider generate verbose comments using this generator
-     */
-    public BindingGeneratorImpl(final YangTextSnippetProvider snippetProvider) {
-        this.verboseCommentGenerator = new VerboseCommentGenerator(snippetProvider);
+    public BindingGeneratorImpl(final boolean skinnyTypes) {
+        this.fullTypes = !skinnyTypes;
     }
 
     /**
@@ -339,11 +319,16 @@ public class BindingGeneratorImpl implements BindingGenerator {
         }
         final String packageName = packageNameForGeneratedType(basePackageName, node.getPath());
         final GeneratedTypeBuilder genType = addDefaultInterfaceDefinition(packageName, node, childOf, module);
-        genType.addComment(node.getDescription().orElse(null));
         annotateDeprecatedIfNecessary(node.getStatus(), genType);
-        genType.setDescription(createDescription(node, genType.getFullyQualifiedName()));
+
         genType.setModuleName(module.getName());
-        genType.setReference(node.getReference().orElse(null));
+
+        if (fullTypes) {
+            genType.setYangSourceDefinition(YangSourceDefinition.of(module, node));
+            TypeComments.description(node).ifPresent(genType::addComment);
+            node.getDescription().ifPresent(genType::setDescription);
+            node.getReference().ifPresent(genType::setReference);
+        }
         genType.setSchemaPath(node.getPath().getPathFromRoot());
         if (node instanceof DataNodeContainer) {
             genCtx.get(module).addChildNodeType(node, genType);
@@ -474,14 +459,18 @@ public class BindingGeneratorImpl implements BindingGenerator {
         final GeneratedTypeBuilder moduleDataTypeBuilder = moduleTypeBuilder(module, "Data");
         addImplementedInterfaceFromUses(module, moduleDataTypeBuilder);
         moduleDataTypeBuilder.addImplementsType(DATA_ROOT);
-        moduleDataTypeBuilder.addComment(module.getDescription().orElse(null));
-        moduleDataTypeBuilder.setDescription(createDescription(module));
-        moduleDataTypeBuilder.setReference(module.getReference().orElse(null));
+
+        if (fullTypes) {
+            moduleDataTypeBuilder.setYangSourceDefinition(YangSourceDefinition.of(module));
+            TypeComments.description(module).ifPresent(moduleDataTypeBuilder::addComment);
+            module.getDescription().ifPresent(moduleDataTypeBuilder::setDescription);
+            module.getReference().ifPresent(moduleDataTypeBuilder::setReference);
+        }
         return moduleDataTypeBuilder;
     }
 
     /**
-     * Converts all <b>rpcs</b> inputs and outputs substatements of the module
+     * Converts all <b>RPCs</b> input and output substatements of the module
      * to the list of <code>Type</code> objects. In addition are to containers
      * and lists which belong to input or output also part of returning list.
      *
@@ -508,7 +497,13 @@ public class BindingGeneratorImpl implements BindingGenerator {
         final String basePackageName = BindingMapping.getRootPackageName(module.getQNameModule());
         final GeneratedTypeBuilder interfaceBuilder = moduleTypeBuilder(module, "Service");
         interfaceBuilder.addImplementsType(Types.typeForClass(RpcService.class));
-        interfaceBuilder.setDescription(createDescription(rpcDefinitions, module.getName()));
+
+        if (fullTypes) {
+            interfaceBuilder.addComment(TypeComments.javadoc(
+                "Interface for implementing the following YANG RPCs defined in module <b>" + module.getName() + "</b>")
+                .get());
+            interfaceBuilder.setYangSourceDefinition(YangSourceDefinition.of(module, rpcDefinitions));
+        }
 
         for (final RpcDefinition rpc : rpcDefinitions) {
             if (rpc != null) {
@@ -594,8 +589,6 @@ public class BindingGeneratorImpl implements BindingGenerator {
         listenerInterface.addImplementsType(BindingTypes.NOTIFICATION_LISTENER);
         final String basePackageName = BindingMapping.getRootPackageName(module.getQNameModule());
 
-
-
         for (final NotificationDefinition notification : notifications) {
             if (notification != null) {
                 processUsesAugments(notification, module);
@@ -615,7 +608,13 @@ public class BindingGeneratorImpl implements BindingGenerator {
                 .setComment(encodeAngleBrackets(notification.getDescription().orElse(null))).setReturnType(Types.VOID);
             }
         }
-        listenerInterface.setDescription(createDescription(notifications, module.getName()));
+
+        if (fullTypes) {
+            listenerInterface.setYangSourceDefinition(YangSourceDefinition.of(module, notifications));
+            listenerInterface.addComment(TypeComments.javadoc(
+                "Interface for receiving the following YANG notifications defined in module <b>" + module.getName()
+                + "</b>").get());
+        }
 
         genCtx.get(module).addTopLevelNodeType(listenerInterface);
     }
@@ -686,9 +685,13 @@ public class BindingGeneratorImpl implements BindingGenerator {
             newType.setExtendsType(gto);
         }
         newType.setAbstract(true);
-        newType.addComment(identity.getDescription().orElse(null));
-        newType.setDescription(createDescription(identity, newType.getFullyQualifiedName()));
-        newType.setReference(identity.getReference().orElse(null));
+
+        if (fullTypes) {
+            newType.setYangSourceDefinition(YangSourceDefinition.of(module, identity));
+            TypeComments.description(identity).ifPresent(newType::addComment);
+            identity.getDescription().ifPresent(newType::setDescription);
+            identity.getReference().ifPresent(newType::setReference);
+        }
         newType.setModuleName(module.getName());
         newType.setSchemaPath(identity.getPath().getPathFromRoot());
 
@@ -802,9 +805,14 @@ public class BindingGeneratorImpl implements BindingGenerator {
         final String moduleName = BindingMapping.getClassName(module.getName()) + postfix;
 
         final GeneratedTypeBuilderImpl moduleBuilder = new GeneratedTypeBuilderImpl(packageName, moduleName);
-        moduleBuilder.setDescription(createDescription(module));
-        moduleBuilder.setReference(module.getReference().orElse(null));
+
         moduleBuilder.setModuleName(moduleName);
+        if (fullTypes) {
+            moduleBuilder.setYangSourceDefinition(YangSourceDefinition.of(module));
+            TypeComments.description(module).ifPresent(moduleBuilder::addComment);
+            module.getDescription().ifPresent(moduleBuilder::setDescription);
+            module.getReference().ifPresent(moduleBuilder::setReference);
+        }
 
         return moduleBuilder;
     }
@@ -1677,10 +1685,13 @@ public class BindingGeneratorImpl implements BindingGenerator {
             final GeneratedTypeBuilder typeBuilder, final Module parentModule) {
         final GeneratedTOBuilderImpl returnType = new GeneratedTOBuilderImpl(genTOBuilder.getPackageName(),
                 genTOBuilder.getName());
-        final String typedefDescription = encodeAngleBrackets(typeDef.getDescription().orElse(null));
 
-        returnType.setDescription(typedefDescription);
-        returnType.setReference(typeDef.getReference().orElse(null));
+        if (fullTypes) {
+            returnType.setYangSourceDefinition(YangSourceDefinition.of(parentModule, typeDef));
+            TypeComments.description(typeDef).ifPresent(returnType::addComment);
+            typeDef.getDescription().ifPresent(returnType::setDescription);
+            typeDef.getReference().ifPresent(returnType::setReference);
+        }
         returnType.setSchemaPath(typeDef.getPath().getPathFromRoot());
         returnType.setModuleName(parentModule.getName());
 
@@ -1830,9 +1841,13 @@ public class BindingGeneratorImpl implements BindingGenerator {
         final GeneratedTypeBuilderImpl newType = new GeneratedTypeBuilderImpl(packageName, genTypeName);
         final Module module = findParentModule(schemaContext, schemaNode);
         qnameConstant(newType, BindingMapping.QNAME_STATIC_FIELD_NAME, schemaNode.getQName());
-        newType.addComment(schemaNode.getDescription().orElse(null));
-        newType.setDescription(createDescription(schemaNode, newType.getFullyQualifiedName()));
-        newType.setReference(schemaNode.getReference().orElse(null));
+
+        if (fullTypes) {
+            newType.setYangSourceDefinition(YangSourceDefinition.of(module, schemaNode));
+            TypeComments.description(schemaNode).ifPresent(newType::addComment);
+            schemaNode.getDescription().ifPresent(newType::setDescription);
+            schemaNode.getReference().ifPresent(newType::setReference);
+        }
         newType.setSchemaPath(schemaNode.getPath().getPathFromRoot());
         newType.setModuleName(module.getName());
 
@@ -2106,68 +2121,6 @@ public class BindingGeneratorImpl implements BindingGenerator {
         return builder;
     }
 
-    private static boolean isNullOrEmpty(final Collection<?> list) {
-        return list == null || list.isEmpty();
-    }
-
-    private String createDescription(final Set<? extends SchemaNode> schemaNodes, final String moduleName) {
-        final StringBuilder sb = new StringBuilder();
-
-        if (!isNullOrEmpty(schemaNodes)) {
-            final SchemaNode node = schemaNodes.iterator().next();
-
-            if (node instanceof RpcDefinition) {
-                sb.append("Interface for implementing the following YANG RPCs defined in module <b>" + moduleName + "</b>");
-            } else if (node instanceof NotificationDefinition) {
-                sb.append("Interface for receiving the following YANG notifications defined in module <b>" + moduleName + "</b>");
-            }
-        }
-        sb.append(NEW_LINE);
-
-        if (verboseCommentGenerator != null) {
-            verboseCommentGenerator.appendYangSnippet(sb, schemaNodes);
-        }
-
-        return replaceAllIllegalChars(sb);
-    }
-
-    private String createDescription(final SchemaNode schemaNode, final String fullyQualifiedName) {
-        final StringBuilder sb = new StringBuilder();
-        final String nodeDescription = encodeAngleBrackets(schemaNode.getDescription().orElse(null));
-        final String formattedDescription = FormattingUtils.formatToParagraph(nodeDescription, 0);
-
-        if (!Strings.isNullOrEmpty(formattedDescription)) {
-            sb.append(formattedDescription);
-            sb.append(NEW_LINE);
-        }
-
-        if (verboseCommentGenerator != null) {
-            final Module module = findParentModule(schemaContext, schemaNode);
-            final String[] namespace = Iterables.toArray(BSDOT_SPLITTER.split(fullyQualifiedName), String.class);
-
-            verboseCommentGenerator.appendYangSnippet(sb, module, schemaNode, namespace[namespace.length - 1]);
-        }
-
-        return replaceAllIllegalChars(sb);
-    }
-
-    private String createDescription(final Module module) {
-        final StringBuilder sb = new StringBuilder();
-        final String moduleDescription = encodeAngleBrackets(module.getDescription().orElse(null));
-        final String formattedDescription = FormattingUtils.formatToParagraph(moduleDescription, 0);
-
-        if (!Strings.isNullOrEmpty(formattedDescription)) {
-            sb.append(formattedDescription);
-            sb.append(NEW_LINE);
-        }
-
-        if (verboseCommentGenerator != null) {
-            verboseCommentGenerator.appendModuleDescription(sb, module);
-        }
-
-        return replaceAllIllegalChars(sb);
-    }
-
     private GeneratedTypeBuilder findChildNodeByPath(final SchemaPath path) {
         for (final ModuleContext ctx : genCtx.values()) {
             final GeneratedTypeBuilder result = ctx.getChildNode(path);
@@ -2202,12 +2155,6 @@ public class BindingGeneratorImpl implements BindingGenerator {
         return genCtx;
     }
 
-    @VisibleForTesting
-    static String replaceAllIllegalChars(final StringBuilder stringBuilder){
-        final String ret = UNICODE_CHAR_PATTERN.matcher(stringBuilder).replaceAll("\\\\\\\\u");
-        return ret.isEmpty() ? "" : ret;
-    }
-
     private static void annotateDeprecatedIfNecessary(final Status status, final GeneratedTypeBuilder builder) {
         if (status == Status.DEPRECATED) {
             builder.addAnnotation("", "Deprecated");
diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/VerboseCommentGenerator.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/VerboseCommentGenerator.java
deleted file mode 100644 (file)
index 0f61088..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.generator.impl;
-
-import static java.util.Objects.requireNonNull;
-import static org.opendaylight.mdsal.binding.model.util.BindingGeneratorUtil.encodeAngleBrackets;
-
-import com.google.common.collect.Iterables;
-import java.util.List;
-import java.util.Set;
-import org.opendaylight.mdsal.binding.generator.spi.YangTextSnippetProvider;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
-import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-
-final class VerboseCommentGenerator {
-    private final YangTextSnippetProvider provider;
-
-    VerboseCommentGenerator(final YangTextSnippetProvider provider) {
-        this.provider = requireNonNull(provider);
-    }
-
-    void appendModuleDescription(final StringBuilder sb, final Module module) {
-        sb.append("<p>")
-        .append("This class represents the following YANG schema fragment defined in module <b>")
-        .append(module.getName())
-        .append("</b>\n")
-        .append("<pre>\n")
-        .append(encodeAngleBrackets(provider.generateYangSnippet(module)))
-        .append("</pre>");
-    }
-
-    void appendYangSnippet(final StringBuilder sb, final Set<? extends SchemaNode> schemaNodes) {
-        if (!schemaNodes.isEmpty()) {
-            sb.append("<pre>\n");
-            for (SchemaNode schemaNode : schemaNodes) {
-                sb.append(encodeAngleBrackets(provider.generateYangSnippet(requireNonNull(schemaNode))));
-            }
-            sb.append("</pre>\n");
-        }
-    }
-
-    void appendYangSnippet(final StringBuilder sb, final Module module, final SchemaNode schemaNode,
-            final String className) {
-
-        sb.append("<p>\n")
-        .append("This class represents the following YANG schema fragment defined in module <b>")
-        .append(module.getName())
-        .append("</b>\n")
-        .append("<pre>\n")
-        .append(encodeAngleBrackets(provider.generateYangSnippet(schemaNode)))
-        .append("</pre>\n")
-        .append("The schema path to identify an instance is\n")
-        .append("<i>")
-        .append(formatSchemaPath(module.getName(), schemaNode.getPath().getPathFromRoot()))
-        .append("</i>\n");
-
-        if (hasBuilderClass(schemaNode)) {
-            final String builderClassName = className + "Builder";
-
-            sb.append("\n<p>To create instances of this class use {@link ").append(builderClassName).append("}.\n")
-            .append("@see ").append(builderClassName).append('\n');
-            if (schemaNode instanceof ListSchemaNode) {
-                final List<QName> keyDef = ((ListSchemaNode)schemaNode).getKeyDefinition();
-                if (keyDef != null && !keyDef.isEmpty()) {
-                    sb.append("@see ").append(className).append("Key");
-                }
-                sb.append('\n');
-            }
-        }
-    }
-
-    private static boolean hasBuilderClass(final SchemaNode schemaNode) {
-        return schemaNode instanceof ContainerSchemaNode || schemaNode instanceof ListSchemaNode
-                || schemaNode instanceof RpcDefinition || schemaNode instanceof NotificationDefinition;
-    }
-
-    private static String formatSchemaPath(final String moduleName, final Iterable<QName> schemaPath) {
-        final StringBuilder sb = new StringBuilder();
-        sb.append(moduleName);
-
-        QName currentElement = Iterables.getFirst(schemaPath, null);
-        for (QName pathElement : schemaPath) {
-            sb.append('/');
-            if (!currentElement.getNamespace().equals(pathElement.getNamespace())) {
-                currentElement = pathElement;
-                sb.append(pathElement);
-            } else {
-                sb.append(pathElement.getLocalName());
-            }
-        }
-        return sb.toString();
-    }
-}
index 47de8714e0bad1e04664ab8d66de5c04a96c4490..cde50e401478cdb961571d7bd69c6b8d1af59083 100644 (file)
@@ -102,7 +102,7 @@ public class BindingRuntimeContext implements Immutable {
         this.strategy = strategy;
         this.schemaContext = schema;
 
-        final BindingGeneratorImpl generator = new BindingGeneratorImpl();
+        final BindingGeneratorImpl generator = new BindingGeneratorImpl(true);
         generator.generateTypes(schema);
         final Map<Module, ModuleContext> modules = generator.getModuleContexts();
 
index 7c72adff8f88fc35359e3f887efc577dded33c72..7344d5b3c49f6fd04bb054a13c71bfa63ffde429 100644 (file)
@@ -950,7 +950,7 @@ public final class TypeProviderImpl implements TypeProvider {
             unionGenTOBuilder = new GeneratedTOBuilderImpl(basePackageName, typeName);
             final String typedefDescription = encodeAngleBrackets(typedef.getDescription().orElse(null));
             unionGenTOBuilder.setDescription(typedefDescription);
-            unionGenTOBuilder.setReference(typedef.getReference().orElse(null));
+            typedef.getReference().ifPresent(unionGenTOBuilder::setReference);
             unionGenTOBuilder.setSchemaPath(typedef.getPath().getPathFromRoot());
             unionGenTOBuilder.setModuleName(module.getName());
         } else {
@@ -1169,7 +1169,7 @@ public final class TypeProviderImpl implements TypeProvider {
             final String typedefDescription = encodeAngleBrackets(typedef.getDescription().orElse(null));
 
             newType.setDescription(typedefDescription);
-            newType.setReference(typedef.getReference().orElse(null));
+            typedef.getReference().ifPresent(newType::setReference);
             newType.setSchemaPath(typedef.getPath().getPathFromRoot());
             newType.setModuleName(moduleName);
 
@@ -1212,7 +1212,7 @@ public final class TypeProviderImpl implements TypeProvider {
             final String typedefDescription = encodeAngleBrackets(typeDef.getDescription().orElse(null));
 
             genTOBuilder.setDescription(typedefDescription);
-            genTOBuilder.setReference(typeDef.getReference().orElse(null));
+            typeDef.getReference().ifPresent(genTOBuilder::setReference);
             genTOBuilder.setSchemaPath(typeDef.getPath().getPathFromRoot());
             genTOBuilder.setModuleName(moduleName);
             genTOBuilder.setBaseType(typeDef);
@@ -1334,7 +1334,7 @@ public final class TypeProviderImpl implements TypeProvider {
         final String typedefDescription = encodeAngleBrackets(typedef.getDescription().orElse(null));
 
         genTOBuilder.setDescription(typedefDescription);
-        genTOBuilder.setReference(typedef.getReference().orElse(null));
+        typedef.getReference().ifPresent(genTOBuilder::setReference);
         genTOBuilder.setSchemaPath(typedef.getPath().getPathFromRoot());
         genTOBuilder.setModuleName(moduleName);
         genTOBuilder.setTypedef(true);
diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/ReplaceAllIllegalCharsTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/ReplaceAllIllegalCharsTest.java
deleted file mode 100644 (file)
index db31db3..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.generator.impl;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-import org.opendaylight.mdsal.binding.generator.impl.BindingGeneratorImpl;
-
-public class ReplaceAllIllegalCharsTest {
-
-    @Test
-    public void unicodeCharReplaceTest() {
-        String inputString = "abcu\\uuuuu\\uuua\\u\\\\uabc\\\\uuuu\\\\\\uuuu\\\\\\\\uuuu///uu/u/u/u/u/u/u";
-
-        StringBuilder sb = new StringBuilder(inputString);
-        String resultString = BindingGeneratorImpl.replaceAllIllegalChars(sb);
-
-        String expectedString = "abcu\\\\uuuuu\\\\uuua\\\\u\\\\uabc\\\\uuuu\\\\uuuu\\\\uuuu///uu/u/u/u/u/u/u";
-        assertEquals(expectedString, resultString);
-    }
-
-}
index 1039c71534a0fe954fb37530dfd0a7e4630f298b..bbb37b57c7bdfe10e3a41d0c813b03544b34bbcb 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Optional;
+import java.util.regex.Pattern;
 import org.opendaylight.mdsal.binding.model.api.AccessModifier;
 import org.opendaylight.mdsal.binding.model.api.Restrictions;
 import org.opendaylight.mdsal.binding.model.api.Type;
@@ -66,6 +67,7 @@ public final class BindingGeneratorUtil {
     private static final CharMatcher DASH_COLON_MATCHER = CharMatcher.anyOf("-:");
     private static final CharMatcher GT_MATCHER = CharMatcher.is('>');
     private static final CharMatcher LT_MATCHER = CharMatcher.is('<');
+    private static final Pattern UNICODE_CHAR_PATTERN = Pattern.compile("\\\\+u");
 
     private static final Restrictions EMPTY_RESTRICTIONS = new Restrictions() {
         @Override
@@ -632,4 +634,9 @@ public final class BindingGeneratorUtil {
         }
         return description;
     }
+
+    public static String replaceAllIllegalChars(final CharSequence stringBuilder){
+        final String ret = UNICODE_CHAR_PATTERN.matcher(stringBuilder).replaceAll("\\\\\\\\u");
+        return ret.isEmpty() ? "" : ret;
+    }
 }
diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/model/util/TypeComments.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/model/util/TypeComments.java
new file mode 100644 (file)
index 0000000..bd7f1ad
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.model.util;
+
+import static org.opendaylight.mdsal.binding.model.util.BindingGeneratorUtil.replaceAllIllegalChars;
+import static org.opendaylight.mdsal.binding.model.util.FormattingUtils.formatToParagraph;
+
+import com.google.common.annotations.Beta;
+import com.google.common.escape.Escaper;
+import com.google.common.escape.Escapers;
+import java.util.Optional;
+import java.util.regex.Pattern;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.mdsal.binding.model.api.TypeComment;
+import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
+
+/**
+ * Utility methods for creating {@link TypeComment}s.
+ */
+@Beta
+@NonNullByDefault
+public final class TypeComments {
+    private static final Escaper ENTITY_ESCAPER = Escapers.builder()
+            .addEscape('<', "&lt;")
+            .addEscape('>', "&gt;")
+            .addEscape('&', "&amp;")
+            .addEscape('@', "&#64;").build();
+    private static final Pattern TAIL_COMMENT_PATTERN = Pattern.compile("*/", Pattern.LITERAL);
+
+    /**
+     * Create a {@link TypeComment} for a javadoc-compliant text snippet. This snippet must be eligible for direct
+     * inclusion in a Java comment without further escaping.
+     *
+     * @param javadoc Pre-formatted javadoc snippet
+     * @return {@link TypeComment}, or empty if the snippet was empty
+     */
+    public static Optional<TypeComment> javadoc(final String javadoc) {
+        return javadoc.isEmpty() ? Optional.empty() : Optional.of(() -> javadoc);
+    }
+
+    /**
+     * Create a {@link TypeComment} for a {@link DocumentedNode}'s description string.
+     *
+     * @param node Documented node containing the description to be processed
+     * @return {@link TypeComment}, or empty if the node's description was empty or non-present.
+     */
+    public static Optional<TypeComment> description(final DocumentedNode node) {
+        final String description = node.getDescription().orElse("");
+        return description.isEmpty() ? Optional.empty() : Optional.of(() -> replaceAllIllegalChars(
+            formatToParagraph(
+                TAIL_COMMENT_PATTERN.matcher(ENTITY_ESCAPER.escape(description)).replaceAll("&#42;&#47;"), 0)));
+    }
+}
index 1d31ea274b932cf650d08c6479e80379feeba0df..e2ce4f36ac3cea5089ed2586efca3e753066ea23 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.mdsal.binding.model.util.generated.type.builder;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Optional;
 import org.opendaylight.mdsal.binding.model.api.AnnotationType;
 import org.opendaylight.mdsal.binding.model.api.Constant;
 import org.opendaylight.mdsal.binding.model.api.Enumeration;
@@ -17,6 +18,8 @@ import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
 import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.mdsal.binding.model.api.TypeComment;
+import org.opendaylight.mdsal.binding.model.api.YangSourceDefinition;
 import org.opendaylight.mdsal.binding.model.api.type.builder.AnnotationTypeBuilder;
 import org.opendaylight.mdsal.binding.model.api.type.builder.EnumBuilder;
 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder;
@@ -28,7 +31,7 @@ import org.opendaylight.mdsal.binding.model.util.AbstractBaseType;
 abstract class AbstractGeneratedType extends AbstractBaseType implements GeneratedType {
 
     private final Type parent;
-    private final String comment;
+    private final TypeComment comment;
     private final List<AnnotationType> annotations;
     private final List<Type> implementsTypes;
     private final List<Enumeration> enumerations;
@@ -37,6 +40,7 @@ abstract class AbstractGeneratedType extends AbstractBaseType implements Generat
     private final List<GeneratedType> enclosedTypes;
     private final List<GeneratedProperty> properties;
     private final boolean isAbstract;
+    private final YangSourceDefinition definition;
 
     public AbstractGeneratedType(final AbstractGeneratedTypeBuilder<?> builder) {
         super(builder.getPackageName(), builder.getName());
@@ -51,10 +55,11 @@ abstract class AbstractGeneratedType extends AbstractBaseType implements Generat
                 builder.getEnclosedTransferObjects());
         this.properties = toUnmodifiableProperties(builder.getProperties());
         this.isAbstract = builder.isAbstract();
+        this.definition = builder.getYangSourceDefinition().orElse(null);
     }
 
-    public AbstractGeneratedType(final Type parent, final String packageName, final String name, final String comment,
-            final List<AnnotationTypeBuilder> annotationBuilders, final boolean isAbstract,
+    public AbstractGeneratedType(final Type parent, final String packageName, final String name,
+            final TypeComment comment, final List<AnnotationTypeBuilder> annotationBuilders, final boolean isAbstract,
             final List<Type> implementsTypes, final List<GeneratedTypeBuilder> enclosedGenTypeBuilders,
             final List<GeneratedTOBuilder> enclosedGenTOBuilders, final List<EnumBuilder> enumBuilders,
             final List<Constant> constants, final List<MethodSignatureBuilder> methodBuilders,
@@ -70,6 +75,7 @@ abstract class AbstractGeneratedType extends AbstractBaseType implements Generat
         this.enclosedTypes = toUnmodifiableEnclosedTypes(enclosedGenTypeBuilders, enclosedGenTOBuilders);
         this.properties = toUnmodifiableProperties(propertyBuilders);
         this.isAbstract = isAbstract;
+        this.definition = null;
     }
 
     protected static final <T> List<T> makeUnmodifiable(final List<T> list) {
@@ -139,7 +145,7 @@ abstract class AbstractGeneratedType extends AbstractBaseType implements Generat
     }
 
     @Override
-    public final String getComment() {
+    public final TypeComment getComment() {
         return this.comment;
     }
 
@@ -183,6 +189,11 @@ abstract class AbstractGeneratedType extends AbstractBaseType implements Generat
         return this.properties;
     }
 
+    @Override
+    public final Optional<YangSourceDefinition> getYangSourceDefinition() {
+        return Optional.ofNullable(definition);
+    }
+
     @Override
     public String toString() {
         final StringBuilder builder = new StringBuilder();
index 4fb8d493907124f07167b2c8632509a8f72a0772..a4eff6bd29d442c12b57a861f86ea95ce009a2d2 100644 (file)
@@ -11,9 +11,12 @@ import com.google.common.base.Preconditions;
 import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
+import java.util.Optional;
 import org.opendaylight.mdsal.binding.model.api.AccessModifier;
 import org.opendaylight.mdsal.binding.model.api.Constant;
 import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.mdsal.binding.model.api.TypeComment;
+import org.opendaylight.mdsal.binding.model.api.YangSourceDefinition;
 import org.opendaylight.mdsal.binding.model.api.type.builder.AnnotationTypeBuilder;
 import org.opendaylight.mdsal.binding.model.api.type.builder.EnumBuilder;
 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder;
@@ -24,7 +27,8 @@ import org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuil
 import org.opendaylight.mdsal.binding.model.util.AbstractBaseType;
 import org.opendaylight.yangtools.util.LazyCollections;
 
-abstract class AbstractGeneratedTypeBuilder<T extends GeneratedTypeBuilderBase<T>> extends AbstractBaseType implements GeneratedTypeBuilderBase<T> {
+abstract class AbstractGeneratedTypeBuilder<T extends GeneratedTypeBuilderBase<T>> extends AbstractBaseType
+        implements GeneratedTypeBuilderBase<T> {
 
     private List<AnnotationTypeBuilder> annotationBuilders = Collections.emptyList();
     private List<Type> implementsTypes = Collections.emptyList();
@@ -34,14 +38,15 @@ abstract class AbstractGeneratedTypeBuilder<T extends GeneratedTypeBuilderBase<T
     private final List<GeneratedTypeBuilder> enclosedTypes = Collections.emptyList();
     private List<GeneratedTOBuilder> enclosedTransferObjects = Collections.emptyList();
     private List<GeneratedPropertyBuilder> properties = Collections.emptyList();
-    private String comment = "";
+    private TypeComment comment;
     private boolean isAbstract;
+    private YangSourceDefinition yangSourceDefinition;
 
     protected AbstractGeneratedTypeBuilder(final String packageName, final String name) {
         super(packageName, name);
     }
 
-    protected String getComment() {
+    protected TypeComment getComment() {
         return this.comment;
     }
 
@@ -87,7 +92,8 @@ abstract class AbstractGeneratedTypeBuilder<T extends GeneratedTypeBuilderBase<T
         Preconditions.checkArgument(name != null, "Name for Enclosing Generated Transfer Object cannot be null!");
         final GeneratedTOBuilder builder = new GeneratedTOBuilderImpl(getFullyQualifiedName(), name);
 
-        Preconditions.checkArgument(!this.enclosedTransferObjects.contains(builder), "This generated type already contains equal enclosing transfer object.");
+        Preconditions.checkArgument(!this.enclosedTransferObjects.contains(builder),
+            "This generated type already contains equal enclosing transfer object.");
         this.enclosedTransferObjects = LazyCollections.lazyAdd(this.enclosedTransferObjects, builder);
         return builder;
     }
@@ -95,14 +101,15 @@ abstract class AbstractGeneratedTypeBuilder<T extends GeneratedTypeBuilderBase<T
     @Override
     public T addEnclosingTransferObject(final GeneratedTOBuilder genTOBuilder) {
         Preconditions.checkArgument(genTOBuilder != null, "Parameter genTOBuilder cannot be null!");
-        Preconditions.checkArgument(!this.enclosedTransferObjects.contains(genTOBuilder), "This generated type already contains equal enclosing transfer object.");
+        Preconditions.checkArgument(!this.enclosedTransferObjects.contains(genTOBuilder),
+            "This generated type already contains equal enclosing transfer object.");
         this.enclosedTransferObjects = LazyCollections.lazyAdd(this.enclosedTransferObjects, genTOBuilder);
         return thisInstance();
     }
 
     @Override
-    public T addComment(final String comment) {
-        this.comment = comment;
+    public T addComment(final TypeComment comment) {
+        this.comment = Preconditions.checkNotNull(comment);
         return thisInstance();
     }
 
@@ -113,7 +120,8 @@ abstract class AbstractGeneratedTypeBuilder<T extends GeneratedTypeBuilderBase<T
 
         final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(packageName, name);
 
-        Preconditions.checkArgument(!this.annotationBuilders.contains(builder), "This generated type already contains equal annotation.");
+        Preconditions.checkArgument(!this.annotationBuilders.contains(builder),
+            "This generated type already contains equal annotation.");
         this.annotationBuilders = LazyCollections.lazyAdd(this.annotationBuilders, builder);
         return builder;
     }
@@ -127,7 +135,8 @@ abstract class AbstractGeneratedTypeBuilder<T extends GeneratedTypeBuilderBase<T
     @Override
     public T addImplementsType(final Type genType) {
         Preconditions.checkArgument(genType != null, "Type cannot be null");
-        Preconditions.checkArgument(!this.implementsTypes.contains(genType), "This generated type already contains equal implements type.");
+        Preconditions.checkArgument(!this.implementsTypes.contains(genType),
+            "This generated type already contains equal implements type.");
         this.implementsTypes = LazyCollections.lazyAdd(this.implementsTypes, genType);
         return thisInstance();
     }
@@ -136,7 +145,8 @@ abstract class AbstractGeneratedTypeBuilder<T extends GeneratedTypeBuilderBase<T
     public Constant addConstant(final Type type, final String name, final Object value) {
         Preconditions.checkArgument(type != null, "Returning Type for Constant cannot be null!");
         Preconditions.checkArgument(name != null, "Name of constant cannot be null!");
-        Preconditions.checkArgument(!containsConstant(name), "This generated type already contains constant with the same name.");
+        Preconditions.checkArgument(!containsConstant(name),
+            "This generated type already contains constant with the same name.");
 
         final Constant constant = new ConstantImpl(this, type, name, value);
         this.constants = LazyCollections.lazyAdd(this.constants, constant);
@@ -158,7 +168,8 @@ abstract class AbstractGeneratedTypeBuilder<T extends GeneratedTypeBuilderBase<T
         Preconditions.checkArgument(name != null, "Name of enumeration cannot be null!");
         final EnumBuilder builder = new EnumerationBuilderImpl(getFullyQualifiedName(), name);
 
-        Preconditions.checkArgument(!this.enumDefinitions.contains(builder), "This generated type already contains equal enumeration.");
+        Preconditions.checkArgument(!this.enumDefinitions.contains(builder),
+            "This generated type already contains equal enumeration.");
         this.enumDefinitions = LazyCollections.lazyAdd(this.enumDefinitions, builder);
         return builder;
     }
@@ -187,7 +198,8 @@ abstract class AbstractGeneratedTypeBuilder<T extends GeneratedTypeBuilderBase<T
     @Override
     public GeneratedPropertyBuilder addProperty(final String name) {
         Preconditions.checkArgument(name != null, "Parameter name can't be null");
-        Preconditions.checkArgument(!containsProperty(name), "This generated type already contains property with the same name.");
+        Preconditions.checkArgument(!containsProperty(name),
+            "This generated type already contains property with the same name.");
 
         final GeneratedPropertyBuilder builder = new GeneratedPropertyBuilderImpl(name);
         builder.setAccessModifier(AccessModifier.PUBLIC);
@@ -206,12 +218,32 @@ abstract class AbstractGeneratedTypeBuilder<T extends GeneratedTypeBuilderBase<T
         return false;
     }
 
+    public Type getParent() {
+        return null;
+    }
+
+    @Override
+    public List<GeneratedPropertyBuilder> getProperties() {
+        return this.properties;
+    }
+
+    @Override
+    public Optional<YangSourceDefinition> getYangSourceDefinition() {
+        return Optional.ofNullable(yangSourceDefinition);
+    }
+
+
+    @Override
+    public void setYangSourceDefinition(final YangSourceDefinition definition) {
+        yangSourceDefinition = Preconditions.checkNotNull(definition);
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = (prime * result) + Objects.hashCode(getName());
-        result = (prime * result) + Objects.hashCode(getPackageName());
+        result = prime * result + Objects.hashCode(getName());
+        result = prime * result + Objects.hashCode(getPackageName());
         return result;
     }
 
@@ -229,13 +261,4 @@ abstract class AbstractGeneratedTypeBuilder<T extends GeneratedTypeBuilderBase<T
         final AbstractGeneratedTypeBuilder<?> other = (AbstractGeneratedTypeBuilder<?>) obj;
         return Objects.equals(getName(), other.getName()) && Objects.equals(getPackageName(), other.getPackageName());
     }
-
-    public Type getParent() {
-        return null;
-    }
-
-    @Override
-    public List<GeneratedPropertyBuilder> getProperties() {
-        return this.properties;
-    }
 }
index 0eaac9ec98e481f5e025b68c94415813c1ee600f..4527f22e534ceb123bf940b302711ec59733f483 100644 (file)
@@ -21,6 +21,8 @@ import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
 import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.mdsal.binding.model.api.TypeComment;
+import org.opendaylight.mdsal.binding.model.api.YangSourceDefinition;
 import org.opendaylight.mdsal.binding.model.api.type.builder.AnnotationTypeBuilder;
 import org.opendaylight.mdsal.binding.model.api.type.builder.EnumBuilder;
 import org.opendaylight.mdsal.binding.model.util.AbstractBaseType;
@@ -319,7 +321,7 @@ public final class EnumerationBuilderImpl extends AbstractBaseType implements En
         }
 
         @Override
-        public String getComment() {
+        public TypeComment getComment() {
             return null;
         }
 
@@ -377,5 +379,11 @@ public final class EnumerationBuilderImpl extends AbstractBaseType implements En
         public String getModuleName() {
             return this.moduleName;
         }
+
+        @Override
+        public Optional<YangSourceDefinition> getYangSourceDefinition() {
+            // TODO Auto-generated method stub
+            return Optional.empty();
+        }
     }
 }
index f718c8b687c06e60f3e060ea72adf52095d563d8..576ba55f8b6ffd1d495c8d7a1fe28e7cee61ea1a 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.mdsal.binding.model.util.generated.type.builder;
 
 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
+import org.opendaylight.mdsal.binding.model.api.TypeComment;
 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
 import org.opendaylight.yangtools.yang.common.QName;
 
@@ -56,8 +57,12 @@ public final class GeneratedTypeBuilderImpl extends AbstractGeneratedTypeBuilder
         builder.append(getPackageName());
         builder.append(", name=");
         builder.append(getName());
-        builder.append(", comment=");
-        builder.append(getComment());
+
+        final TypeComment comment = getComment();
+        if (comment != null) {
+            builder.append(", comment=");
+            builder.append(comment.getJavadoc());
+        }
         builder.append(", annotations=");
         builder.append(getAnnotations());
         builder.append(", implements=");
index 861449dbb86875b985a9f507031d9f96ecf8468f..fbd1b67c879c10f512aa2a15f48fadc579975259 100644 (file)
@@ -367,4 +367,12 @@ public class BindingGeneratorUtilTest {
         assertFalse(restrictions.getLengthConstraint().isPresent());
         assertTrue(restrictions.getPatternConstraints().isEmpty());
     }
+
+    @Test
+    public void unicodeCharReplaceTest() {
+        String inputString = "abcu\\uuuuu\\uuua\\u\\\\uabc\\\\uuuu\\\\\\uuuu\\\\\\\\uuuu///uu/u/u/u/u/u/u";
+
+        assertEquals("abcu\\\\uuuuu\\\\uuua\\\\u\\\\uabc\\\\uuuu\\\\uuuu\\\\uuuu///uu/u/u/u/u/u/u",
+            BindingGeneratorUtil.replaceAllIllegalChars(inputString));
+    }
 }
index ebcaa626ecbe11c8aef6fcff91b7bbf20d84c003..e12819c5fec9d58fbc7a6c5fe1f9999bce8e6b11 100644 (file)
@@ -27,6 +27,7 @@ import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTOBuilder;
 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
 import org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder;
 import org.opendaylight.mdsal.binding.model.util.BindingGeneratorUtil;
+import org.opendaylight.mdsal.binding.model.util.TypeComments;
 import org.opendaylight.mdsal.binding.model.util.Types;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
@@ -291,7 +292,7 @@ public class GeneratedTypeBuilderTest {
         generatedTypeBuilder.setModuleName("myModuleName");
         generatedTypeBuilder.setReference("myReference");
         generatedTypeBuilder.setSchemaPath(SchemaPath.create(true, QName.create("test", "/path")).getPathFromRoot());
-        assertNotNull(generatedTypeBuilder.addComment("My comment.."));
+        assertNotNull(generatedTypeBuilder.addComment(TypeComments.javadoc("My comment..").get()));
 
         assertEquals(
                 "GeneratedTransferObject [packageName=my.package, name=MyName, comment=My comment.., annotations=[], implements=[], enclosedTypes=[], constants=[], enumerations=[], properties=, methods=[]]",
@@ -303,6 +304,6 @@ public class GeneratedTypeBuilderTest {
         assertEquals("myModuleName", instance.getModuleName());
         assertEquals("myReference", instance.getReference());
         assertEquals(SchemaPath.create(true, QName.create("test", "/path")).getPathFromRoot(), instance.getSchemaPath());
-        assertEquals("My comment..", instance.getComment());
+        assertEquals("My comment..", instance.getComment().getJavadoc());
     }
 }
index 000dc9d116e1fbcd321e767baee640824af2ebae..f9652b65d5912539175fe0557bedf79cfc3d4bad 100644 (file)
@@ -7,8 +7,11 @@
  */
 package org.opendaylight.mdsal.binding.java.api.generator
 
+import static org.opendaylight.mdsal.binding.model.util.BindingGeneratorUtil.encodeAngleBrackets
+
 import com.google.common.base.CharMatcher
 import com.google.common.base.Splitter
+import com.google.common.collect.Iterables
 import java.util.Arrays
 import java.util.Collection
 import java.util.HashMap
@@ -16,7 +19,6 @@ import java.util.List
 import java.util.Map
 import java.util.StringTokenizer
 import java.util.regex.Pattern
-import org.opendaylight.yangtools.yang.common.QName
 import org.opendaylight.mdsal.binding.model.api.ConcreteType
 import org.opendaylight.mdsal.binding.model.api.Constant
 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty
@@ -26,7 +28,16 @@ import org.opendaylight.mdsal.binding.model.api.MethodSignature
 import org.opendaylight.mdsal.binding.model.api.Restrictions
 import org.opendaylight.mdsal.binding.model.api.Type
 import org.opendaylight.mdsal.binding.model.api.TypeMember
+import org.opendaylight.mdsal.binding.model.api.YangSourceDefinition.Single
+import org.opendaylight.mdsal.binding.model.api.YangSourceDefinition.Multiple
 import org.opendaylight.mdsal.binding.model.util.Types
+import org.opendaylight.yangtools.yang.common.QName
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode
+import org.opendaylight.yangtools.yang.model.api.DocumentedNode
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition
+import org.opendaylight.yangtools.yang.model.api.SchemaNode
 
 abstract class BaseTemplate {
     protected val GeneratedType type;
@@ -209,40 +220,117 @@ abstract class BaseTemplate {
     }
 
     def protected String formatDataForJavaDoc(GeneratedType type) {
-        val typeDescription = type.getDescription().encodeJavadocSymbols;
+        val sb = new StringBuilder()
+        val comment = type.comment
+        if (comment !== null) {
+            sb.append(comment.javadoc)
+        }
+
+        appendSnippet(sb, type)
 
         return '''
-            «IF !typeDescription.nullOrEmpty»
-            «typeDescription»
+            «IF sb.length != 0»
+            «sb.toString»
             «ENDIF»
         '''.toString
     }
 
-    private static final CharMatcher AMP_MATCHER = CharMatcher.is('&');
+    private static val AMP_MATCHER = CharMatcher.is('&')
 
-    def encodeJavadocSymbols(String description) {
+    def static encodeJavadocSymbols(String description) {
         if (description.nullOrEmpty) {
             return description;
         }
 
-        return AMP_MATCHER.replaceFrom(TAIL_COMMENT_PATTERN.matcher(description).replaceAll("&#42;&#47;"), "&amp;");
+        return TAIL_COMMENT_PATTERN.matcher(AMP_MATCHER.replaceFrom(description, "&amp;")).replaceAll("&#42;&#47;")
     }
 
     def protected String formatDataForJavaDoc(GeneratedType type, String additionalComment) {
-        val StringBuilder typeDescription = new StringBuilder();
-        if (!type.description.nullOrEmpty) {
-            typeDescription.append(type.description)
-            typeDescription.append(NEW_LINE)
-            typeDescription.append(NEW_LINE)
-            typeDescription.append(NEW_LINE)
-            typeDescription.append(additionalComment)
-        } else {
-            typeDescription.append(additionalComment)
+        val comment = type.comment
+        if (comment === null) {
+            return '''
+                «additionalComment»
+            '''
         }
 
+        val sb = new StringBuilder().append(comment.javadoc)
+        appendSnippet(sb, type)
+
+        sb.append(NEW_LINE)
+        .append(NEW_LINE)
+        .append(NEW_LINE)
+        .append(additionalComment)
+
         return '''
-            «typeDescription.toString»
-        '''.toString
+            «sb.toString»
+        '''
+    }
+
+    def private static void appendSnippet(StringBuilder sb, GeneratedType type) {
+        val optDef = type.yangSourceDefinition
+        if (optDef.present) {
+            val def = optDef.get
+            sb.append(NEW_LINE)
+
+               if (def instanceof Single) {
+                val node = def.node
+                sb.append("<p>\n")
+                .append("This class represents the following YANG schema fragment defined in module <b>")
+                .append(def.module.name).append("</b>\n")
+                .append("<pre>\n")
+                .append(encodeAngleBrackets(encodeJavadocSymbols(YangTemplate.generateYangSnippet(node))))
+                .append("</pre>")
+
+                if (node instanceof SchemaNode) {
+                    sb.append("The schema path to identify an instance is\n")
+                    .append("<i>")
+                    .append(formatSchemaPath(def.module.name, node.path.pathFromRoot))
+                    .append("</i>\n")
+
+                    if (hasBuilderClass(node)) {
+                        val builderName = type.name + "Builder";
+
+                        sb.append("\n<p>To create instances of this class use {@link ").append(builderName)
+                        .append("}.\n")
+                        .append("@see ").append(builderName).append('\n')
+                        if (node instanceof ListSchemaNode) {
+                            val keyDef = node.keyDefinition
+                            if (keyDef !== null && !keyDef.empty) {
+                                sb.append("@see ").append(type.name).append("Key")
+                            }
+                            sb.append('\n');
+                        }
+                    }
+                }
+               } else if (def instanceof Multiple) {
+                sb.append("<pre>\n")
+                for (DocumentedNode schemaNode : def.nodes) {
+                    sb.append(encodeAngleBrackets(encodeJavadocSymbols(YangTemplate.generateYangSnippet(schemaNode))))
+                }
+                sb.append("</pre>\n")
+            }
+        }
+    }
+
+    def private static boolean hasBuilderClass(SchemaNode schemaNode) {
+        return schemaNode instanceof ContainerSchemaNode || schemaNode instanceof ListSchemaNode
+                || schemaNode instanceof RpcDefinition || schemaNode instanceof NotificationDefinition;
+    }
+
+    def private static String formatSchemaPath(String moduleName, Iterable<QName> schemaPath) {
+        val sb = new StringBuilder().append(moduleName);
+
+        var currentElement = Iterables.getFirst(schemaPath, null);
+        for (QName pathElement : schemaPath) {
+            sb.append('/')
+            if (!currentElement.namespace.equals(pathElement.namespace)) {
+                currentElement = pathElement
+                sb.append(pathElement)
+            } else {
+                sb.append(pathElement.getLocalName())
+            }
+        }
+        return sb.toString();
     }
 
     def protected String formatDataForJavaDoc(TypeMember type, String additionalComment) {
index ace7b17b007374460129ae30d3e7a69b5ab1ad95..e38544e910d526e95c69c938fbcfe6fab92e623f 100644 (file)
@@ -11,7 +11,6 @@ import java.util.Collection
 import java.util.List
 import java.util.Map
 import java.util.Set
-import org.opendaylight.mdsal.binding.generator.spi.YangTextSnippetProvider
 import org.opendaylight.mdsal.binding.model.util.FormattingUtils
 import org.opendaylight.yangtools.yang.common.Revision
 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode
@@ -21,6 +20,7 @@ import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode
 import org.opendaylight.yangtools.yang.model.api.Deviation
+import org.opendaylight.yangtools.yang.model.api.DocumentedNode
 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition
 import org.opendaylight.yangtools.yang.model.api.FeatureDefinition
 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition
@@ -41,7 +41,7 @@ import org.opendaylight.yangtools.yang.model.api.UsesNode
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair
 
-final class YangTemplate implements YangTextSnippetProvider {
+final class YangTemplate {
 
     private static val String SKIP_PROPERTY_NAME = "mdsal.skip.verbose"
 
@@ -49,13 +49,7 @@ final class YangTemplate implements YangTextSnippetProvider {
 
     private static val SKIPPED_EMPTY = '''(Empty due to «SKIP_PROPERTY_NAME» property = true)'''
 
-    private static val INSTANCE = new YangTemplate();
-
-    def static YangTemplate getInstance() {
-        return INSTANCE;
-    }
-
-    override String generateYangSnippet(Module module) {
+    def static String generateYangSnippet(Module module) {
         if (SKIP)
             return SKIPPED_EMPTY
         '''
@@ -118,9 +112,11 @@ final class YangTemplate implements YangTextSnippetProvider {
         '''
     }
 
-    override String generateYangSnippet(SchemaNode schemaNode) {
+    def static String generateYangSnippet(DocumentedNode schemaNode) {
         if (schemaNode === null)
             return ''
+        if (schemaNode instanceof Module)
+            return generateYangSnippet(schemaNode)
         if (SKIP)
             return SKIPPED_EMPTY
         '''
index b89b0706324f0dce32fd7dca6df1f3bd858f143e..cb95792066d44dd77ebc3b7ed0627d7f554cd35e 100644 (file)
@@ -13,7 +13,6 @@ import org.junit.Before;
 import org.junit.BeforeClass;
 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
 import org.opendaylight.mdsal.binding.generator.impl.BindingGeneratorImpl;
-import org.opendaylight.mdsal.binding.java.api.generator.YangTemplate;
 
 public abstract class BaseCompilationTest {
 
@@ -30,7 +29,7 @@ public abstract class BaseCompilationTest {
 
     @Before
     public void init() {
-        bindingGenerator = new BindingGeneratorImpl(YangTemplate.getInstance());
+        bindingGenerator = new BindingGeneratorImpl();
     }
 
 }
index 230dc9b0a2fc3bafa6f7781638bf473fb0b8770f..2bdb36cd938a7016cdd58b5b8b738527004d1276 100644 (file)
@@ -17,7 +17,6 @@ import org.junit.Test;
 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
 import org.opendaylight.mdsal.binding.generator.impl.BindingGeneratorImpl;
 import org.opendaylight.mdsal.binding.java.api.generator.TOGenerator;
-import org.opendaylight.mdsal.binding.java.api.generator.YangTemplate;
 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
@@ -36,7 +35,7 @@ public class ClassCodeGeneratorTest {
         final SchemaContext context = YangParserTestUtils.parseYangResource("/list-composite-key.yang");
 
         assertNotNull(context);
-        final BindingGenerator bindingGen = new BindingGeneratorImpl(YangTemplate.getInstance());
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
         assertTrue(genTypes != null);