Eclipseplugins
CodeFormatter.java
1 package com.proalpha.pds.templates.helper;
2 
3 import java.util.Arrays;
4 
5 public final class CodeFormatter {
6 
7  private static final int RIGHTMARGIN = 80;
8 
9  private CodeFormatter() {
10  super();
11  }
12 
13  public static String SingleLineComment(String Line) {
14  return SingleLineComment(Line, 1);
15  }
16 
17  public static String SingleLineComment(String Line, int StartColumn) {
18  int i;
19  int length;
20 
21  length = Line.length();
22 
23  for (i = 0; i < RIGHTMARGIN - 6 - length - (StartColumn - 1); i++) {
24  Line += " ";
25  }
26 
27  Line = "/* " + Line + " */";
28 
29  for (i = 0; i < (StartColumn - 1); i++) {
30  Line = " " + Line;
31  }
32  return Line;
33 
34  }
35 
36  public static String MultiLineComment(String CommentText) {
37  return MultiLineComment(CommentText, 1);
38  }
39 
40  public static String MultiLineComment(String CommentText, int StartColumn) {
41  String content = "";
42  int counter = 0;
43  String lineSeparator = System.getProperties().getProperty(
44  "line.separator");
45 
46  String[] commentLineSepArray = CommentText.split(lineSeparator);
47 
48  for (String s : commentLineSepArray) {
49  content += SingleLineComment(s, StartColumn);
50  if ((commentLineSepArray.length - 1) > (counter)) {
51  content += lineSeparator;
52  }
53  counter++;
54  }
55  return content;
56  }
57 
58  public static String pad(String src, int padTo, char padChar) {
59  int numPad = padTo - src.length();
60  if (numPad > 0) {
61  StringBuffer sb = new StringBuffer();
62  char[] pad = new char[numPad];
63  Arrays.fill(pad, padChar);
64  sb.append(src);
65  sb.append(pad);
66  return sb.toString();
67  } else {
68  return src;
69  }
70  }
71 }