diff --git a/src/test/java/org/openrewrite/kotlin/KotlinIrTypeMappingTest.java b/src/test/java/org/openrewrite/kotlin/KotlinIrTypeMappingTest.java index 0137bfdf7..76e7b4692 100644 --- a/src/test/java/org/openrewrite/kotlin/KotlinIrTypeMappingTest.java +++ b/src/test/java/org/openrewrite/kotlin/KotlinIrTypeMappingTest.java @@ -172,7 +172,7 @@ public String methodType(String methodName) { void fileField() { IrProperty property = getCompiledSource().getDeclarations().stream() .filter(it -> it instanceof IrProperty && "field".equals(((IrProperty) it).getName().asString())) - .map(it -> (IrProperty) it).findFirst().orElseThrow(); + .map(IrProperty.class::cast).findFirst().orElseThrow(); assertThat(typeMapper().variableType(property).toString()) .isEqualTo("org.openrewrite.kotlin.KotlinTypeGoatKt{name=field,type=kotlin.Int}"); } @@ -181,7 +181,7 @@ void fileField() { void fileFunction() { IrFunction function = getCompiledSource().getDeclarations().stream() .filter(it -> it instanceof IrFunction && "function".equals(((IrFunction) it).getName().asString())) - .map(it -> (IrFunction) it).findFirst().orElseThrow(); + .map(IrFunction.class::cast).findFirst().orElseThrow(); assertThat(typeMapper().methodDeclarationType(function).toString()) .isEqualTo("org.openrewrite.kotlin.KotlinTypeGoatKt{name=function,return=kotlin.Unit,parameters=[org.openrewrite.kotlin.C]}"); } diff --git a/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java b/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java index e3d3a1ffd..c3edbe500 100644 --- a/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java +++ b/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java @@ -83,7 +83,7 @@ public JavaType.Method methodType(String methodName) { public K.Property getProperty(String fieldName) { return goatClassDeclaration.getClassDeclaration().getBody().getStatements().stream() - .filter(it -> it instanceof K.Property) + .filter(K.Property.class::isInstance) .map(K.Property.class::cast) .filter(mv -> mv.getVariableDeclarations().getVariables().stream().anyMatch(v -> v.getSimpleName().equals(fieldName))) .findFirst() @@ -110,7 +110,7 @@ void fieldType() { assertThat(id.getType()).isInstanceOf(JavaType.Class.class); assertThat(id.getType().toString()).isEqualTo("kotlin.Int"); - J.MethodDeclaration getter = property.getAccessors().getElements().stream().filter(x -> x.getName().getSimpleName().equals("get")).findFirst().orElse(null); + J.MethodDeclaration getter = property.getAccessors().getElements().stream().filter(x -> "get".equals(x.getName().getSimpleName())).findFirst().orElse(null); JavaType.FullyQualified declaringType = getter.getMethodType().getDeclaringType(); assertThat(declaringType.getFullyQualifiedName()).isEqualTo("org.openrewrite.kotlin.KotlinTypeGoat"); assertThat(getter.getMethodType().getName()).isEqualTo("get"); @@ -118,7 +118,7 @@ void fieldType() { assertThat(getter.getName().getType()).isEqualTo(getter.getMethodType()); assertThat(getter.getMethodType().toString().substring(declaringType.toString().length())).isEqualTo("{name=get,return=kotlin.Int,parameters=[]}"); - J.MethodDeclaration setter = property.getAccessors().getElements().stream().filter(x -> x.getName().getSimpleName().equals("set")).findFirst().orElse(null); + J.MethodDeclaration setter = property.getAccessors().getElements().stream().filter(x -> "set".equals(x.getName().getSimpleName())).findFirst().orElse(null); declaringType = setter.getMethodType().getDeclaringType(); assertThat(declaringType.getFullyQualifiedName()).isEqualTo("org.openrewrite.kotlin.KotlinTypeGoat"); assertThat(setter.getMethodType().getName()).isEqualTo("set"); @@ -129,7 +129,7 @@ void fieldType() { @Test void fileField() { J.VariableDeclarations.NamedVariable nv = cu.getStatements().stream() - .filter(it -> it instanceof J.VariableDeclarations) + .filter(J.VariableDeclarations.class::isInstance) .flatMap(it -> ((J.VariableDeclarations) it).getVariables().stream()) .filter(it -> "field".equals(it.getSimpleName())).findFirst().orElseThrow(); @@ -142,7 +142,7 @@ void fileField() { @Test void fileFunction() { J.MethodDeclaration md = cu.getStatements().stream() - .filter(it -> it instanceof J.MethodDeclaration) + .filter(J.MethodDeclaration.class::isInstance) .map(J.MethodDeclaration.class::cast) .filter(it -> "function".equals(it.getSimpleName())).findFirst().orElseThrow(); @@ -199,7 +199,7 @@ void parameterized() { .map(J.MethodDeclaration.class::cast).findFirst().orElseThrow(); assertThat(md.getMethodType().toString()) .isEqualTo("org.openrewrite.kotlin.KotlinTypeGoat{name=parameterized,return=org.openrewrite.kotlin.PT,parameters=[org.openrewrite.kotlin.PT]}"); - J.VariableDeclarations vd = ((J.VariableDeclarations) md.getParameters().get(0)); + J.VariableDeclarations vd = (J.VariableDeclarations) md.getParameters().get(0); assertThat(vd.getTypeExpression().getType().toString()) .isEqualTo("org.openrewrite.kotlin.PT"); assertThat(((J.ParameterizedType) vd.getTypeExpression()).getClazz().getType().toString()) @@ -1267,7 +1267,7 @@ void annotationOnKotlinConeType(String input, String type) { new KotlinIsoVisitor() { @Override public J.Annotation visitAnnotation(J.Annotation annotation, Integer integer) { - assertThat(String.valueOf(annotation.getType().toString())).isEqualTo(type); + assertThat(annotation.getType().toString()).isEqualTo(type); found.set(true); return super.visitAnnotation(annotation, integer); } @@ -1316,11 +1316,11 @@ class Test { new KotlinIsoVisitor() { @Override public J.Identifier visitIdentifier(J.Identifier identifier, Integer integer) { - if (identifier.getSimpleName().equals("lang")) { + if ("lang".equals(identifier.getSimpleName())) { assertThat(identifier.getType()).isNull(); isFieldTargetNull.set(true); } - if (identifier.getSimpleName().equals("StringBuilder")) { + if ("StringBuilder".equals(identifier.getSimpleName())) { assertThat(identifier.getType().toString()).isEqualTo("java.lang.StringBuilder"); isStringBuilderTyped.set(true); } @@ -1419,15 +1419,12 @@ fun bar(b: Array) {} new KotlinIsoVisitor() { @Override public J.Identifier visitIdentifier(J.Identifier identifier, Integer integer) { - switch (identifier.getSimpleName()) { - case "String" -> { - assertThat(identifier.getType().toString()).isEqualTo("kotlin.String"); - count.incrementAndGet(); - } - case "Number" -> { - assertThat(identifier.getType().toString()).isEqualTo("kotlin.Number"); - count.incrementAndGet(); - } + if ("String".equals(identifier.getSimpleName())) { + assertThat(identifier.getType().toString()).isEqualTo("kotlin.String"); + count.incrementAndGet(); + } else if ("Number".equals(identifier.getSimpleName())) { + assertThat(identifier.getType().toString()).isEqualTo("kotlin.Number"); + count.incrementAndGet(); } return super.visitIdentifier(identifier, integer); } diff --git a/src/test/java/org/openrewrite/kotlin/style/AutodetectTest.java b/src/test/java/org/openrewrite/kotlin/style/AutodetectTest.java index 228dbd9bb..eebb608e3 100644 --- a/src/test/java/org/openrewrite/kotlin/style/AutodetectTest.java +++ b/src/test/java/org/openrewrite/kotlin/style/AutodetectTest.java @@ -493,15 +493,15 @@ class Test { assertThat(importLayout.getLayout().get(1)) .isInstanceOf(ImportLayoutStyle.Block.ImportPackage.class) - .matches(b -> ((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString().equals("java\\..+")); + .matches(b -> "java\\..+".equals(((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString())); assertThat(importLayout.getLayout().get(2)) .isInstanceOf(ImportLayoutStyle.Block.ImportPackage.class) - .matches(b -> ((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString().equals("javax\\..+")); + .matches(b -> "javax\\..+".equals(((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString())); assertThat(importLayout.getLayout().get(3)) .isInstanceOf(ImportLayoutStyle.Block.ImportPackage.class) - .matches(b -> ((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString().equals("kotlin\\..+")); + .matches(b -> "kotlin\\..+".equals(((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString())); assertThat(importLayout.getLayout().get(4)).isInstanceOf(ImportLayoutStyle.Block.AllAliases.class); } @@ -551,15 +551,15 @@ class Test { assertThat(importLayout.getLayout().get(1)) .isInstanceOf(ImportLayoutStyle.Block.ImportPackage.class) - .matches(b -> ((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString().equals("kotlin\\..+")); + .matches(b -> "kotlin\\..+".equals(((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString())); assertThat(importLayout.getLayout().get(2)) .isInstanceOf(ImportLayoutStyle.Block.ImportPackage.class) - .matches(b -> ((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString().equals("javax\\..+")); + .matches(b -> "javax\\..+".equals(((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString())); assertThat(importLayout.getLayout().get(3)) .isInstanceOf(ImportLayoutStyle.Block.ImportPackage.class) - .matches(b -> ((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString().equals("java\\..+")); + .matches(b -> "java\\..+".equals(((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString())); assertThat(importLayout.getLayout().get(4)).isInstanceOf(ImportLayoutStyle.Block.AllOthers.class); } @@ -594,17 +594,17 @@ class Test { assertThat(importLayout.getLayout().get(0)) .isInstanceOf(ImportLayoutStyle.Block.ImportPackage.class) - .matches(b -> ((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString().equals("java\\..+")); + .matches(b -> "java\\..+".equals(((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString())); assertThat(importLayout.getLayout().get(1)) .isInstanceOf(ImportLayoutStyle.Block.ImportPackage.class) - .matches(b -> ((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString().equals("kotlin\\..+")); + .matches(b -> "kotlin\\..+".equals(((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString())); assertThat(importLayout.getLayout().get(2)).isInstanceOf(ImportLayoutStyle.Block.AllOthers.class); assertThat(importLayout.getLayout().get(3)) .isInstanceOf(ImportLayoutStyle.Block.ImportPackage.class) - .matches(b -> ((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString().equals("javax\\..+")); + .matches(b -> "javax\\..+".equals(((ImportLayoutStyle.Block.ImportPackage) b).getPackageWildcard().toString())); assertThat(importLayout.getLayout().get(4)).isInstanceOf(ImportLayoutStyle.Block.AllAliases.class); }