Use properly module file path resolver 90/62990/9
authorMartin Ciglan <martin.ciglan@pantheon.tech>
Mon, 11 Sep 2017 16:45:09 +0000 (18:45 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 12 Sep 2017 21:12:05 +0000 (21:12 +0000)
in binding2 Twirl template.

- fix implementation
- checkstyle fixes

Change-Id: I14aca1517cb1f5d6087b38791b298b4ec096509d
Signed-off-by: Martin Ciglan <martin.ciglan@pantheon.tech>
binding2/mdsal-binding2-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/javav2/java/api/generator/renderers/BaseRenderer.java
binding2/mdsal-binding2-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/javav2/java/api/generator/renderers/BuilderRenderer.java
binding2/mdsal-binding2-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/javav2/java/api/generator/renderers/EnumRenderer.java
binding2/mdsal-binding2-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/javav2/java/api/generator/renderers/YangModuleInfoTemplateRenderer.java
binding2/mdsal-binding2-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/javav2/java/api/generator/util/AlphabeticallyTypeMemberComparator.java
binding2/mdsal-binding2-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/javav2/java/api/generator/util/TextTemplateUtil.java
binding2/mdsal-binding2-java-api-generator/src/main/twirl/org/opendaylight/mdsal/binding/javav2/java/api/generator/yangModuleInfoTemplate.scala.txt

index 4c5726db0fee5cde2bee76c002a6a7ed803d5b85..cdf6f13108aa47c4d8bfbed8754124857fa101f9 100644 (file)
@@ -245,7 +245,7 @@ public abstract class BaseRenderer {
     }
 
     /**
-     * @param constant
+     * @param constant constant to emit
      * @return string with constant wrapped in code
      */
     protected String emitConstant(final Constant constant) {
index 31e3520f55db18f8ccfb1b6db42c017916a5281f..bd7e75a0908fee306ab08b592e4997b1e9ba4107 100644 (file)
@@ -248,6 +248,9 @@ public class BuilderRenderer extends BaseRenderer {
 
     /**
      * Method is used to find out if given type implements any interface from uses.
+     *
+     * @param type type to inspect
+     * @return has implements from uses-stmt true/false
      */
     public static boolean hasImplementsFromUses(GeneratedType type) {
         for (Type impl : getAllIfcs(type)) {
index 7aa07f46bd77ee20817b2d62bb82d60f628d283f..b70009c601723ee3748ab691df0f7609b81e10c2 100644 (file)
@@ -31,7 +31,7 @@ public class EnumRenderer extends BaseRenderer {
     }
 
     /**
-     * @param enumeration
+     * @param enumeration enumeration to write
      * @return List of enumeration pairs with javadoc
      */
     public static String writeEnumeration(final Enumeration enumeration) {
index 0d58154f199543a9fde6d13e862ace6f6d81969d..ebb1e7f2295efd32b4aa2420f2969510e729dfed 100644 (file)
@@ -82,7 +82,7 @@ public class YangModuleInfoTemplateRenderer {
         importedNames.put("semVer", importedName(SemVer.class));
         importedNames.put("schemaSourceRepresentation", importedName(SchemaSourceRepresentation.class));
 
-        return yangModuleInfoTemplate.render(module, ctx, importedNames).body();
+        return yangModuleInfoTemplate.render(module, ctx, importedNames, moduleFilePathResolver).body();
     }
 
     /**
index e55eac7d78bad44ce0867ce995756af85a449c82..a539c9064333ddb9d45a521c4c0d0a6a0b65774f 100644 (file)
@@ -15,7 +15,7 @@ import org.opendaylight.mdsal.binding.javav2.model.api.TypeMember;
  * Alphabetically type member {@link Comparator} which provides sorting by name for type members
  * (variables and methods) in generated class.
  *
- * @param <T>
+ * @param <T> type
  */
 public class AlphabeticallyTypeMemberComparator<T extends TypeMember> implements Comparator<T>{
 
index 654767e27bbd2546f2049438085b69adc30ab5af..5eaca3cfa07c2c514ae516648f68d5e1ecc25ffa 100644 (file)
@@ -15,7 +15,9 @@ import com.google.common.base.Strings;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import java.util.List;
+import java.util.Optional;
 import java.util.StringTokenizer;
+import java.util.function.Function;
 import java.util.regex.Pattern;
 import org.opendaylight.mdsal.binding.javav2.generator.util.Types;
 import org.opendaylight.mdsal.binding.javav2.model.api.AccessModifier;
@@ -89,7 +91,7 @@ public final class TextTemplateUtil {
 
     /**
      * Returns formatted Javadoc, based on type
-     * @param typeName
+     * @param typeName given type name
      * @return formatted Javadoc, based on type
      */
     public static String formatDataForJavaDocBuilder(final String typeName) {
@@ -105,8 +107,8 @@ public final class TextTemplateUtil {
 
     /**
      * Returns formatted Javadoc with possible additional comment, based on type
-     * @param type
-     * @param additionalComment
+     * @param type given type
+     * @param additionalComment additional comment to format
      * @return formatted Javadoc with possible additional comment, based on type
      */
     public static String formatDataForJavaDoc(final GeneratedType type, final String additionalComment) {
@@ -123,7 +125,7 @@ public final class TextTemplateUtil {
 
     /**
      * Returns properties names in formatted string
-     * @param properties
+     * @param properties list of given properties
      * @return properties names in formatted string
      */
     //FIXME: this needs further clarification in future patch
@@ -133,7 +135,7 @@ public final class TextTemplateUtil {
 
     /**
      * Returns formatted type description
-     * @param type
+     * @param type given type
      * @return formatted type description
      */
     public static String formatDataForJavaDoc(final GeneratedType type) {
@@ -142,8 +144,8 @@ public final class TextTemplateUtil {
 
     /**
      * Returns parameter name, based on given Type
-     * @param returnType
-     * @param paramName
+     * @param returnType given type
+     * @param paramName parameter name
      * @return parameter name, based on given Type
      */
     public static String paramValue(final Type returnType, final String paramName) {
@@ -174,7 +176,7 @@ public final class TextTemplateUtil {
 
     /**
      * Returns related Javadoc
-     * @param methodSignature
+     * @param methodSignature method signature
      * @return related Javadoc
      */
     public static String getJavaDocForInterface(final MethodSignature methodSignature) {
@@ -211,7 +213,7 @@ public final class TextTemplateUtil {
 
     /**
      * Returns collection of properties as formatted String
-     * @param properties
+     * @param properties list of given properties
      * @return generated properties as formatted String
      */
     public static String propsAsArgs(final Iterable<GeneratedProperty> properties) {
@@ -220,8 +222,8 @@ public final class TextTemplateUtil {
 
     /**
      * Returns properties as formatted String
-     * @param properties
-     * @param booleanName
+     * @param properties list of given properties
+     * @param booleanName Java Boolean type name
      * @return Properties as formatted String
      */
     public static String propsAsList(final Iterable<GeneratedProperty> properties, final String booleanName) {
@@ -231,7 +233,7 @@ public final class TextTemplateUtil {
 
     /**
      * Extracts available restrictions from given type
-     * @param currentType
+     * @param currentType given type
      * @return restrictions from given type
      */
     public static Restrictions getRestrictions(final Type currentType) {
@@ -249,6 +251,7 @@ public final class TextTemplateUtil {
      * method(type fieldname)
      *
      * @param property type from getter
+     * @return underscored string form
      */
     public static String fieldName(final GeneratedProperty property) {
         final String name = Preconditions.checkNotNull(property.getName());
@@ -256,7 +259,7 @@ public final class TextTemplateUtil {
     }
 
     /**
-     * Template method which generates sequence of the names of the class attributes
+     * Template method which generates sequence of the names of the class attributes.
      *
      * @param parameters group of generated property instances which are transformed to the sequence of parameter names
      * @return string with the list of the parameter names
@@ -266,10 +269,10 @@ public final class TextTemplateUtil {
     }
 
     /**
-     * Helper method for building getter
+     * Helper method for building getter.
      *
      * @param field property name
-     * @return getter for propery
+     * @return getter for property
      */
     public static String getterMethodName(final GeneratedProperty field) {
         final Type type = Preconditions.checkNotNull(field.getReturnType());
@@ -279,10 +282,10 @@ public final class TextTemplateUtil {
     }
 
     /**
-     * Returns built setter method body
-     * @param field
-     * @param typeName
-     * @param returnTypeName
+     * Returns built setter method body from input parameters.
+     * @param field generated property
+     * @param typeName type name
+     * @param returnTypeName return type name
      * @return built setter method body
      */
     public static String setterMethod(final GeneratedProperty field, final String typeName, final String returnTypeName) {
@@ -319,7 +322,7 @@ public final class TextTemplateUtil {
     }
 
     /**
-     * Cuts prefix from getter name
+     * Cuts prefix from getter name.
      *
      * @param getter getter name
      * @return getter name without prefix
@@ -338,8 +341,8 @@ public final class TextTemplateUtil {
     }
 
     /**
-     * Returns list of properties as formatted String
-     * @param properties
+     * Returns list of properties as formatted String.
+     * @param properties input list of generated properties
      * @return formatted property list as String
      */
     public static String getPropertyList(final List<GeneratedProperty> properties) {
@@ -363,16 +366,21 @@ public final class TextTemplateUtil {
     }
 
     /**
-     * Returns source path as String
-     * @param module
+     * Returns source path as String.
+     * @param module module
+     * @param moduleFilePathResolver function module to module file path
      * @return formatted String source path
      */
-    public static String getSourcePath(final Module module) {
-        return "/".concat(module.getModuleSourcePath().replace(java.io.File.separatorChar, '/'));
+    public static String getSourcePath(final Module module, final Function<Module, Optional<String>> moduleFilePathResolver) {
+        final java.util.Optional<String> moduleFilePath = moduleFilePathResolver.apply(module);
+        Preconditions.checkArgument(moduleFilePath.isPresent(),"Module file path for %s is not present", module);
+
+        return moduleFilePath.get();
     }
 
     /**
-     * util method for unionTemplateBuilderTemplate
+     * Util method for unionTemplateBuilderTemplate.
+     * @param modifier enum representing Java access modifier
      * @return needed access modifier
      */
     public static String getAccessModifier(final AccessModifier modifier) {
index 4e752537bae3aafbccaec601a807416a106d1d5c..e2a7fedacac33c1ff323b257bd06cfeaaf2d6d54 100644 (file)
@@ -6,6 +6,8 @@
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  *@
 
+@import java.util.function.Function;
+@import java.util.Optional
 @import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifier.CLASS
 @import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifierNormalizer.normalizeSpecificIdentifier
 @import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifierNormalizer.normalizeFullPackageName
@@ -16,7 +18,8 @@
 @import org.opendaylight.yangtools.yang.model.api.Module
 @import org.opendaylight.yangtools.yang.model.api.SchemaContext
 
-@(module: Module, ctx: SchemaContext, importedNames: Map[String, String])
+@(module: Module, ctx: SchemaContext, importedNames: Map[String, String],
+moduleFilePathResolver: Function[Module, Optional[String]])
 @if(module != null && ctx != null) {
 public final class @{MODULE_INFO_CLASS_NAME} implements @{importedNames.get("yangModuleInfo")} {
 
@@ -26,7 +29,7 @@ public final class @{MODULE_INFO_CLASS_NAME} implements @{importedNames.get("yan
     private final @{importedNames.get("string")} namespace = "@{module.getNamespace.toString}";
     private final @{importedNames.get("string")} semanticVersion = "@{module.getSemanticVersion}";
     private final @{importedNames.get("string")} revision = "@{module.getQNameModule.getFormattedRevision}";
-    private final @{importedNames.get("string")} resourcePath = "@{getSourcePath(module)}";
+    private final @{importedNames.get("string")} resourcePath = "@{getSourcePath(module, moduleFilePathResolver)}";
     private final @{importedNames.get("set")}<YangModuleInfo> importedModules;
 
     public static @{importedNames.get("yangModuleInfo")} getInstance() {
@@ -47,7 +50,7 @@ public final class @{MODULE_INFO_CLASS_NAME} implements @{importedNames.get("yan
         private final @{importedNames.get("string")} semanticVersion = "@{submodule.getSemanticVersion}";
         private final @{importedNames.get("string")} namespace = "@{submodule.getNamespace.toString}";
         private final @{importedNames.get("string")} revision = "@{submodule.getQNameModule.getFormattedRevision}";
-        private final @{importedNames.get("string")} resourcePath = "@{getSourcePath(submodule)}";
+        private final @{importedNames.get("string")} resourcePath = "@{getSourcePath(submodule, moduleFilePathResolver)}";
         private final @{importedNames.get("set")}<YangModuleInfo> importedModules;
 
         public static @{importedNames.get("yangModuleInfo")} getInstance() {