Skip to content

Method: createFromPlainText(String, boolean)

1: package de.fhdw.wtf.generator.java.generatorModel;
2:
3: /**
4: * Represents generated comments or comments which are imported by ImportAllFromClipperTask. It is used for the
5: * {@link GeneratorModel}.
6: */
7: public final class GenComment {
8:         
9:         /**
10:          * Text of the comment.
11:          */
12:         private final String text;
13:         
14:         /**
15:          * "/**".
16:          */
17:         private static final String COMMENT_START = "/**";
18:         
19:         /**
20:          * "*".
21:          */
22:         private static final String COMMENT_STAR = " * ";
23:         
24:         /**
25:          * "*\/".
26:          */
27:         private static final String COMMENT_END = " */";
28:         
29:         /**
30:          * "\t".
31:          */
32:         private static final String TAB = "\t";
33:         
34:         /**
35:          * "\n".
36:          */
37:         private static final String NEXTLINE = "\n";
38:         
39:         /**
40:          * "\\n".
41:          */
42:         private static final String NEXTLINE_REGEX = "\\n";
43:         
44:         /**
45:          * private constructor for factory pattern.
46:          *
47:          * @param text
48:          * : text of comment.
49:          */
50:         private GenComment(final String text) {
51:                 this.text = text;
52:         }
53:         
54:         /**
55:          * Factory method for {@link GenComment}.
56:          *
57:          * @param text
58:          * : text of comment.
59:          * @return : new GenComment.
60:          */
61:         public static GenComment create(final String text) {
62:                 return new GenComment(text);
63:         }
64:         
65:         /**
66:          * Creates the java comment structure of plain text with "/**" and "*\/" for start and end of comment.
67:          *
68:          * @param text
69:          * : text to be converted to a comment.
70:          * @param operationComment
71:          * : signal if the comment is an operation comment.
72:          * @return new {@link GenComment}.
73:          */
74:         public static GenComment createFromPlainText(final String text, final boolean operationComment) {
75:                 final StringBuilder result = new StringBuilder();
76:                 result.append(COMMENT_START + NEXTLINE);
77:                 final String[] commentLines = text.split(NEXTLINE_REGEX);
78:•                for (final String commentLine : commentLines) {
79:•                        if (operationComment) {
80:                                 result.append(TAB);
81:                         }
82:                         result.append(COMMENT_STAR + commentLine + NEXTLINE);
83:                 }
84:•                if (operationComment) {
85:                         result.append(TAB);
86:                 }
87:                 result.append(COMMENT_END);
88:                 return new GenComment(result.toString());
89:                 // FIXME schön machen
90:         }
91:         
92:         /**
93:          * Projections.
94:          *
95:          * @return text of the comment. If the text is converted to a comment than the java comment structure is contained.
96:          */
97:         public String getText() {
98:                 return this.text;
99:         }
100:         
101:         @Override
102:         public boolean equals(final Object obj) {
103:                 if (obj instanceof GenComment) {
104:                         final GenComment others = (GenComment) obj;
105:                         return others.getText().equals(this.text);
106:                 }
107:                 return false;
108:         }
109:         
110:         @Override
111:         public int hashCode() {
112:                 return 0;
113:         }
114:         
115:         @Override
116:         public String toString() {
117:                 return this.text;
118:         }
119: }