@@ -172,7 +172,8 @@ public Void visitLiteral(LiteralTree literalTree, Void aVoid) {
172172 return null ;
173173 }
174174 int pos = getStartPosition (literalTree );
175- if (input .substring (pos , Math .min (input .length (), pos + 3 )).equals (TEXT_BLOCK_DELIMITER )) {
175+ if (input .substring (pos , Math .min (input .length (), pos + TEXT_BLOCK_DELIMITER .length ()))
176+ .equals (TEXT_BLOCK_DELIMITER )) {
176177 textBlocks .add (getCurrentPath ());
177178 return null ;
178179 }
@@ -269,11 +270,8 @@ private Map<TreePath, String> computeCustomTextBlocksIndent(List<TreePath> textB
269270 Tree parent = parentPath .getLeaf ();
270271 if (parent instanceof MethodInvocationTree ) {
271272 textBlockToParent .put (textBlock , parent );
272- if (parentToIndent .containsKey (parent )) {
273- continue ;
274- }
275273 List <Tree > allArguments = new ArrayList <>(((JCMethodInvocation ) parent ).getArguments ());
276- parentToIndent .put (
274+ parentToIndent .computeIfAbsent (
277275 parent ,
278276 // A method can be split in multiple lines (eg. for field access
279277 // Class.builder()
@@ -282,18 +280,18 @@ private Map<TreePath, String> computeCustomTextBlocksIndent(List<TreePath> textB
282280 // In this case the parent of the arguments should be the method ("Class.builder().method")
283281 // the indentation of the arguments will be relative to the indentation of the last line of
284282 // the method name.
285- computePrefixIndentation (
286- ((JCMethodInvocation ) parent ).getMethodSelect (), allArguments , false ));
283+ parentTree -> computePrefixIndentation (
284+ ((JCMethodInvocation ) parentTree ).getMethodSelect (), allArguments , false ));
287285 } else if (parent .getKind () == Kind .PLUS ) {
288286 while (parentPath .getParentPath ().getLeaf ().getKind () == Kind .PLUS ) {
289287 parentPath = parentPath .getParentPath ();
290288 }
291- parent = parentPath .getLeaf ();
292- textBlockToParent .put (textBlock , parent );
293- if ( parentToIndent .containsKey ( parent )) {
294- continue ;
295- }
296- parentToIndent . put ( parent , computePrefixIndentation ( parent , flattenExpressionTree (parent ), true ));
289+ Tree concatenationRoot = parentPath .getLeaf ();
290+ textBlockToParent .put (textBlock , concatenationRoot );
291+ parentToIndent .computeIfAbsent (
292+ concatenationRoot ,
293+ concatenationRootTree -> computePrefixIndentation (
294+ concatenationRootTree , flattenExpressionTree (concatenationRootTree ), true ));
297295 }
298296 }
299297
@@ -313,14 +311,12 @@ private String computePrefixIndentation(
313311 .negate ()
314312 .indexIn (input .substring (lineParentStartPosition , endParentPosition ));
315313 int extraIndent = 4 ;
316- RangeSet <Integer > allRanges = TreeRangeSet .create ();
317314 for (Tree expression : childExpressions ) {
318315 int startingPos = getStartPosition (expression );
319316 int startLine = lineMap .getLineNumber (startingPos );
320317 int lineStartPosition = lineMap .getStartPosition (startLine );
321318 int endPos = getEndPosition (unit , expression );
322319 int endLine = lineMap .getLineNumber (endPos );
323- allRanges .add (Range .closed (startLine , endLine ));
324320 int parentLine = shouldUseStartLineParent ? startParentLine : endParentLine ;
325321 // ignore indentation if the current argument is on the same line as the parent
326322 if (startLine == parentLine ) {
@@ -329,7 +325,7 @@ private String computePrefixIndentation(
329325 // if this is a line that ends a textBlock (if the line starts with triple quotes & the current tree
330326 // starts after)
331327 int startColumn = CharMatcher .whitespace ().negate ().indexIn (input .substring (lineStartPosition , endPos ));
332- if (input .startsWith (" \" \" \" " , lineStartPosition + startColumn )
328+ if (input .startsWith (TEXT_BLOCK_DELIMITER , lineStartPosition + startColumn )
333329 && startingPos != lineStartPosition + startColumn ) {
334330 continue ;
335331 }
0 commit comments