Skip to content

Commit

Permalink
Don't throw exception from K.Constructor#withType() (#462)
Browse files Browse the repository at this point in the history
As the constructor's type must be changed through `K.Constructor#methodDeclaration`, the `withType()` method is now simply a no-op (which is also something we do in some other places).

Fixes: #433
  • Loading branch information
knutwannheden authored Nov 22, 2023
1 parent d47f64e commit 075e40a
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/openrewrite/kotlin/tree/K.java
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ public Constructor(UUID id, Markers markers, J.MethodDeclaration methodDeclarati

@Override
public Constructor withType(@Nullable JavaType type) {
throw new UnsupportedOperationException("To change the return type of this constructor, use withMethodType(..)");
return this; // type must be changed on method declaration
}

@Override
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/org/openrewrite/kotlin/ChangePackageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.openrewrite.kotlin;

import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.ExpectedToFail;
import org.openrewrite.DocumentExample;
import org.openrewrite.Issue;
import org.openrewrite.PathUtils;
Expand Down Expand Up @@ -169,7 +168,6 @@ class Dog : Animal() {
);
}

@ExpectedToFail
@Issue("https://github.com/openrewrite/rewrite-kotlin/issues/433")
@Test
void changePackageSecondaryConstructor() {
Expand Down
1 change: 0 additions & 1 deletion src/test/java/org/openrewrite/kotlin/ChangeTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ class A(val a: Metrics)
);
}

@ExpectedToFail
@Issue("https://github.com/openrewrite/rewrite-kotlin/issues/433")
@Test
void changeImportSecondaryConstructor() {
Expand Down

0 comments on commit 075e40a

Please sign in to comment.