本文整理汇总了Java中org.eclipse.jdt.core.formatter.CodeFormatter.F_INCLUDE_COMMENTS属性的典型用法代码示例。如果您正苦于以下问题:Java CodeFormatter.F_INCLUDE_COMMENTS属性的具体用法?Java CodeFormatter.F_INCLUDE_COMMENTS怎么用?Java CodeFormatter.F_INCLUDE_COMMENTS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.eclipse.jdt.core.formatter.CodeFormatter
的用法示例。
在下文中一共展示了CodeFormatter.F_INCLUDE_COMMENTS属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatInternal
/** Runs the Google Java formatter on the given source, with only the given ranges specified. */
private TextEdit formatInternal(int kind, String source, IRegion[] regions, int initialIndent) {
try {
boolean includeComments =
(kind & CodeFormatter.F_INCLUDE_COMMENTS) == CodeFormatter.F_INCLUDE_COMMENTS;
kind &= ~CodeFormatter.F_INCLUDE_COMMENTS;
SnippetKind snippetKind;
switch (kind) {
case ASTParser.K_EXPRESSION:
snippetKind = SnippetKind.EXPRESSION;
break;
case ASTParser.K_STATEMENTS:
snippetKind = SnippetKind.STATEMENTS;
break;
case ASTParser.K_CLASS_BODY_DECLARATIONS:
snippetKind = SnippetKind.CLASS_BODY_DECLARATIONS;
break;
case ASTParser.K_COMPILATION_UNIT:
snippetKind = SnippetKind.COMPILATION_UNIT;
break;
default:
throw new IllegalArgumentException(String.format("Unknown snippet kind: %d", kind));
}
List<Replacement> replacements =
new SnippetFormatter()
.format(
snippetKind, source, rangesFromRegions(regions), initialIndent, includeComments);
if (idempotent(source, regions, replacements)) {
// Do not create edits if there's no diff.
return null;
}
// Convert replacements to text edits.
return editFromReplacements(replacements);
} catch (IllegalArgumentException | FormatterException exception) {
// Do not format on errors.
return null;
}
}
示例2: Scribe
Scribe(CodeFormatterVisitor formatter, long sourceLevel, IRegion[] regions, CodeSnippetParsingUtil codeSnippetParsingUtil, boolean includeComments) {
initializeScanner(sourceLevel, formatter.preferences);
this.formatter = formatter;
this.pageWidth = formatter.preferences.page_width;
this.tabLength = formatter.preferences.tab_size;
this.indentationLevel= 0; // initialize properly
this.numberOfIndentations = 0;
this.useTabsOnlyForLeadingIndents = formatter.preferences.use_tabs_only_for_leading_indentations;
this.indentEmptyLines = formatter.preferences.indent_empty_lines;
this.tabChar = formatter.preferences.tab_char;
if (this.tabChar == DefaultCodeFormatterOptions.MIXED) {
this.indentationSize = formatter.preferences.indentation_size;
} else {
this.indentationSize = this.tabLength;
}
this.lineSeparator = formatter.preferences.line_separator;
this.lineSeparatorAndSpace = this.lineSeparator+' ';
this.firstLS = this.lineSeparator.charAt(0);
this.lsLength = this.lineSeparator.length();
this.indentationLevel = formatter.preferences.initial_indentation_level * this.indentationSize;
this.regions= regions;
if (codeSnippetParsingUtil != null) {
final RecordedParsingInformation information = codeSnippetParsingUtil.recordedParsingInformation;
if (information != null) {
this.lineEnds = information.lineEnds;
this.commentPositions = information.commentPositions;
}
}
if (formatter.preferences.comment_format_line_comment) this.formatComments |= CodeFormatter.K_SINGLE_LINE_COMMENT;
if (formatter.preferences.comment_format_block_comment) this.formatComments |= CodeFormatter.K_MULTI_LINE_COMMENT;
if (formatter.preferences.comment_format_javadoc_comment) this.formatComments |= CodeFormatter.K_JAVA_DOC;
if (includeComments) this.formatComments |= CodeFormatter.F_INCLUDE_COMMENTS;
reset();
}
示例3: setIncludeComments
void setIncludeComments(boolean on) {
if (on) {
this.formatComments |= CodeFormatter.F_INCLUDE_COMMENTS;
} else {
this.formatComments &= ~CodeFormatter.F_INCLUDE_COMMENTS;
}
}
示例4: getFlagsForCompilationUnitFormat
public static int getFlagsForCompilationUnitFormat() {
return CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS;
}
示例5: includesComments
boolean includesComments() {
return (this.formatComments & CodeFormatter.F_INCLUDE_COMMENTS) != 0;
}