Skip to content

Commit

Permalink
Added type validation to Assertions.
Browse files Browse the repository at this point in the history
Disabled type validation on tests with intentionally unresolvable types.
Fixed NPE in KotlinPrinter.
Fixed errors in AnnotationTest.
  • Loading branch information
traceyyoshima committed Dec 13, 2023
1 parent d2b4cae commit e333f1d
Show file tree
Hide file tree
Showing 10 changed files with 477 additions and 127 deletions.
342 changes: 334 additions & 8 deletions src/main/java/org/openrewrite/kotlin/Assertions.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ public J visitVariableDeclarations(J.VariableDeclarations multiVariable, PrintOu
p.append("val");
}

if (m.getType() == J.Modifier.Type.LanguageExtension && m.getKeyword().equals("typealias")) {
if (m.getType() == J.Modifier.Type.LanguageExtension && m.getKeyword() != null && m.getKeyword().equals("typealias")) {
isTypeAlias = true;
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/openrewrite/kotlin/search/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2023 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
@NonNullFields
package org.openrewrite.kotlin.search;

import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.internal.lang.NonNullFields;
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.openrewrite.java.tree.TypeUtils;
import org.openrewrite.kotlin.tree.K;
import org.openrewrite.test.RewriteTest;
import org.openrewrite.test.TypeValidation;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -947,6 +948,7 @@ class A : RemoteStub()
@Test
void unknownIdentifier() {
rewriteRun(
spec -> spec.typeValidationOptions(TypeValidation.none()),
kotlin(
//language=none
"class A : RemoteStub",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.openrewrite.style.NamedStyles;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import org.openrewrite.test.TypeValidation;

import java.util.function.Consumer;
import java.util.function.UnaryOperator;
Expand Down Expand Up @@ -2223,8 +2224,11 @@ fun test0() {
@Test
void trailingLambdaCall() {
rewriteRun(
spec -> spec.typeValidationOptions(TypeValidation.none()),
kotlin(
"""
import kotlin.reflect.full.memberProperties
inline fun <reified T : Any> T.destruct(): Map<String, Any?> {
return T::class.memberProperties.map {
it.name to it.get(this)
Expand Down
Loading

0 comments on commit e333f1d

Please sign in to comment.