+ //\r
+ \r
+ // secend scan\r
+ int startmax = 0;\r
+ rd = new BufferedReader(new StringReader(wholeline));\r
+ while ((line = rd.readLine()) != null) {\r
+ if (line.matches("\\/\\*\\*")) {\r
+ incomment = true;\r
+ templine.append(line + "\n");\r
+ } else if (line.matches("\\*\\*\\/")) {\r
+ incomment = false;\r
+ templine.append(line + "\n");\r
+ } else if (incomment) {\r
+ mtrnewcomment = ptnnewcomment.matcher(line);\r
+ if (mtrnewcomment.find()) {\r
+ startmax = mtrnewcomment.group(1).length() > startmax ? mtrnewcomment.group(1).length() : startmax;\r
+ }\r
+ }\r
+ }\r
+ startmax++;\r
+ //\r
+ \r
+ // third scan\r
+ int n = 0;\r
+ String temp = null;\r
+ String[] tempcont = null;\r
+ int count = 0;\r
+ templine = new StringBuffer();\r
+ rd = new BufferedReader(new StringReader(wholeline));\r
+ while ((line = rd.readLine()) != null) {\r
+ if (line.matches("\\/\\*\\*")) {\r
+ incomment = true;\r
+ templine.append(line + "\n");\r
+ } else if (line.matches("\\*\\*\\/")) {\r
+ incomment = false;\r
+ templine.append(line + "\n");\r
+ } else if (incomment) {\r
+ mtrnewcomment = ptnnewcomment.matcher(line);\r
+ if (mtrnewcomment.find()) {\r
+ n = startmax - mtrnewcomment.group(1).length();\r
+ templine.append(mtrnewcomment.group(1));\r
+ while (n-- >= 0) {\r
+ templine.append(" ");\r
+ }\r
+ temp = mtrnewcomment.group(3);\r
+ tempcont = temp.split(" "); // use \\s+ ?\r
+ \r
+ count = 0;\r
+ for (int i = 0; i < tempcont.length; i++) {\r
+ count += tempcont[i].length();\r
+ if (count <= (totallinelength - startmax)) {\r
+ templine.append(tempcont[i] + " ");\r
+ count += 1;\r
+ } else {\r
+ templine.append("\n");\r
+ n = startmax;\r
+ while (n-- >= 0) {\r
+ templine.append(" ");\r
+ }\r
+ templine.append(tempcont[i] + " ");\r
+ count = tempcont[i].length() + 1;\r
+ }\r
+ }\r
+ templine.append("\n");\r
+ } else {\r
+ templine.append(line + "\n");\r
+ }\r
+ } else {\r
+ templine.append(line + "\n");\r
+ }\r
+ }\r
+ wholeline = templine.toString();\r
+ //\r