Skip to content

Commit 98f5f53

Browse files
committed
comments
1 parent 1815e21 commit 98f5f53

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

palantir-java-format/src/main/java/com/palantir/javaformat/java/StringWrapper.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ private void indentTextBlocks(TreeRangeMap<Integer, String> replacements, List<T
256256
* In order to compute the indentation value we need to do:
257257
* 1. for each textBlock find the enclosing block/parent (only for concat expressions/method invocations)
258258
* 2. for each parent, find the arguments/concatenated expressions and find the max indentation level
259+
* (ignore the lines that start with a text block ending)
259260
* 3. store the mapping between the textBlock and the indentation level computed before.
260261
*/
261262
private Map<TreePath, String> computeCustomTextBlocksIndent(List<TreePath> textBlocks) {
@@ -269,12 +270,16 @@ private Map<TreePath, String> computeCustomTextBlocksIndent(List<TreePath> textB
269270
if (parentToIndent.containsKey(parent)) {
270271
continue;
271272
}
272-
// Tree finalParent = (((JCMethodInvocation) parent).getMethodSelect() instanceof JCFieldAccess ?
273-
// ((JCMethodInvocation) parent).getMethodSelect() : parent;
274273
List<Tree> allArguments = new ArrayList<>(((JCMethodInvocation) parent).getArguments());
275-
276274
parentToIndent.put(
277275
parent,
276+
// A method can be split in multiple lines (eg. for field access
277+
// Class.builder()
278+
// .method("arguments")
279+
// .build()
280+
// In this case the parent of the arguments should be the method ("Class.builder().method")
281+
// the indentation of the arguments will be relative to the indentation of the last line of
282+
// the method name.
278283
computePrefixIndentation(
279284
((JCMethodInvocation) parent).getMethodSelect(), allArguments, false));
280285
} else if (parent.getKind() == Kind.PLUS) {
@@ -300,8 +305,6 @@ private String computePrefixIndentation(
300305
int startParentLine = lineMap.getLineNumber(startParentPosition);
301306
int endParentPosition = getEndPosition(unit, parentPath);
302307
int endParentLine = lineMap.getLineNumber(endParentPosition);
303-
// the only relevant lineParentEndPosition should be the one that doesn't end with a """
304-
// because that one is not valid
305308
int lineParentStartPosition =
306309
lineMap.getStartPosition(shouldUseStartLineParent ? startParentLine : endParentLine);
307310
int startParentColumn = CharMatcher.whitespace()
@@ -321,8 +324,8 @@ private String computePrefixIndentation(
321324
if (startLine == parentLine) {
322325
continue;
323326
}
324-
// if this is a line that ends with a textBlock (ending with a textBlock if the line starts with
325-
// triple quotes & the current tree starts later on the line)
327+
// if this is a line that ends a textBlock (if the line starts with triple quotes & the current tree
328+
// starts after)
326329
int startColumn = CharMatcher.whitespace().negate().indexIn(input.substring(lineStartPosition, endPos));
327330
if (input.startsWith("\"\"\"", lineStartPosition + startColumn)
328331
&& startingPos != lineStartPosition + startColumn) {

0 commit comments

Comments
 (0)