Java Code Examples for org.eclipse.jdt.core.formatter.CodeFormatter#F_INCLUDE_COMMENTS
The following examples show how to use
org.eclipse.jdt.core.formatter.CodeFormatter#F_INCLUDE_COMMENTS .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavadocLineBreakPreparator.java From spring-javaformat with Apache License 2.0 | 5 votes |
@Override public void apply(int kind, TokenManager tokenManager, ASTNode astRoot) { if ((kind & CodeFormatter.F_INCLUDE_COMMENTS) != 0) { ASTVisitor visitor = new Vistor(tokenManager); for (Comment comment : getComments(astRoot)) { comment.accept(visitor); } } }
Example 2
Source File: FormatterHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private int getFormattingKind(ICompilationUnit cu, boolean includeComments) { int kind = includeComments ? CodeFormatter.F_INCLUDE_COMMENTS : 0; if (cu.getResource() != null && cu.getResource().getName().equals(IModule.MODULE_INFO_JAVA)) { kind |= CodeFormatter.K_MODULE_INFO; } else { kind |= CodeFormatter.K_COMPILATION_UNIT; } return kind; }
Example 3
Source File: GoogleJavaFormatter.java From google-java-format with Apache License 2.0 | 5 votes |
/** 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; } }
Example 4
Source File: Scribe.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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(); }
Example 5
Source File: Scribe.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
void setIncludeComments(boolean on) { if (on) { this.formatComments |= CodeFormatter.F_INCLUDE_COMMENTS; } else { this.formatComments &= ~CodeFormatter.F_INCLUDE_COMMENTS; } }
Example 6
Source File: CodeFormatterFlags.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 4 votes |
public static int getFlagsForCompilationUnitFormat() { return CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS; }
Example 7
Source File: Scribe.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
boolean includesComments() { return (this.formatComments & CodeFormatter.F_INCLUDE_COMMENTS) != 0; }