You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Utility class to help indent strings that contain code.
5
5
*/
6
6
publicclassIndentationHelper {
7
-
/**
8
-
* Enum which denotes the different types of indentation possible.
9
-
* When {@link #NULL} is passed to any method in this class, the output of said method should match the input.
10
-
*/
11
-
publicenumIndentationType {
12
-
/**
13
-
* A tab character (\t) should be used for indentation.
14
-
*/
15
-
TABS("\t"),
16
-
/**
17
-
* Four spaces should be used for indentation.
18
-
*/
19
-
FOUR_SPACES(" "),
20
-
/**
21
-
* Two spaces should be used for indentation
22
-
*/
23
-
TWO_SPACES(" "),
24
-
/**
25
-
* Doesn't define an indentation type but
26
-
* Is used as a substitute to null to indicate that a String given to any method in {@link IndentationHelper} should not be changed.
27
-
*/
28
-
NULL("");
7
+
/**
8
+
* Enum which denotes the different types of indentation possible.
9
+
* When {@link #NULL} is passed to any method in this class, the output of said method should match the input.
10
+
*/
11
+
publicenumIndentationType {
12
+
/**
13
+
* A tab character (\t) should be used for indentation.
14
+
*/
15
+
TABS("\t"),
16
+
/**
17
+
* Four spaces should be used for indentation.
18
+
*/
19
+
FOUR_SPACES(" "),
20
+
/**
21
+
* Two spaces should be used for indentation.
22
+
*/
23
+
TWO_SPACES(" "),
24
+
/**
25
+
* Doesn't define an indentation type but
26
+
* Is used as a substitute to null to indicate that a String given to any method in {@link IndentationHelper} should not be changed.
27
+
*/
28
+
NULL("");
29
29
30
-
/**
31
-
* Holds the characters used for indentation of the type.
32
-
*/
33
-
privatefinalStringpattern;
30
+
/**
31
+
* Holds the characters used for indentation of the type.
32
+
*/
33
+
privatefinalStringpattern;
34
34
35
-
/**
36
-
* Constructs the indentation type
37
-
* @param pattern The pattern to be used as indentation
38
-
*/
39
-
IndentationType(Stringpattern) {
40
-
this.pattern = pattern;
41
-
}
35
+
/**
36
+
* Constructs the indentation type.
37
+
*
38
+
* @param pattern The pattern to be used as indentation
39
+
*/
40
+
IndentationType(Stringpattern) {
41
+
this.pattern = pattern;
42
+
}
42
43
43
-
/**
44
-
* Get the pattern for a given Indentation type.
45
-
* @return the pattern to be used for indenting.
46
-
*/
47
-
publicStringgetPattern() {
48
-
returnpattern;
49
-
}
44
+
/**
45
+
* Get the pattern for a given Indentation type.
46
+
*
47
+
* @return the pattern to be used for indenting.
48
+
*/
49
+
publicStringgetPattern() {
50
+
returnpattern;
51
+
}
50
52
51
-
/**
52
-
* Returns the number of characters a pattern is using.
53
-
* @return the number of characters the pattern of this type consists of.
54
-
*/
55
-
privateintgetNumberOfChars() {
56
-
returnpattern.length();
57
-
}
53
+
/**
54
+
* Returns the number of characters a pattern is using.
55
+
*
56
+
* @return the number of characters the pattern of this type consists of.
57
+
*/
58
+
privateintgetNumberOfChars() {
59
+
returnpattern.length();
60
+
}
61
+
}
58
62
59
-
}
63
+
/**
64
+
* Private enum to denote the current State of the Indentation Process.
65
+
*/
66
+
privateenumIndentationState {
67
+
/**
68
+
* Denotes that the Process is currently in a codeblock and should indent the code accordingly.
69
+
*/
70
+
CODE,
71
+
/**
72
+
* Denotes that the Process is currently in a String literal.
73
+
*/
74
+
STRING,
75
+
/**
76
+
* Denotes that the Indentation Process is currently in a character literal.
77
+
*/
78
+
CHARACTER,
79
+
/**
80
+
* Denotes that the Process is currently in a single line comment.
81
+
*/
82
+
SINGLE_LINE_COMMENT,
83
+
/**
84
+
* Denotes that the process is inside a multi line comment or a javadoc.
85
+
*/
86
+
MULTI_LINE_COMMENT
87
+
}
60
88
61
-
/**
62
-
* Aims to indent the given String using the pattern provided. Will return the String unchanged if {@link IndentationHelper.IndentationType#NULL} is passed as the IndentationType parameter.
63
-
* @param text The text that should be indented.
64
-
* @param type The type of indentation to be used.
65
-
* @return The indented String with the format specified.
* Aims to indent the given String using the pattern provided. Will return the String unchanged if {@link IndentationHelper.IndentationType#NULL} is passed as the IndentationType parameter.
92
+
*
93
+
* @param text The text that should be indented.
94
+
* @param type The type of indentation to be used.
95
+
* @return The indented String with the format specified.
0 commit comments