+ // Create a directory and possibly a sub directory
+ private void createDirectories(String dir, String subdir) {
+
+ createDirectory(dir);
+ if (subdir != null) {
+ createDirectory(dir + "/" + subdir);
+ }
+ }
+
+
+ // Inserting array members into a Map object
+ // that maps arrKey to arrVal objects
+ private void arraysToMap(Map map, Object[] arrKey, Object[] arrVal) {
+
+ for(int i = 0; i < arrKey.length; i++) {
+
+ map.put(arrKey[i], arrVal[i]);
+ }
+ }
+
+
+ // Return parameter category, i.e. PRIMITIVES, NONPRIMITIVES, or USERDEFINED
+ private ParamCategory getParamCategory(String paramType) {
+
+ if (mapPrimitives.containsKey(paramType)) {
+ return ParamCategory.PRIMITIVES;
+ // We can either use mapNonPrimitivesJava or mapNonPrimitivesCplus here
+ } else if (mapNonPrimitivesJava.containsKey(getSimpleType(paramType))) {
+ return ParamCategory.NONPRIMITIVES;
+ } else
+ return ParamCategory.USERDEFINED;
+ }
+
+
+ // Return full class name for non-primitives to generate Java import statements
+ // e.g. java.util.Set for Set, java.util.Map for Map
+ private String getNonPrimitiveJavaClass(String paramNonPrimitives) {
+
+ return mapNonPrimitivesJava.get(paramNonPrimitives);
+ }
+
+
+ // Return full class name for non-primitives to generate Cplus include statements
+ // e.g. #include <set> for Set, #include <map> for Map
+ private String getNonPrimitiveCplusClass(String paramNonPrimitives) {
+
+ return mapNonPrimitivesCplus.get(paramNonPrimitives);
+ }
+
+
+ // Get simple types, e.g. HashSet for HashSet<...>
+ // Basically strip off the "<...>"
+ private String getSimpleType(String paramType) {
+
+ // Check if this is generics
+ if(paramType.contains("<")) {
+ String[] type = paramType.split("<");
+ return type[0];
+ } else
+ return paramType;
+ }
+
+
+ // Generate a set of classes for import statements
+ private Set<String> getImportClasses(Collection<String> methods) {
+
+ Set<String> importClasses = new HashSet<String>();
+ for (String method : methods) {
+ List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+ for (String paramType : methPrmTypes) {
+
+ String simpleType = getSimpleType(paramType);
+ if (getParamCategory(simpleType) == ParamCategory.NONPRIMITIVES) {
+ importClasses.add(getNonPrimitiveJavaClass(simpleType));
+ }
+ }
+ }
+ return importClasses;
+ }
+
+
+ // Generate a set of classes for include statements
+ private Set<String> getIncludeClasses(Collection<String> methods) {
+
+ Set<String> includeClasses = new HashSet<String>();
+ for (String method : methods) {
+
+ List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+ for (String paramType : methPrmTypes) {
+
+ String simpleType = getSimpleType(paramType);
+ if (getParamCategory(simpleType) == ParamCategory.NONPRIMITIVES) {
+ includeClasses.add(getNonPrimitiveCplusClass(simpleType));
+ }
+ }
+ }
+ return includeClasses;
+ }
+
+
+ private void printImportStatements(Set<String> importClasses) {
+
+ for(String cls : importClasses) {
+ println("import " + cls + ";");
+ }
+ }
+
+
+ private void printIncludeStatements(Set<String> includeClasses) {
+
+ for(String cls : includeClasses) {
+ println("#include <" + cls + ">");
+ }
+ }
+
+
+ // Get the C++ version of a non-primitive type
+ // e.g. set for Set and map for Map
+ // Input nonPrimitiveType has to be generics in format
+ private String[] getTypeOfGeneric(String nonPrimitiveType) {
+
+ // Handle <, >, and , for 2-type generic/template
+ String[] substr = nonPrimitiveType.split("<")[1].split(">")[0].split(",");
+ return substr;
+ }
+
+
+ private String checkAndGetCplusType(String paramType) {
+
+ if (getParamCategory(paramType) == ParamCategory.PRIMITIVES) {
+ return convertType(paramType);
+ } else if (getParamCategory(paramType) == ParamCategory.NONPRIMITIVES) {
+
+ // Check for generic/template format
+ if (paramType.contains("<") && paramType.contains(">")) {
+
+ String genericClass = getSimpleType(paramType);
+ String[] genericType = getTypeOfGeneric(paramType);
+ String cplusTemplate = null;
+ if (genericType.length == 1) // Generic/template with one type
+ cplusTemplate = getNonPrimitiveCplusClass(genericClass) +
+ "<" + convertType(genericType[0]) + ">";
+ else // Generic/template with two types
+ cplusTemplate = getNonPrimitiveCplusClass(genericClass) +
+ "<" + convertType(genericType[0]) + "," + convertType(genericType[1]) + ">";
+ return cplusTemplate;
+ } else
+ return getNonPrimitiveCplusClass(paramType);
+ } else
+ // Just return it as is if it's not non-primitives
+ return paramType;
+ }
+
+
+ // Get simple types, e.g. HashSet for HashSet<...>
+ // Basically strip off the "<...>"
+ private String checkAndGetParamClass(String paramType) {
+
+ // Check if this is generics
+ if(getParamCategory(paramType) == ParamCategory.USERDEFINED) {
+ // TODO: replace this with the proper stub interface name
+ return paramType + "Remote";
+ } else
+ return paramType;
+ }
+
+