private void alignAssignmentStatements(List<Statement> statements) { List<List<ExpressionStatement>> assignmentGroups = toAlignGroups(statements, n -> optionalCast(n, ExpressionStatement.class) .filter(es -> es.getExpression() instanceof Assignment)); this.alignGroups.addAll(assignmentGroups); AlignIndexFinder<ExpressionStatement> assignFinder = es -> { Assignment a = (Assignment) es.getExpression(); int operatorIndex = this.tm.firstIndexBefore(a.getRightHandSide(), -1); while (this.tm.get(operatorIndex).isComment()) operatorIndex--; return Optional.of(operatorIndex); }; assignmentGroups.forEach(ag -> alignNodes(ag, assignFinder)); if (this.options.align_with_spaces || this.options.tab_char != DefaultCodeFormatterOptions.TAB) { // align assign operators on their right side (e.g. +=, >>=) for (List<ExpressionStatement> group : assignmentGroups) { List<Token> assignTokens = group.stream() .map(assignFinder::findIndex) .filter(Optional::isPresent) .map(o -> this.tm.get(o.get())) .collect(toList()); int maxWidth = assignTokens.stream().mapToInt(Token::countChars).max().orElse(0); for (Token token : assignTokens) token.setAlign(token.getAlign() + maxWidth - token.countChars()); } } }
if (token.hasNLSTag()) { this.nlsTags.add(token); position += token.countChars() + (token.isSpaceBefore() ? 1 : 0);
if (token.hasNLSTag()) { this.nlsTags.add(token); position += token.countChars() + (token.isSpaceBefore() ? 1 : 0);
if (token.hasNLSTag()) { this.nlsTags.add(token); position += token.countChars() + (token.isSpaceBefore() ? 1 : 0);
private boolean tokenizeMultilineComment(Token commentToken) { if (this.allowSubstituteWrapping == null || this.allowSubstituteWrapping.length < commentToken.countChars()) { this.allowSubstituteWrapping = new boolean[commentToken.countChars()]; Arrays.fill(this.allowSubstituteWrapping, 0, commentToken.countChars(), !isJavadoc);
private boolean tokenizeMultilineComment(Token commentToken) { if (this.allowSubstituteWrapping == null || this.allowSubstituteWrapping.length < commentToken.countChars()) { this.allowSubstituteWrapping = new boolean[commentToken.countChars()]; Arrays.fill(this.allowSubstituteWrapping, 0, commentToken.countChars(), !isJavadoc);
private boolean tokenizeMultilineComment(Token commentToken) { if (this.allowSubstituteWrapping == null || this.allowSubstituteWrapping.length < commentToken.countChars()) { this.allowSubstituteWrapping = new boolean[commentToken.countChars()]; Arrays.fill(this.allowSubstituteWrapping, 0, commentToken.countChars(), !isJavadoc);
for (Token token : this.tokens) { if (token.tokenType == TokenNameCOMMENT_JAVADOC) { parser.setSourceRange(token.originalStart, token.countChars()); CompilationUnit cu = (CompilationUnit) parseSourceCode(parser, ASTParser.K_COMPILATION_UNIT, true);