PHP Code Formatter (concluded)
Revision | 2217ff195d898085919831f31316a217d6e5e32a (tree) |
---|---|
Time | 2014-08-27 13:01:54 |
Author | Hiroaki Kamei <kmtr@outl...> |
Commiter | Hiroaki Kamei |
PHPDOC indent option
@@ -77,6 +77,28 @@ public class OutputBuffer { | ||
77 | 77 | return this; |
78 | 78 | } |
79 | 79 | |
80 | + public OutputBuffer appendNoIndent(String str) { | |
81 | + if (str.equals("")) { | |
82 | + return this; | |
83 | + } | |
84 | + if (Utils.hasCrLf(str)) { | |
85 | + str = Utils.convertCrLf(str); | |
86 | + String[] strings = str.split("\\n"); | |
87 | + for (int i = 0; i < strings.length; i++) { | |
88 | + append(strings[i]); | |
89 | + if (i < strings.length - 1) { | |
90 | + newLine(); | |
91 | + } | |
92 | + } | |
93 | + if (str.endsWith("\n")) { | |
94 | + newLine(); | |
95 | + } | |
96 | + } else { | |
97 | + lineBuffer.append(str); | |
98 | + } | |
99 | + return this; | |
100 | + } | |
101 | + | |
80 | 102 | public OutputBuffer appendRaw(String str, boolean head) { |
81 | 103 | if (str.equals("")) { |
82 | 104 | return this; |
@@ -102,6 +124,29 @@ public class OutputBuffer { | ||
102 | 124 | return this; |
103 | 125 | } |
104 | 126 | |
127 | + | |
128 | + public OutputBuffer appendRawNoIndent(String str, boolean head) { | |
129 | + if (str.equals("")) { | |
130 | + return this; | |
131 | + } | |
132 | + if (Utils.hasCrLf(str)) { | |
133 | + str = Utils.convertCrLf(str); | |
134 | + String[] strings = str.split("\\n"); | |
135 | + for (int i = 0; i < strings.length; i++) { | |
136 | + lineBuffer.append(strings[i]); | |
137 | + if (i < strings.length - 1) { | |
138 | + newLine(true); | |
139 | + } | |
140 | + } | |
141 | + if (str.endsWith("\n")) { | |
142 | + newLine(true); | |
143 | + } | |
144 | + } else { | |
145 | + lineBuffer.append(str); | |
146 | + } | |
147 | + return this; | |
148 | + } | |
149 | + | |
105 | 150 | public OutputBuffer join(String str) { |
106 | 151 | if (lineBuffer.toString().trim().length() == 0) { |
107 | 152 | int index = outputBuffer.size() - 1; |
@@ -280,9 +280,17 @@ public class ASTFormatter extends RunThroughVisitor { | ||
280 | 280 | } |
281 | 281 | } |
282 | 282 | if (i > 0 && pos > 0) { |
283 | - output.appendRaw(leader + s, false); | |
283 | + if (options.indent_phpdoc_comment_indent) { | |
284 | + output.appendRaw(leader + s, false); | |
285 | + } else { | |
286 | + output.appendRawNoIndent(s, false); | |
287 | + } | |
284 | 288 | } else { |
285 | - output.append(s); | |
289 | + if (options.indent_phpdoc_comment_indent) { | |
290 | + output.append(s); | |
291 | + } else { | |
292 | + output.appendNoIndent(s); | |
293 | + } | |
286 | 294 | } |
287 | 295 | if (i < strings.length - 1) { |
288 | 296 | output.newLine(true); |
@@ -1488,6 +1488,20 @@ public class CodeFormatterConstants { | ||
1488 | 1488 | |
1489 | 1489 | /** |
1490 | 1490 | * <pre> |
1491 | + * FORMATTER / Option to indent php doc comment | |
1492 | + * - option id: "org.eclipse.jdt.core.formatter.indent_php_doc_comment_indent" | |
1493 | + * - possible values: { TRUE, FALSE } | |
1494 | + * - default: TRUE | |
1495 | + * </pre> | |
1496 | + * @see #TRUE | |
1497 | + * @see #FALSE | |
1498 | + * @since 3.0 | |
1499 | + */ | |
1500 | + public final static String FORMATTER_INDENT_PHPDOC_COMMENT_INDENT = FormatterPlugin.OPTION_ID | |
1501 | + + ".formatter.indent_phpdoc_comment_indent"; //$NON-NLS-1$ | |
1502 | + | |
1503 | + /** | |
1504 | + * <pre> | |
1491 | 1505 | * FORMATTER / Option to specify the equivalent number of spaces that represents one indentation |
1492 | 1506 | * - option id: "org.eclipse.jdt.core.formatter.indentation.size" |
1493 | 1507 | * - possible values: "<n>", where n is zero or a positive integer |
@@ -102,6 +102,7 @@ public class CodeFormatterOptions { | ||
102 | 102 | public boolean indent_body_declarations_compare_to_type_header; |
103 | 103 | public boolean indent_breaks_compare_to_cases; |
104 | 104 | public boolean indent_empty_lines; |
105 | + public boolean indent_phpdoc_comment_indent; | |
105 | 106 | public boolean indent_switchstatements_compare_to_cases; |
106 | 107 | public boolean indent_switchstatements_compare_to_switch; |
107 | 108 | public int indentation_size; |
@@ -515,6 +516,9 @@ public class CodeFormatterOptions { | ||
515 | 516 | options.put(CodeFormatterConstants.FORMATTER_INDENT_EMPTY_LINES, |
516 | 517 | this.indent_empty_lines ? CodeFormatterConstants.TRUE |
517 | 518 | : CodeFormatterConstants.FALSE); |
519 | + options.put(CodeFormatterConstants.FORMATTER_INDENT_PHPDOC_COMMENT_INDENT, | |
520 | + this.indent_phpdoc_comment_indent ? CodeFormatterConstants.TRUE | |
521 | + : CodeFormatterConstants.FALSE); | |
518 | 522 | options.put( |
519 | 523 | CodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_CASES, |
520 | 524 | this.indent_switchstatements_compare_to_cases ? CodeFormatterConstants.TRUE |
@@ -1869,6 +1873,12 @@ public class CodeFormatterOptions { | ||
1869 | 1873 | this.indent_breaks_compare_to_cases = CodeFormatterConstants.TRUE |
1870 | 1874 | .equals(indentBreaksCompareToCasesOption); |
1871 | 1875 | } |
1876 | + final Object indentCommentBlocksHasIndent = settings | |
1877 | + .get(CodeFormatterConstants.FORMATTER_INDENT_PHPDOC_COMMENT_INDENT); | |
1878 | + if (indentCommentBlocksHasIndent != null) { | |
1879 | + this.indent_phpdoc_comment_indent = CodeFormatterConstants.TRUE | |
1880 | + .equals(indentCommentBlocksHasIndent); | |
1881 | + } | |
1872 | 1882 | final Object indentEmptyLinesOption = settings |
1873 | 1883 | .get(CodeFormatterConstants.FORMATTER_INDENT_EMPTY_LINES); |
1874 | 1884 | if (indentEmptyLinesOption != null) { |
@@ -3157,6 +3167,7 @@ public class CodeFormatterOptions { | ||
3157 | 3167 | this.blank_lines_before_imports = 1; |
3158 | 3168 | this.blank_lines_before_member_type = 1; |
3159 | 3169 | this.blank_lines_before_method = 0; |
3170 | + this.indent_phpdoc_comment_indent = true; | |
3160 | 3171 | this.blank_lines_before_new_chunk = 1; |
3161 | 3172 | this.blank_lines_before_package = 0; |
3162 | 3173 | this.blank_lines_between_import_groups = 1; |
@@ -373,6 +373,7 @@ final class FormatterMessages extends NLS { | ||
373 | 373 | public static String IndentationTabPage_switch_group_option_indent_break_statements; |
374 | 374 | public static String IndentationTabPage_indent_empty_lines; |
375 | 375 | public static String IndentationTabPage_use_tabs_only_for_leading_indentations; |
376 | + public static String IndentationTabPage_phpdoc_comment_indent; | |
376 | 377 | |
377 | 378 | public static String OffOnTagsTabPage_description; |
378 | 379 | public static String OffOnTagsTabPage_enableOffOnTags; |
@@ -568,3 +568,5 @@ WhiteSpaceOptions_trait_use=Trait 'use' | ||
568 | 568 | WhiteSpaceTabPage_trait_use=Trait 'use' |
569 | 569 | WhiteSpaceTabPage_before_comma_in_trait_use=Before comma in trait 'use' |
570 | 570 | WhiteSpaceTabPage_after_comma_in_trait_use=After comma in trait 'use' |
571 | + | |
572 | +IndentationTabPage_phpdoc_comment_indent=Indent PHPDOC comment |
@@ -383,3 +383,5 @@ WhiteSpaceOptions_trait_use=Trait 'use' | ||
383 | 383 | WhiteSpaceTabPage_trait_use=Trait 'use' |
384 | 384 | WhiteSpaceTabPage_before_comma_in_trait_use=Trait\u306E'use'\u6587\u306E\u30AB\u30F3\u30DE\u306E\u524D |
385 | 385 | WhiteSpaceTabPage_after_comma_in_trait_use=Trait\u306E'use'\u6587\u306E\u30AB\u30F3\u30DE\u306E\u5F8C |
386 | + | |
387 | +IndentationTabPage_phpdoc_comment_indent=PHPDOC\u3092\u30a4\u30f3\u30c7\u30f3\u30c8\u3059\u308b |
@@ -30,6 +30,9 @@ public class IndentationTabPage extends FormatterTabPage { | ||
30 | 30 | "var $theInt=1;" + //$NON-NLS-1$ |
31 | 31 | "var $someString=\"Hello\";" + //$NON-NLS-1$ |
32 | 32 | "var $aDouble=3.0;\n\n" + //$NON-NLS-1$ |
33 | + "/**\n" + //$NON-NLS-1$ | |
34 | + " * PHP DOC\n" + //$NON-NLS-1$ | |
35 | + " */\n" + //$NON-NLS-1$ | |
33 | 36 | "function foo() {" + //$NON-NLS-1$ |
34 | 37 | "switch($a){" + //$NON-NLS-1$ |
35 | 38 | "case 0:" + //$NON-NLS-1$ |
@@ -177,6 +180,11 @@ public class IndentationTabPage extends FormatterTabPage { | ||
177 | 180 | createCheckboxPref(classGroup, numColumns, |
178 | 181 | FormatterMessages.IndentationTabPage_indent_empty_lines, |
179 | 182 | CodeFormatterConstants.FORMATTER_INDENT_EMPTY_LINES, FALSE_TRUE); |
183 | + | |
184 | + //with comment indent pref | |
185 | + createCheckboxPref(classGroup, numColumns, | |
186 | + FormatterMessages.IndentationTabPage_phpdoc_comment_indent, | |
187 | + CodeFormatterConstants.FORMATTER_INDENT_PHPDOC_COMMENT_INDENT, FALSE_TRUE); | |
180 | 188 | } |
181 | 189 | |
182 | 190 | public void initializePage() { |