Testing and fixing bugs on enum data types
authorrtrimana <rtrimana@uci.edu>
Thu, 1 Dec 2016 05:06:13 +0000 (21:06 -0800)
committerrtrimana <rtrimana@uci.edu>
Thu, 1 Dec 2016 05:06:13 +0000 (21:06 -0800)
config/iotpolicy/testclasspolicy.pol
iotjava/iotpolicy/IoTCompiler.java
iotjava/iotrmi/C++/basics/TestClass.hpp
iotjava/iotrmi/C++/basics/TestClass_Stub.cpp
iotjava/iotrmi/Java/basics/TestClass.java
iotjava/iotrmi/Java/basics/TestClass_Stub.java

index 481a284c815ca65f6068b2d680b5ede69c864d01..ddd86d8e5d91a938f2c993a31503b73aa8307221 100644 (file)
@@ -24,10 +24,9 @@ public interface TestClassInterface {
        public List<Boolean> getBooleanList(List<Boolean> in);
        public List<Character> getCharList(List<Character> in);
 
-       public void registerCallback(CallBackInterface _cb);
-       public int callBack();
-
        public Enum handleEnum(Enum en);
+       public Enum[] handleEnumArray(Enum en[]);
+       public List<Enum> handleEnumList(List<Enum> en);
 
        public int getA();
        public void setA(int _int);
@@ -60,9 +59,10 @@ public interface TestClassInterface {
                method = "getDoubleList(List<Double> in)";
                method = "getBooleanList(List<Boolean> in)";
                method = "getCharList(List<Character> in)";
-               method = "registerCallback(CallBackInterface _cb)";
-               method = "callBack()";
+
                method = "handleEnum(Enum en)";
+               method = "handleEnumArray(Enum en[])";
+               method = "handleEnumList(List<Enum> en)";
                method = "getA()";
                method = "setA(int _int)";
                method = "setB(float _float)";
index ab19e6a313c69d1a29e29b124c07146dadcc8304..9d9ecdd948f576618dd68f7f71783950f2026c2c 100644 (file)
@@ -493,15 +493,17 @@ public class IoTCompiler {
        /**
         * HELPER: writeJavaInitCallbackPermission() writes the permission for callback
         */
-       private void writeJavaInitCallbackPermission(String intface, InterfaceDecl intDecl) {
+       private void writeJavaInitCallbackPermission(String intface, InterfaceDecl intDecl, boolean callbackExist) {
 
-               String method = "___initCallBack()";
-               int methodNumId = intDecl.getHelperMethodNumId(method);
-               Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
-               for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
-                       String newIntface = intMeth.getKey();
-                       int newObjectId = getNewIntfaceObjectId(newIntface);
-                       println("set" + newObjectId + "Allowed.add(" + methodNumId + ");");
+               if (callbackExist) {
+                       String method = "___initCallBack()";
+                       int methodNumId = intDecl.getHelperMethodNumId(method);
+                       Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
+                       for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                               String newIntface = intMeth.getKey();
+                               int newObjectId = getNewIntfaceObjectId(newIntface);
+                               println("set" + newObjectId + "Allowed.add(" + methodNumId + ");");
+                       }
                }
        }
 
@@ -558,20 +560,20 @@ public class IoTCompiler {
                for (int i = 0; i < methParams.size(); i++) {
                        String paramType = methPrmTypes.get(i);
                        String param = methParams.get(i);
-                       String simpleType = getSimpleType(paramType);
+                       String simpleType = getGenericType(paramType);
                        if (isEnumClass(simpleType)) {
                        // Check if this is enum type
                                if (isArray(param)) {   // An array
-                                       println("int len" + i + " = " + param + ".length;");
-                                       println("int paramEnum" + i + "[] = new int[len];");
+                                       println("int len" + i + " = " + getSimpleIdentifier(param) + ".length;");
+                                       println("int paramEnum" + i + "[] = new int[len" + i + "];");
                                        println("for (int i = 0; i < len" + i + "; i++) {");
-                                       println("paramEnum" + i + "[i] = " + param + "[i].ordinal();");
+                                       println("paramEnum" + i + "[i] = " + getSimpleIdentifier(param) + "[i].ordinal();");
                                        println("}");
                                } else if (isList(paramType)) { // A list
-                                       println("int len" + i + " = " + param + ".size();");
-                                       println("int paramEnum" + i + "[] = new int[len];");
+                                       println("int len" + i + " = " + getSimpleIdentifier(param) + ".size();");
+                                       println("int paramEnum" + i + "[] = new int[len" + i + "];");
                                        println("for (int i = 0; i < len" + i + "; i++) {");
-                                       println("paramEnum" + i + "[i] = " + param + ".get(i).ordinal();");
+                                       println("paramEnum" + i + "[i] = " + getSimpleIdentifier(param) + ".get(i).ordinal();");
                                        println("}");
                                } else {        // Just one element
                                        println("int paramEnum" + i + "[] = new int[1];");
@@ -588,10 +590,10 @@ public class IoTCompiler {
        private void checkAndWriteEnumRetTypeJavaStub(String retType) {
 
                // Strips off array "[]" for return type
-               String pureType = getSimpleArrayType(getSimpleType(retType));
+               String pureType = getSimpleArrayType(getGenericType(retType));
                // Take the inner type of generic
                if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES)
-                       pureType = getTypeOfGeneric(retType)[0];
+                       pureType = getGenericType(retType);
                if (isEnumClass(pureType)) {
                // Check if this is enum type
                        // Enum decoder
@@ -891,16 +893,16 @@ public class IoTCompiler {
                        if (isStructClass(getGenericType(getSimpleArrayType(retType)))) {
                                writeStructReturnJavaStub(getGenericType(getSimpleArrayType(retType)), retType);
                        } else {
-                       // Check if the return value NONPRIMITIVES
-                               if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES) {
-                                       String[] retGenValType = getTypeOfGeneric(retType);
-                                       println("Class<?> retGenValType = " + retGenValType[0] + ".class;");
-                                       println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, retGenValType, paramCls, paramObj);");
-                                       println("return (" + retType + ")retObj;");
-                               } else if (getParamCategory(retType) == ParamCategory.ENUM) {
                                // This is an enum type
+                               if (getParamCategory(getGenericType(getSimpleArrayType(retType))) == ParamCategory.ENUM) {
                                        println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);");
                                        checkAndWriteEnumRetTypeJavaStub(retType);
+                               } else if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES) {
+                               // Check if the return value NONPRIMITIVES
+                                       String retGenValType = getGenericType(retType);
+                                       println("Class<?> retGenValType = " + retGenValType + ".class;");
+                                       println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, retGenValType, paramCls, paramObj);");
+                                       println("return (" + retType + ")retObj;");
                                } else {
                                        println("Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);");
                                        println("return (" + retType + ")retObj;");
@@ -1246,14 +1248,14 @@ public class IoTCompiler {
        /**
         * HELPER: writeConstructorJavaSkeleton() writes the constructor of the skeleton class
         */
-       private void writeConstructorJavaSkeleton(String newSkelClass, String intface, InterfaceDecl intDecl, Collection<String> methods) {
+       private void writeConstructorJavaSkeleton(String newSkelClass, String intface, InterfaceDecl intDecl, Collection<String> methods, boolean callbackExist) {
 
                println("public " + newSkelClass + "(" + intface + " _mainObj, int _port) throws Exception {");
                println("mainObj = _mainObj;");
                println("rmiObj = new IoTRMIObject(_port);");
                // Generate permission control initialization
                writeConstructorJavaPermission(intface);
-               writeJavaInitCallbackPermission(intface, intDecl);
+               writeJavaInitCallbackPermission(intface, intDecl, callbackExist);
                writeStructPermissionJavaSkeleton(methods, intDecl, intface);
                println("___waitRequestInvokeMethod();");
                println("}\n");
@@ -1393,22 +1395,22 @@ public class IoTCompiler {
                for (int i = 0; i < methParams.size(); i++) {
                        String paramType = methPrmTypes.get(i);
                        String param = methParams.get(i);
-                       String simpleType = getSimpleType(paramType);
+                       String simpleType = getGenericType(paramType);
                        if (isEnumClass(simpleType)) {
                        // Check if this is enum type
                                println("int paramInt" + i + "[] = (int[]) paramObj[" + i + "];");
                                println(simpleType + "[] enumVals = " + simpleType + ".values();");
                                if (isArray(param)) {   // An array
                                        println("int len" + i + " = paramInt" + i + ".length;");
-                                       println(simpleType + "[] paramEnum = new " + simpleType + "[len];");
+                                       println(simpleType + "[] paramEnum" + i + " = new " + simpleType + "[len" + i + "];");
                                        println("for (int i = 0; i < len" + i + "; i++) {");
-                                       println("paramEnum[i] = enumVals[paramInt" + i + "[i]];");
+                                       println("paramEnum" + i + "[i] = enumVals[paramInt" + i + "[i]];");
                                        println("}");
                                } else if (isList(paramType)) { // A list
                                        println("int len" + i + " = paramInt" + i + ".length;");
-                                       println("List<" + simpleType + "> paramEnum = new ArrayList<" + simpleType + ">();");
+                                       println("List<" + simpleType + "> paramEnum" + i + " = new ArrayList<" + simpleType + ">();");
                                        println("for (int i = 0; i < len" + i + "; i++) {");
-                                       println("paramEnum.add(enumVals[paramInt" + i + "[i]]);");
+                                       println("paramEnum" + i + ".add(enumVals[paramInt" + i + "[i]]);");
                                        println("}");
                                } else {        // Just one element
                                        println(simpleType + " paramEnum" + i + " = enumVals[paramInt" + i + "[0]];");
@@ -1424,10 +1426,10 @@ public class IoTCompiler {
        private void checkAndWriteEnumRetTypeJavaSkeleton(String retType, String methodId) {
 
                // Strips off array "[]" for return type
-               String pureType = getSimpleArrayType(getSimpleType(retType));
+               String pureType = getSimpleArrayType(getGenericType(retType));
                // Take the inner type of generic
                if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES)
-                       pureType = getTypeOfGeneric(retType)[0];
+                       pureType = getGenericType(retType);
                if (isEnumClass(pureType)) {
                // Check if this is enum type
                        // Enum decoder
@@ -1448,10 +1450,10 @@ public class IoTCompiler {
        private void checkAndWriteEnumRetConvJavaSkeleton(String retType) {
 
                // Strips off array "[]" for return type
-               String pureType = getSimpleArrayType(getSimpleType(retType));
+               String pureType = getSimpleArrayType(getGenericType(retType));
                // Take the inner type of generic
                if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES)
-                       pureType = getTypeOfGeneric(retType)[0];
+                       pureType = getGenericType(retType);
                if (isEnumClass(pureType)) {
                // Check if this is enum type
                        if (isArray(retType)) { // An array
@@ -1462,9 +1464,9 @@ public class IoTCompiler {
                                println("}");
                        } else if (isList(retType)) {   // A list
                                println("int retLen = retEnum.size();");
-                               println("List<" + pureType + "> retEnumVal = new ArrayList<" + pureType + ">();");
+                               println("int[] retEnumVal = new int[retLen];");
                                println("for (int i = 0; i < retLen; i++) {");
-                               println("retEnumVal.add(retEnum[i].ordinal());");
+                               println("retEnumVal[i] = retEnum.get(i).ordinal();");
                                println("}");
                        } else {        // Just one element
                                println("int[] retEnumVal = new int[1];");
@@ -1656,9 +1658,9 @@ public class IoTCompiler {
                String retType = intDecl.getMethodType(method);
                if (retType.equals("void")) {
                        print(intDecl.getMethodId(method) + "(");
-               } else if (isEnumClass(getSimpleArrayType(getSimpleType(retType)))) {   // Enum type
+               } else if (isEnumClass(getSimpleArrayType(getGenericType(retType)))) {  // Enum type
                        checkAndWriteEnumRetTypeJavaSkeleton(retType, intDecl.getMethodId(method));
-               } else if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) { // Struct type
+               } else if (isStructClass(getSimpleArrayType(getGenericType(retType)))) {        // Struct type
                        print(retType + " retStruct = " + intDecl.getMethodId(method) + "(");
                } else { // We do have a return value
                        print("Object retObj = " + intDecl.getMethodId(method) + "(");
@@ -1667,9 +1669,9 @@ public class IoTCompiler {
 
                        if (isCallbackMethod) {
                                print(mapStubParam.get(i));     // Get the callback parameter
-                       } else if (isEnumClass(getSimpleType(methPrmTypes.get(i)))) { // Enum class
+                       } else if (isEnumClass(getGenericType(methPrmTypes.get(i)))) { // Enum class
                                print(getEnumParam(methPrmTypes.get(i), methParams.get(i), i));
-                       } else if (isStructClass(getSimpleType(methPrmTypes.get(i)))) {
+                       } else if (isStructClass(getGenericType(methPrmTypes.get(i)))) {
                                print("paramStruct" + i);
                        } else {
                                String prmType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
@@ -1683,11 +1685,11 @@ public class IoTCompiler {
                }
                println(");");
                if (!retType.equals("void")) {
-                       if (isEnumClass(getSimpleArrayType(getSimpleType(retType)))) { // Enum type
+                       if (isEnumClass(getSimpleArrayType(getGenericType(retType)))) { // Enum type
                                checkAndWriteEnumRetConvJavaSkeleton(retType);
                                println("rmiObj.sendReturnObj(retObj);");
-                       } else if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) { // Struct type
-                               writeStructReturnJavaSkeleton(getSimpleArrayType(getSimpleType(retType)), retType);
+                       } else if (isStructClass(getSimpleArrayType(getGenericType(retType)))) { // Struct type
+                               writeStructReturnJavaSkeleton(getSimpleArrayType(getGenericType(retType)), retType);
                                println("rmiObj.sendReturnObj(retCls, retObj);");
                        } else
                                println("rmiObj.sendReturnObj(retObj);");
@@ -1778,8 +1780,9 @@ public class IoTCompiler {
                print("new Class<?>[] { ");
                for (int i = 0; i < methParams.size(); i++) {
                        String prmType = methPrmTypes.get(i);
-                       if (getParamCategory(prmType) == ParamCategory.NONPRIMITIVES)
-                               print(getTypeOfGeneric(prmType)[0] + ".class");
+                       if ((getParamCategory(prmType) == ParamCategory.NONPRIMITIVES) &&
+                               !isEnumClass(getGenericType(prmType)))
+                                       print(getGenericType(prmType) + ".class");
                        else
                                print("null");
                        if (i != methParams.size() - 1)
@@ -2124,7 +2127,7 @@ public class IoTCompiler {
                        // Write properties
                        writePropertiesJavaSkeleton(intface, callbackExist, intDecl);
                        // Write constructor
-                       writeConstructorJavaSkeleton(newSkelClass, intface, intDecl, methods);
+                       writeConstructorJavaSkeleton(newSkelClass, intface, intDecl, methods, callbackExist);
                        // Write methods
                        writeMethodJavaSkeleton(methods, intDecl, callbackClasses, false);
                        // Write method helper
@@ -2552,9 +2555,6 @@ public class IoTCompiler {
 
                        List<String> methParams = intDecl.getMethodParams(method);
                        List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
-
-                       //System.out.println("\n\nMethod return type: " + checkAndGetCplusType(intDecl.getMethodType(method)) + "\n\n");
-
                        print(checkAndGetCplusType(intDecl.getMethodType(method)) + " " +
                                intDecl.getMethodId(method) + "(");
                        boolean isCallbackMethod = false;
@@ -2631,11 +2631,8 @@ public class IoTCompiler {
                        if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object
                                print("\"int\"");
                        } else { // Generate normal classes if it's not a callback object
-                               //String paramTypeC = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
-                               //String prmType = getSimpleType(getEnumType(paramTypeC));
                                String paramTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i));
-                               String prmType = getEnumCplusClsType(paramTypeC);
-                               print("\"" + prmType + "\"");
+                               print("\"" + paramTypeC + "\"");
                        }
                        if (i != methParams.size() - 1) // Check if this is the last element
                                print(", ");
@@ -2683,14 +2680,13 @@ public class IoTCompiler {
                for (int i = 0; i < methParams.size(); i++) {
                        String paramType = methPrmTypes.get(i);
                        String param = methParams.get(i);
-                       String simpleType = getSimpleType(paramType);
-                       if (isEnumClass(simpleType)) {
+                       if (isEnumClass(getGenericType(paramType))) {
                        // Check if this is enum type
                                if (isArrayOrList(paramType, param)) {  // An array or vector
-                                       println("int len" + i + " = " + param + ".size();");
-                                       println("vector<int> paramEnum" + i + "(len);");
+                                       println("int len" + i + " = " + getSimpleIdentifier(param) + ".size();");
+                                       println("vector<int> paramEnum" + i + "(len" + i + ");");
                                        println("for (int i = 0; i < len" + i + "; i++) {");
-                                       println("paramEnum" + i + "[i] = (int) " + param + "[i];");
+                                       println("paramEnum" + i + "[i] = (int) " + getSimpleIdentifier(param) + "[i];");
                                        println("}");
                                } else {        // Just one element
                                        println("vector<int> paramEnum" + i + "(1);");
@@ -2707,10 +2703,10 @@ public class IoTCompiler {
        private void checkAndWriteEnumRetTypeCplusStub(String retType) {
 
                // Strips off array "[]" for return type
-               String pureType = getSimpleArrayType(getSimpleType(retType));
+               String pureType = getSimpleArrayType(getGenericType(retType));
                // Take the inner type of generic
                if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES)
-                       pureType = getTypeOfGeneric(retType)[0];
+                       pureType = getGenericType(retType);
                if (isEnumClass(pureType)) {
                // Check if this is enum type
                        println("vector<int> retEnumInt;");
@@ -2955,8 +2951,6 @@ public class IoTCompiler {
                checkAndWriteStructSetupCplusStub(methParams, methPrmTypes, intDecl, method);
                println("int methodId = " + intDecl.getMethodNumId(method) + ";");
                String retType = intDecl.getMethodType(method);
-               //String retTypeC = checkAndGetCplusType(retType);
-               //println("string retType = \"" + checkAndGetCplusArrayType(getStructType(getEnumType(retTypeC))) + "\";");
                println("string retType = \"" + checkAndGetCplusRetClsType(getStructType(getEnumType(retType))) + "\";");
                // Generate array of parameter types
                if (isStructPresent(methParams, methPrmTypes)) {
@@ -2965,11 +2959,8 @@ public class IoTCompiler {
                        println("int numParam = " + methParams.size() + ";");
                        print("string paramCls[] = { ");
                        for (int i = 0; i < methParams.size(); i++) {
-                               //String paramTypeC = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
-                               //String prmType = getSimpleType(getEnumType(paramTypeC));
                                String paramTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i));
-                               String prmType = getEnumCplusClsType(paramTypeC);
-                               print("\"" + prmType + "\"");
+                               print("\"" + paramTypeC + "\"");
                                // Check if this is the last element (don't print a comma)
                                if (i != methParams.size() - 1) {
                                        print(", ");
@@ -2998,7 +2989,7 @@ public class IoTCompiler {
                                writeStructReturnCplusStub(getGenericType(getSimpleArrayType(retType)), retType);
                        } else {
                        // Check if the return value NONPRIMITIVES
-                               if (getParamCategory(retType) == ParamCategory.ENUM) {
+                               if (isEnumClass(getSimpleArrayType(getGenericType(retType)))) {
                                        checkAndWriteEnumRetTypeCplusStub(retType);
                                } else {
                                        //if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES)
@@ -3616,7 +3607,7 @@ public class IoTCompiler {
                for (int i = 0; i < methParams.size(); i++) {
                        String paramType = methPrmTypes.get(i);
                        String param = methParams.get(i);
-                       String simpleType = getSimpleType(paramType);
+                       String simpleType = getGenericType(paramType);
                        if (isEnumClass(simpleType)) {
                        // Check if this is enum type
                                if (isArrayOrList(paramType, param)) {  // An array
@@ -3640,7 +3631,7 @@ public class IoTCompiler {
        private void checkAndWriteEnumRetTypeCplusSkeleton(String retType) {
 
                // Strips off array "[]" for return type
-               String pureType = getSimpleArrayType(getSimpleType(retType));
+               String pureType = getSimpleArrayType(getGenericType(retType));
                // Take the inner type of generic
                if (getParamCategory(retType) == ParamCategory.NONPRIMITIVES)
                        pureType = getTypeOfGeneric(retType)[0];
@@ -3672,9 +3663,9 @@ public class IoTCompiler {
                        String paramType = returnGenericCallbackType(methPrmTypes.get(i));
                        if (callbackClasses.contains(paramType))
                                print("stub" + i);
-                       else if (isEnumClass(getSimpleType(paramType))) // Check if this is enum type
+                       else if (isEnumClass(getGenericType(paramType)))        // Check if this is enum type
                                print("paramEnum" + i);
-                       else if (isStructClass(getSimpleType(paramType)))       // Struct type
+                       else if (isStructClass(getGenericType(paramType)))      // Struct type
                                print("paramStruct" + i);
                        else
                                print(getSimpleIdentifier(methParams.get(i)));
@@ -3704,23 +3695,23 @@ public class IoTCompiler {
                if (retType.equals("void")) {
                        writeMethodInputParameters(methParams, methPrmTypes, callbackClasses, methodId);
                } else { // We do have a return value
-                       if (isEnumClass(getSimpleArrayType(getSimpleType(retType)))) // Enum type
+                       if (isEnumClass(getSimpleArrayType(getGenericType(retType)))) // Enum type
                                print(checkAndGetCplusType(retType) + " retEnum = ");
-                       else if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) // Struct type
+                       else if (isStructClass(getSimpleArrayType(getGenericType(retType)))) // Struct type
                                print(checkAndGetCplusType(retType) + " retStruct = ");
                        else
                                print(checkAndGetCplusType(retType) + " retVal = ");
                        writeMethodInputParameters(methParams, methPrmTypes, callbackClasses, methodId);
                        checkAndWriteEnumRetTypeCplusSkeleton(retType);
-                       if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) // Struct type
-                               writeStructReturnCplusSkeleton(getSimpleArrayType(getSimpleType(retType)), retType);
-                       if (isEnumClass(getSimpleArrayType(getSimpleType(retType)))) // Enum type
+                       if (isStructClass(getSimpleArrayType(getGenericType(retType)))) // Struct type
+                               writeStructReturnCplusSkeleton(getSimpleArrayType(getGenericType(retType)), retType);
+                       if (isEnumClass(getSimpleArrayType(getGenericType(retType)))) // Enum type
                                println("void* retObj = &retEnumInt;");
                        else
-                               if (!isStructClass(getSimpleArrayType(getSimpleType(retType)))) // Struct type
+                               if (!isStructClass(getSimpleArrayType(getGenericType(retType)))) // Struct type
                                        println("void* retObj = &retVal;");
                        String retTypeC = checkAndGetCplusType(retType);
-                       if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) // Struct type
+                       if (isStructClass(getSimpleArrayType(getGenericType(retType)))) // Struct type
                                println("rmiObj->sendReturnObj(retObj, retCls, numRetObj);");
                        else
                                println("rmiObj->sendReturnObj(retObj, \"" + checkAndGetCplusRetClsType(getEnumType(retType)) + "\");");
@@ -3745,11 +3736,8 @@ public class IoTCompiler {
                                callbackType = paramType;
                                print("\"int\"");
                        } else {        // Generate normal classes if it's not a callback object
-                               //String paramTypeC = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
-                               //String prmType = getSimpleType(getEnumType(paramTypeC));
                                String paramTypeC = checkAndGetCplusArgClsType(methPrmTypes.get(i), methParams.get(i));
-                               String prmType = getEnumCplusClsType(paramTypeC);
-                               print("\"" + prmType + "\"");
+                               print("\"" + paramTypeC + "\"");
                        }
                        if (i != methParams.size() - 1) {
                                print(", ");
@@ -3763,10 +3751,12 @@ public class IoTCompiler {
                for (int i = 0; i < methParams.size(); i++) {
                        String paramType = returnGenericCallbackType(methPrmTypes.get(i));
                        if (!callbackClasses.contains(paramType)) {
-                               String methPrmType = checkAndGetCplusType(methPrmTypes.get(i));
-                               if (isEnumClass(getSimpleType(methPrmType))) {  // Check if this is enum type
+                               String methParamType = methPrmTypes.get(i);
+                               if (isEnumClass(getSimpleArrayType(getGenericType(methParamType)))) {   
+                               // Check if this is enum type
                                        println("vector<int> paramEnumInt" + i + ";");
                                } else {
+                                       String methPrmType = checkAndGetCplusType(methParamType);
                                        String methParamComplete = checkAndGetCplusArray(methPrmType, methParams.get(i));
                     println(methParamComplete + ";");
                                }
@@ -3778,7 +3768,7 @@ public class IoTCompiler {
                        String paramType = returnGenericCallbackType(methPrmTypes.get(i));
                        if (callbackClasses.contains(paramType))
                                print("&numStubs" + i);
-                       else if (isEnumClass(getSimpleType(paramType))) // Check if this is enum type
+                       else if (isEnumClass(getGenericType(paramType)))        // Check if this is enum type
                                print("&paramEnumInt" + i);
                        else
                                print("&" + getSimpleIdentifier(methParams.get(i)));
@@ -3961,14 +3951,14 @@ public class IoTCompiler {
                                } else {        // Generate normal classes if it's not a callback object
                                        String paramTypeC = checkAndGetCplusType(methPrmTypes.get(i));
                                        String prmTypeC = checkAndGetCplusArrayType(paramTypeC, methParams.get(i));
-                                       if (isEnumClass(getSimpleType(paramTypeC))) {   // Check if this is enum type
+                                       if (isEnumClass(getGenericType(paramTypeC))) {  // Check if this is enum type
                                                println("vector<int> paramEnumInt" + i + ";");
                                        } else {
                                                String methParamComplete = checkAndGetCplusArray(paramTypeC, methParams.get(i));
                                                println(methParamComplete + ";");
                                        }
                                        println("paramCls[pos] = \"" + getEnumType(prmTypeC) + "\";");
-                                       if (isEnumClass(getSimpleType(paramType)))      // Check if this is enum type
+                                       if (isEnumClass(getGenericType(paramType)))     // Check if this is enum type
                                                println("paramObj[pos++] = &paramEnumInt" + i);
                                        else
                                                println("paramObj[pos++] = &" + getSimpleIdentifier(methParams.get(i)) + ";");
@@ -4561,9 +4551,12 @@ public class IoTCompiler {
        /**
         * This function converts Java to C++ type for compilation
         */
-       private String convertType(String jType) {
+       private String convertType(String type) {
 
-               return mapPrimitives.get(jType);
+               if (mapPrimitives.containsKey(type))
+                       return mapPrimitives.get(type);
+               else
+                       return type;
        }
 
 
@@ -4816,7 +4809,7 @@ public class IoTCompiler {
                String pureType = getSimpleArrayType(type);
                // Take the inner type of generic
                if (getParamCategory(type) == ParamCategory.NONPRIMITIVES)
-                       pureType = getTypeOfGeneric(type)[0];
+                       pureType = getGenericType(type);
                if (isEnumClass(pureType)) {
                        String enumType = "int[]";
                        return enumType;
@@ -4831,7 +4824,7 @@ public class IoTCompiler {
                String pureType = getSimpleArrayType(type);
                // Take the inner type of generic
                if (getParamCategory(type) == ParamCategory.NONPRIMITIVES)
-                       pureType = getTypeOfGeneric(type)[0];
+                       pureType = getGenericType(type);
                if (isEnumClass(pureType)) {
                        String enumType = "int*";
                        return enumType;
@@ -4847,7 +4840,7 @@ public class IoTCompiler {
                String pureType = getSimpleArrayType(type);
                // Take the inner type of generic
                if (getParamCategory(type) == ParamCategory.NONPRIMITIVES)
-                       pureType = getTypeOfGeneric(type)[0];
+                       pureType = getGenericType(type);
                if (isStructClass(pureType)) {
                        String structType = "int";
                        return structType;
@@ -5161,7 +5154,12 @@ public class IoTCompiler {
        // - Check and return C++ vector class, e.g. List<Integer> A into vector<int>
        private String checkAndGetCplusArgClsType(String paramType, String param) {
 
-               String paramTypeRet = null;
+               String paramTypeRet = getEnumCplusClsType(paramType);
+               if (!paramTypeRet.equals(paramType)) 
+               // Just return if it is an enum type
+               // Type will still be the same if it's not an enum type
+                       return paramTypeRet;
+
                // Check for array declaration
                if (param.contains("[]")) {
                        paramTypeRet = getSimpleArrayType(paramType) + "*";
index 63507122e15909461a191243413fdcc5114026fd..4dd11ff1cc3eb6c93edaac6faa6180becec9174c 100644 (file)
@@ -45,6 +45,8 @@ class TestClass : public TestClassInterface {
 
                // Enum
                Enum                            handleEnum(Enum en);
+               vector<Enum>            handleEnumArray(vector<Enum> vecEn);
+               vector<Enum>            handleEnumList(vector<Enum> vecEn);
 
                int                                     getA();
                void                            setA(int _int);
@@ -268,14 +270,24 @@ Enum TestClass::handleEnum(Enum en) {
 }
 
 
-/*vector<EnumC> TestClass::handleEnum(vector<EnumC> vecEn) {
+vector<Enum> TestClass::handleEnumArray(vector<Enum> vecEn) {
 
-       for (EnumC en : vecEn) {
+       for (Enum en : vecEn) {
                cout << "Enum: " << en << endl;
        }
        
        return vecEn;
-}*/
+}
+
+
+vector<Enum> TestClass::handleEnumList(vector<Enum> vecEn) {
+
+       for (Enum en : vecEn) {
+               cout << "Enum: " << en << endl;
+       }
+       
+       return vecEn;
+}
 
 
 string TestClass::sumArray(vector<string> newA) {
index a1c35c0718e251ae3997b6a30d9d01bbb4882cdf..01b0a90f9392a6e157e022edb7c2b393cc87c422 100644 (file)
@@ -87,6 +87,19 @@ int main(int argc, char *argv[])
        en = APPLE;
        Enum res = tcStub->handleEnum(en);
        cout << "Return value: " << res << endl;
+       vector<Enum> vecEn;
+       vecEn.push_back(APPLE);
+       vecEn.push_back(ORANGE);
+       vecEn.push_back(APPLE);
+       vecEn.push_back(GRAPE);
+       vector<Enum> vecRes = tcStub->handleEnumArray(vecEn);
+       for (Enum en : vecRes) {
+               cout << "Enum value: " << en << endl;
+       }
+       vector<Enum> vecRes2 = tcStub->handleEnumList(vecEn);
+       for (Enum en : vecRes2) {
+               cout << "Enum value: " << en << endl;
+       }
 
        cout << "==== OTHERS ====" << endl;
        cout << "Return value: " << tcStub->getA() << endl;
index 01924a5951d6394b3290cac2e795da0805d4a7cf..a7453a499a2d1fb8d4adc64d1d38fa31e34a824b 100644 (file)
@@ -213,6 +213,7 @@ public class TestClass implements TestClassInterface {
        }
 
 
+       // Enum
        public Enum handleEnum(Enum en) {
 
                System.out.println("Enum: " + en);
@@ -221,15 +222,24 @@ public class TestClass implements TestClassInterface {
        }
 
 
-       // Enum
-       /*public EnumJ[] handleEnum(EnumJ[] en) {
+       public Enum[] handleEnumArray(Enum[] en) {
 
-               for (EnumJ e : en) {
+               for (Enum e : en) {
                        System.out.println("Enum: " + e);
                }
                
                return en;
-       }*/
+       }
+
+
+       public List<Enum> handleEnumList(List<Enum> en) {
+
+               for (Enum e : en) {
+                       System.out.println("Enum: " + e);
+               }
+               
+               return en;
+       }
 
 
        // Getters
index 26ecd4347e64e1749e76272c06ef49ed17a8d7d2..63c3fffa50e0a9aa8098725381bcbace103a21f5 100644 (file)
@@ -64,6 +64,12 @@ public class TestClass_Stub {
                Enum en = Enum.APPLE;
                Enum res = tcstub.handleEnum(en);
                System.out.println("Enum member: " + res);
+               Enum[] enArr = { Enum.APPLE, Enum.ORANGE, Enum.APPLE, Enum.GRAPE };
+               Enum[] resArr = tcstub.handleEnumArray(enArr);
+               System.out.println("Enum members: " + Arrays.toString(resArr));
+               List<Enum> enArr2 = new ArrayList(Arrays.asList(enArr));
+               List<Enum> resArr2 = tcstub.handleEnumList(enArr2);
+               System.out.println("Enum members: " + resArr2.toString());
 
                System.out.println("==== OTHERS ====");
                System.out.println("Return value: " + tcstub.getA());