You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2019/08/27 08:33:50 UTC
[plc4x] 01/02: - Adjusted the code generation to the latest changes
in the plc4x-maven-plugin
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit a7eefd63fe7a285fc4c01d57be838c21f0ba667d
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Tue Aug 27 10:32:43 2019 +0200
- Adjusted the code generation to the latest changes in the plc4x-maven-plugin
---
.../protocol/freemarker/FreemarkerLanguageOutput.java | 5 +++--
.../apache/plc4x/language/java/JavaLanguageTemplateHelper.java | 10 +++++++++-
.../src/main/resources/templates/java/active-io-template.ftlh | 10 +++++-----
.../src/main/resources/templates/java/passive-io-template.ftlh | 10 +++++-----
.../src/main/resources/templates/java/pojo-template.ftlh | 4 ++--
5 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/build-utils/language-base-freemarker/src/main/java/org/apache/plc4x/plugins/codegenerator/protocol/freemarker/FreemarkerLanguageOutput.java b/build-utils/language-base-freemarker/src/main/java/org/apache/plc4x/plugins/codegenerator/protocol/freemarker/FreemarkerLanguageOutput.java
index 6b69f20..7ae87a7 100644
--- a/build-utils/language-base-freemarker/src/main/java/org/apache/plc4x/plugins/codegenerator/protocol/freemarker/FreemarkerLanguageOutput.java
+++ b/build-utils/language-base-freemarker/src/main/java/org/apache/plc4x/plugins/codegenerator/protocol/freemarker/FreemarkerLanguageOutput.java
@@ -41,7 +41,7 @@ public abstract class FreemarkerLanguageOutput implements LanguageOutput {
private static final Logger LOGGER = LoggerFactory.getLogger(FreemarkerLanguageOutput.class);
@Override
- public void generate(File outputDir, String packageName, Map<String, ComplexTypeDefinition> types)
+ public void generate(File outputDir, String languageName, String protocolName, Map<String, ComplexTypeDefinition> types)
throws GenerationException {
try {
@@ -60,7 +60,8 @@ public abstract class FreemarkerLanguageOutput implements LanguageOutput {
// Prepare a new generation context
Map<String, Object> typeContext = new HashMap<>();
- typeContext.put("packageName", packageName);
+ typeContext.put("languageName", languageName);
+ typeContext.put("protocolName", protocolName);
typeContext.put("typeName", typeEntry.getKey());
typeContext.put("type", typeEntry.getValue());
typeContext.put("helper", getHelper(types));
diff --git a/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java b/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java
index 5f4685f..3dca032 100644
--- a/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java
+++ b/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java
@@ -46,6 +46,14 @@ public class JavaLanguageTemplateHelper implements FreemarkerLanguageTemplateHel
this.types = types;
}
+ public String languagePackageName(String languageName) {
+ return String.join("", languageName.split("\\-"));
+ }
+
+ public String protocolPackageName(String protocolName) {
+ return String.join("", protocolName.split("\\-"));
+ }
+
public String getLanguageTypeNameForField(TypedField field) {
boolean optional = field instanceof OptionalField;
return getLanguageTypeNameForField(!optional, field);
@@ -294,7 +302,7 @@ public class JavaLanguageTemplateHelper implements FreemarkerLanguageTemplateHel
return "writeUnsignedInt(" + simpleTypeReference.getSize() + ", ((Number) " + fieldName + ").intValue())";
}
if (simpleTypeReference.getSize() <= 32) {
- return "writeUnsignedLong(" + simpleTypeReference.getSize() + ", ((Number) " + fieldName + ").longValue()";
+ return "writeUnsignedLong(" + simpleTypeReference.getSize() + ", ((Number) " + fieldName + ").longValue())";
}
return "writeUnsignedBigInteger" + simpleTypeReference.getSize() + ", (BigInteger) " + fieldName + ")";
}
diff --git a/build-utils/language-java/src/main/resources/templates/java/active-io-template.ftlh b/build-utils/language-java/src/main/resources/templates/java/active-io-template.ftlh
index 50cafe8..3c0a8a1 100644
--- a/build-utils/language-java/src/main/resources/templates/java/active-io-template.ftlh
+++ b/build-utils/language-java/src/main/resources/templates/java/active-io-template.ftlh
@@ -16,7 +16,7 @@
specific language governing permissions and limitations
under the License.
-->
-${packageName?replace(".", "/")}/io/${typeName}IO.java
+org/apache/plc4x/${helper.languagePackageName(languageName)}/${helper.protocolPackageName(protocolName)}/io/${typeName}IO.java
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -36,10 +36,10 @@ ${packageName?replace(".", "/")}/io/${typeName}IO.java
under the License.
*/
-package ${packageName}.io;
+package org.apache.plc4x.${helper.languagePackageName(languageName)}.${helper.protocolPackageName(protocolName)}.io;
-import ${packageName}.*;
-<#if helper.getComplexTypes(type)?has_content>import ${packageName}.io.*;</#if>
+import org.apache.plc4x.${helper.languagePackageName(languageName)}.${helper.protocolPackageName(protocolName)}.*;
+<#if helper.getComplexTypes(type)?has_content>import org.apache.plc4x.${helper.languagePackageName(languageName)}.${helper.protocolPackageName(protocolName)}.io.*;</#if>
import org.apache.plc4x.java.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -226,7 +226,7 @@ public class ${typeName}IO implements MessageIO<${typeName}<#if helper.isDiscrim
<#case "optional">
// Optional Field (${field.name}) (Can be skipped, if a given expression evaluates to false)
- ${helper.getLanguageTypeNameForField(field)} ${field.name} = ${helper.getNullValueForType(field.type)};
+ ${helper.getLanguageTypeNameForField(field)} ${field.name} = null;
if(${helper.toDeserializationExpression(field.conditionExpression, type.parserArguments)?no_esc}) {
${field.name} = <#if helper.isSimpleType(field.type)>io.${helper.getReadBufferReadMethodCall(field.type)}<#else>${field.type.name?uncap_first}IO.parse(io);</#if>;
}
diff --git a/build-utils/language-java/src/main/resources/templates/java/passive-io-template.ftlh b/build-utils/language-java/src/main/resources/templates/java/passive-io-template.ftlh
index 92f63de..2807bb6 100644
--- a/build-utils/language-java/src/main/resources/templates/java/passive-io-template.ftlh
+++ b/build-utils/language-java/src/main/resources/templates/java/passive-io-template.ftlh
@@ -16,7 +16,7 @@
specific language governing permissions and limitations
under the License.
-->
-${packageName?replace(".", "/")}/io/${typeName}IO.java
+org/apache/plc4x/${helper.languagePackageName(languageName)}/${helper.protocolPackageName(protocolName)}/io/${typeName}IO.java
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -36,10 +36,10 @@ ${packageName?replace(".", "/")}/io/${typeName}IO.java
under the License.
*/
-package ${packageName}.io;
+package org.apache.plc4x.${helper.languagePackageName(languageName)}.${helper.protocolPackageName(protocolName)}.io;
-import ${packageName}.*;
-<#if helper.getComplexTypes(type)?has_content>import ${packageName}.io.*;</#if>
+import org.apache.plc4x.${helper.languagePackageName(languageName)}.${helper.protocolPackageName(protocolName)}.*;
+<#if helper.getComplexTypes(type)?has_content>import org.apache.plc4x.${helper.languagePackageName(languageName)}.${helper.protocolPackageName(protocolName)}.io.*;</#if>
import org.apache.plc4x.java.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -226,7 +226,7 @@ public class ${typeName}IO implements MessageInput<${typeName}<#if helper.isDisc
<#case "optional">
// Optional Field (${field.name}) (Can be skipped, if a given expression evaluates to false)
- ${helper.getLanguageTypeNameForField(field)} ${field.name} = ${helper.getNullValueForType(field.type)};
+ ${helper.getLanguageTypeNameForField(field)} ${field.name} = null;
if(${helper.toDeserializationExpression(field.conditionExpression, type.parserArguments)?no_esc}) {
${field.name} = <#if helper.isSimpleType(field.type)>io.${helper.getReadBufferReadMethodCall(field.type)}<#else>${field.type.name?uncap_first}IO.parse(io);</#if>;
}
diff --git a/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh b/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh
index 628e4ce..27d52d5 100644
--- a/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh
+++ b/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh
@@ -16,7 +16,7 @@
specific language governing permissions and limitations
under the License.
-->
-${packageName?replace(".", "/")}/${typeName}.java
+org/apache/plc4x/${helper.languagePackageName(languageName)}/${helper.protocolPackageName(protocolName)}/${typeName}.java
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -36,7 +36,7 @@ ${packageName?replace(".", "/")}/${typeName}.java
under the License.
*/
-package ${packageName};
+package org.apache.plc4x.${helper.languagePackageName(languageName)}.${helper.protocolPackageName(protocolName)};
import com.fasterxml.jackson.annotation.*;
import org.apache.plc4x.java.utils.Message;