Skip to content

Commit

Permalink
Fix issue 401 kdocBeforeValueParameter (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
kunli2 authored Nov 15, 2023
1 parent 1c21420 commit 976c84e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ public J visitParameter(KtParameter parameter, ExecutionContext data) {
}

JavaType.Variable vt = variableType(parameter, owner(parameter));
J.Identifier name = createIdentifier(requireNonNull(parameter.getNameIdentifier()), vt);
J.Identifier name = createIdentifier(requireNonNull(parameter.getNameIdentifier()), vt, consumedSpaces);

if (parameter.getTypeReference() != null) {
markers = markers.addIfAbsent(new TypeReferencePrefix(randomId(), prefix(parameter.getColon())));
Expand Down Expand Up @@ -903,26 +903,9 @@ public J visitPrimaryConstructor(KtPrimaryConstructor constructor, ExecutionCont
JContainer<Statement> params;

if (constructor.getValueParameterList() != null) {
// constructor.getValueParameterList().accept(this, data);

// todo. move to constructor.getValueParameterList().accept(this, data);
List<KtParameter> ktParameters = constructor.getValueParameters();
List<JRightPadded<Statement>> statements = new ArrayList<>(ktParameters.size());

for (int i = 0; i < ktParameters.size(); i++) {
KtParameter ktParameter = ktParameters.get(i);
Statement statement = convertToStatement(ktParameter.accept(this, data));
statements.add(maybeTrailingComma(ktParameter, padRight(statement, endFixAndSuffix(ktParameter)), i == ktParameters.size() - 1));
}

if (ktParameters.isEmpty()) {
Statement param = new J.Empty(randomId(), prefix(constructor.getValueParameterList().getRightParenthesis()), Markers.EMPTY);
statements.add(padRight(param, Space.EMPTY));
}

params = JContainer.build(
prefix(constructor.getValueParameterList()),
statements,
prefix(constructor.getValueParameterList(), preConsumedInfix(constructor)),
mapParameters(constructor.getValueParameterList(), data),
Markers.EMPTY);
} else {
throw new UnsupportedOperationException("TODO");
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/org/openrewrite/kotlin/tree/CommentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,25 @@ class CodeGenConfig(
)
);
}

@Issue("https://github.com/openrewrite/rewrite-kotlin/issues/401")
@ParameterizedTest
@ValueSource(strings = {
"var name: Boolean = true",
"variable: Boolean = true"
})
void kdocBeforeValueParameter(String input) {
rewriteRun(
kotlin(
"""
class Test(
/**
*
*/
%s
)
""".formatted(input)
)
);
}
}

0 comments on commit 976c84e

Please sign in to comment.