+ String path = createDirectories(dir, subdir);
+ for (String intface : mapIntfacePTH.keySet()) {
+
+ Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
+ for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+
+ // Open a new file to write into
+ String newIntface = intMeth.getKey();
+ String newStubClass = newIntface + "_Stub";
+ FileWriter fw = new FileWriter(path + "/" + newStubClass + ".java");
+ pw = new PrintWriter(new BufferedWriter(fw));
+ DeclarationHandler decHandler = mapIntDeclHand.get(intface);
+ InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(intface);
+ // Pass in set of methods and get import classes
+ Set<String> importClasses = getImportClasses(intMeth.getValue(), intDecl);
+ printImportStatements(importClasses);
+ // Write interface header
+ println("");
+ println("public class " + newStubClass + " implements " + newIntface + " {");
+ println("");
+ // Write methods
+ for (String method : intMeth.getValue()) {
+
+ List<String> methParams = intDecl.getMethodParams(method);
+ List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+ print("public " + intDecl.getMethodType(method) + " " +
+ intDecl.getMethodId(method) + "(");
+ for (int i = 0; i < methParams.size(); i++) {
+
+ print(methPrmTypes.get(i) + " " + methParams.get(i));
+ // Check if this is the last element (don't print a comma)
+ if (i != methParams.size() - 1) {
+ print(", ");
+ }
+ }
+ println(") {");
+ // Check if this is not "void"
+ if (!intDecl.getMethodType(method).equals("void")) {
+ String retStmt = generateReturnStmt(intDecl.getMethodType(method));
+ println("return " + retStmt + ";");
+ }
+ println("}"); println("");
+ }
+ println("}");
+ pw.close();
+ System.out.println("IoTCompiler: Generated stub class " + newStubClass + ".java...");
+ }
+ }
+ }