Skip to content

Commit

Permalink
support method declaration parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
kunli2 committed Oct 5, 2023
1 parent bef1f08 commit 654ee82
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,50 @@ public J visitNullableType(KtNullableType nullableType, ExecutionContext data) {

@Override
public J visitParameter(KtParameter parameter, ExecutionContext data) {
throw new UnsupportedOperationException("TODO");
Markers markers = Markers.EMPTY;
List<J.Annotation> leadingAnnotations = new ArrayList<>();
List<J.Modifier> modifiers = new ArrayList<>();
TypeTree typeExpression = null;
List<JRightPadded<J.VariableDeclarations.NamedVariable>> vars = new ArrayList<>(1);

if (!parameter.getAnnotations().isEmpty()) {
throw new UnsupportedOperationException("TODO");
}

if (parameter.getValOrVarKeyword() != null) {
throw new UnsupportedOperationException("TODO");
}

J.Identifier name = createIdentifier(parameter.getName(), Space.EMPTY, type(parameter));

if (parameter.getTypeReference() != null) {
markers = markers.addIfAbsent(new TypeReferencePrefix(randomId(), prefix(parameter.getColon())));
typeExpression = parameter.getTypeReference().accept(this, data).withPrefix(prefix(parameter.getTypeReference()));
}

J.VariableDeclarations.NamedVariable namedVariable = new J.VariableDeclarations.NamedVariable(
randomId(),
Space.EMPTY,
Markers.EMPTY,
name,
emptyList(),
null,
variableType(parameter)
);

vars.add(padRight(namedVariable, suffix(parameter)));

return new J.VariableDeclarations(
randomId(),
prefix(parameter),
markers,
leadingAnnotations,
modifiers,
typeExpression,
null,
emptyList(),
vars
);
}

@Override
Expand Down Expand Up @@ -1341,7 +1384,11 @@ public J visitNamedFunction(KtNamedFunction function, ExecutionContext data) {
), Markers.EMPTY
);
} else {
throw new UnsupportedOperationException("TODO");
List<JRightPadded<Statement>> rps = new ArrayList<>();
for (KtParameter param : ktParameters) {
rps.add(padRight(convertToStatement(param.accept(this, data)), Space.EMPTY));
}
params = JContainer.build(prefix(function.getValueParameterList()), rps, Markers.EMPTY);
}

if (function.getTypeReference() != null) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/openrewrite/kotlin/tree/CommentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.ExpectedToFail;
import org.openrewrite.Issue;
import org.openrewrite.test.RewriteTest;

Expand Down Expand Up @@ -79,7 +80,7 @@ internal fun method() {
);
}

@Disabled("To be supported")
@ExpectedToFail("corrected")
@Issue("https://github.com/openrewrite/rewrite-kotlin/issues/320")
@Test
void nestedComment() {
Expand Down

0 comments on commit 654ee82

Please sign in to comment.