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/07 08:47:51 UTC

[plc4x] 04/17: Merge branch 'develop' of https://github.com/apache/plc4x into implement-df1-protocol

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch feature/implement-df1-driver
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 17dc04f87e57782ec70816b337136d89fa89d768
Merge: 3ac2921 2b768c2
Author: v.emmert <v....@pragmaticminds.de>
AuthorDate: Tue Jul 30 14:54:49 2019 +0200

    Merge branch 'develop' of https://github.com/apache/plc4x into implement-df1-protocol

 .../freemarker/FreemarkerLanguageOutput.java       |  3 +-
 .../language/java/JavaLanguageTemplateHelper.java  | 30 ++++++++++-
 .../main/resources/templates/java/io-template.ftlh | 60 +++++++++++++++++++---
 3 files changed, 84 insertions(+), 9 deletions(-)

diff --cc build-utils/language-java/src/main/resources/templates/java/io-template.ftlh
index 67a92f1,32ef907..4e7aae7
--- a/build-utils/language-java/src/main/resources/templates/java/io-template.ftlh
+++ b/build-utils/language-java/src/main/resources/templates/java/io-template.ftlh
@@@ -239,10 -245,49 +245,52 @@@ public class ${typeName}IO implements M
  </#switch>
  </#list>
      }
 +    public static int CRC(Object... args) {
 +        return 0;
 +    }
  
+     private static Map<String, Method> staticMethods;
+ 
+     /**
+      * Notice, this method doesn't support using multiple static methods with the same name
+      * but with different argument types. In this case it will use the first used method and
+      * probably fail for all others.
+      *
+      * @param fullyQualifiedMethodName Fully qualified Class name with method name (Example "a.b.c.Foo.bar")
+      * @param args arguments passed to the static method.
+      * @return
+      */
+     private static Object STATIC_CALL(String fullyQualifiedMethodName, Object... args) {
+         if(staticMethods == null) {
+             staticMethods = new HashMap<>();
+         }
+         // Get the method handle and cache it for later usage.
+         if(!staticMethods.containsKey(fullyQualifiedMethodName)) {
+             // Get the types of the arguments.
+             Class<?>[] argTypes = new Class[args.length];
+             for(int i = 0; i < args.length; i++) {
+                 argTypes[i] = args[i].getClass();
+             }
+             // Get the method handle.
+             String className = fullyQualifiedMethodName.substring(0, fullyQualifiedMethodName.lastIndexOf("."));
+             String methodName = fullyQualifiedMethodName.substring(className.length());
+             try {
+                 Class clazz = Class.forName(className);
+                 Method method = clazz.getMethod(methodName, argTypes);
+                 staticMethods.put(fullyQualifiedMethodName, method);
+             } catch (ClassNotFoundException | NoSuchMethodException e) {
+                 throw new RuntimeException("Error finding static method", e);
+             }
+         }
+         Method method = staticMethods.get(fullyQualifiedMethodName);
+         try {
+             // Invoke the static method.
+             return method.invoke(null, args);
+         } catch (InvocationTargetException | IllegalAccessException e) {
+             throw new RuntimeException("Error invoking static method", e);
+         }
+     }
+ 
      private static int COUNT(Object obj) {
          if(obj.getClass().isArray()) {
              Object[] arr = (Object[]) obj;