static void splitJavaFiles(L tok) ctex { splitJavaFiles(tok, newFile("output")); } static void splitJavaFiles(L tok, File outDir) ctex { L indexes = jfindAll(tok, "package"); if (empty(indexes) || indexes.get(0) != 1) indexes.add(0, 1); for (int i = 0; i < l(indexes); i++) { int from = indexes.get(i); int to = i+1 < l(indexes) ? indexes.get(i+1) : l(tok); L subtok = cncSubList(tok, from, to); S src = join(subtok); //print(shorten(src, 80)); S pack = tok_packageName(subtok); print("Package: " + quote(pack)); L> classes = allClasses(subtok); /*for (L c : classes) { //print(" Class: " + shorten(join(c), 80)); print(" Class: " + quote(getClassDeclarationName(c))); }*/ if (empty(classes)) print("No classes?? " + quote(src)); else { S className = getNameOfPublicClass(subtok); if (className == null) className = getNameOfAnyClass(subtok); S fileName = addSlash(pack.replace('.', '/')) + className + ".java"; print("File name: " + fileName); saveTextFile(newFile(outDir, fileName), join(subtok)); } print(); } }