Skip to content

Commit ebfbc0e

Browse files
quaffmhalbritter
authored andcommitted
Cleanup kotlin sources
1. remove unused imports 2. remove redundant semicolon 3. remove empty class body 4. remove redundant 'constructor' keyword 5. remove redundant 'Unit' return type 6. use non-null type if possible See gh-38708
1 parent 4ad9f11 commit ebfbc0e

File tree

20 files changed

+32
-56
lines changed

20 files changed

+32
-56
lines changed

Diff for: spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/data/sql/h2webconsole/springsecurity/DevProfileSecurityConfiguration.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class DevProfileSecurityConfiguration {
4040

4141
// tag::customizer[]
4242
private fun <T> yourCustomAuthorization(): Customizer<T> {
43-
return Customizer.withDefaults<T>()
43+
return Customizer.withDefaults()
4444
}
4545
// end::customizer[]
4646

Diff for: spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/externalconfig/typesafeconfigurationproperties/validate/nested/MyProperties.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class MyProperties {
2929

3030
var remoteAddress: @NotNull InetAddress? = null
3131

32-
val security: @Valid Security? = Security()
32+
val security: @Valid Security = Security()
3333

3434
class Security {
3535
var username: @NotEmpty String? = null

Diff for: spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testcontainers/atdevelopmenttime/devtools/MyContainersConfiguration.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package org.springframework.boot.docs.features.testcontainers.atdevelopmenttime.
1717

1818
import org.springframework.boot.devtools.restart.RestartScope
1919
import org.springframework.boot.test.context.TestConfiguration
20-
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
20+
import org.springframework.boot.testcontainers.service.connection.ServiceConnection
2121
import org.springframework.context.annotation.Bean
2222
import org.testcontainers.containers.MongoDBContainer
2323

Diff for: spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testcontainers/atdevelopmenttime/dynamicproperties/MyContainersConfiguration.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.boot.docs.features.testcontainers.atdevelopmenttime.dynamicproperties
1818

1919
import org.springframework.boot.test.context.TestConfiguration
20-
import org.springframework.context.annotation.Bean;
20+
import org.springframework.context.annotation.Bean
2121
import org.springframework.test.context.DynamicPropertyRegistry
2222
import org.testcontainers.containers.MongoDBContainer
2323

@@ -27,8 +27,8 @@ class MyContainersConfiguration {
2727
@Bean
2828
fun monogDbContainer(properties: DynamicPropertyRegistry): MongoDBContainer {
2929
var container = MongoDBContainer("mongo:5.0")
30-
properties.add("spring.data.mongodb.host", container::getHost);
31-
properties.add("spring.data.mongodb.port", container::getFirstMappedPort);
30+
properties.add("spring.data.mongodb.host", container::getHost)
31+
properties.add("spring.data.mongodb.port", container::getFirstMappedPort)
3232
return container
3333
}
3434

Diff for: spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testcontainers/atdevelopmenttime/importingcontainerdeclarations/MyContainersConfiguration.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,4 @@ import org.springframework.boot.testcontainers.context.ImportTestcontainers
2121

2222
@TestConfiguration(proxyBeanMethods = false)
2323
@ImportTestcontainers(MyContainers::class)
24-
class MyContainersConfiguration {
25-
26-
}
24+
class MyContainersConfiguration

Diff for: spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testing/springbootapplications/autoconfiguredrestclient/MyRestClientTests.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MyRestClientTests(
3131
@Autowired val server: MockRestServiceServer) {
3232

3333
@Test
34-
fun getVehicleDetailsWhenResultIsSuccessShouldReturnDetails(): Unit {
34+
fun getVehicleDetailsWhenResultIsSuccessShouldReturnDetails() {
3535
server.expect(MockRestRequestMatchers.requestTo("/greet/details"))
3636
.andRespond(MockRestResponseCreators.withSuccess("hello", MediaType.TEXT_PLAIN))
3737
val greeting = service.callRestService()

Diff for: spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testing/springbootapplications/userconfigurationandslicing/MyMongoConfiguration.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.boot.docs.features.testing.springbootapplications.userconfigurationandslicing
1818

1919
import org.springframework.context.annotation.Configuration
20-
import org.springframework.data.mongodb.config.EnableMongoAuditing;
20+
import org.springframework.data.mongodb.config.EnableMongoAuditing
2121

2222
@Configuration(proxyBeanMethods = false)
2323
@EnableMongoAuditing

Diff for: spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testing/springbootapplications/usingmain/always/MyApplicationTests.kt

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package org.springframework.boot.docs.features.testing.springbootapplications.us
1919
import org.junit.jupiter.api.Test
2020
import org.springframework.boot.test.context.SpringBootTest
2121
import org.springframework.boot.test.context.SpringBootTest.UseMainMethod
22-
import org.springframework.context.annotation.Import
2322

2423
@SpringBootTest(useMainMethod = UseMainMethod.ALWAYS)
2524
class MyApplicationTests {

Diff for: spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testing/springbootapplications/usingmain/custom/MyApplication.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ class MyApplication
2626
fun main(args: Array<String>) {
2727
runApplication<MyApplication>(*args) {
2828
setBannerMode(Banner.Mode.OFF)
29-
setAdditionalProfiles("myprofile");
29+
setAdditionalProfiles("myprofile")
3030
}
3131
}

Diff for: spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testing/testcontainers/serviceconnections/MyRedisConfiguration.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package org.springframework.boot.docs.features.testing.testcontainers.servicecon
1818

1919
import org.springframework.boot.test.context.TestConfiguration
2020
import org.springframework.boot.testcontainers.service.connection.ServiceConnection
21-
import org.springframework.context.annotation.Bean;
21+
import org.springframework.context.annotation.Bean
2222
import org.testcontainers.containers.GenericContainer
2323

2424
@TestConfiguration(proxyBeanMethods = false)

Diff for: spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/graphql/runtimewiring/GreetingController.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.docs.web.graphql.runtimewiring;
17+
package org.springframework.boot.docs.web.graphql.runtimewiring
1818

1919
import org.springframework.graphql.data.method.annotation.Argument
2020
import org.springframework.graphql.data.method.annotation.QueryMapping

Diff for: spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/security/springwebflux/MyWebFluxSecurityConfiguration.kt

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package org.springframework.boot.docs.web.security.springwebflux
1919
import org.springframework.boot.autoconfigure.security.reactive.PathRequest
2020
import org.springframework.context.annotation.Bean
2121
import org.springframework.context.annotation.Configuration
22-
import org.springframework.security.config.Customizer
2322
import org.springframework.security.config.Customizer.withDefaults
2423
import org.springframework.security.config.web.server.ServerHttpSecurity
2524
import org.springframework.security.web.server.SecurityWebFilterChain

Diff for: spring-boot-project/spring-boot-test/src/test/kotlin/org/springframework/boot/test/context/KotlinApplicationWithMainThrowingException.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import org.springframework.boot.SpringBootConfiguration
44
import org.springframework.boot.runApplication
55

66
@SpringBootConfiguration(proxyBeanMethods = false)
7-
open class KotlinApplicationWithMainThrowingException {
8-
}
7+
open class KotlinApplicationWithMainThrowingException
98

109
fun main(args: Array<String>) {
1110
runApplication<KotlinApplicationWithMainThrowingException>(*args)

Diff for: spring-boot-project/spring-boot-test/src/test/kotlin/org/springframework/boot/test/context/SpringBootContextLoaderKotlinTests.kt

-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ package org.springframework.boot.test.context
1818

1919
import org.assertj.core.api.Assertions.assertThatIllegalStateException
2020
import org.junit.jupiter.api.Test
21-
import org.springframework.boot.SpringBootConfiguration
2221
import org.springframework.boot.test.context.SpringBootTest.UseMainMethod
23-
import org.springframework.context.annotation.Configuration
2422
import org.springframework.test.context.TestContext
2523
import org.springframework.test.context.TestContextManager
2624

Diff for: spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/running/application-plugin-main-class-name.gradle.kts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.springframework.boot.gradle.tasks.run.BootRun
2-
31
plugins {
42
java
53
application

Diff for: spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/running/spring-boot-dsl-main-class-name.gradle.kts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.springframework.boot.gradle.tasks.run.BootRun
2-
31
plugins {
42
java
53
application

Diff for: spring-boot-project/spring-boot/src/main/kotlin/org/springframework/boot/SpringApplicationExtensions.kt

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import org.springframework.util.Assert
2121
import org.springframework.util.ClassUtils
2222
import org.springframework.util.ReflectionUtils
2323
import kotlin.reflect.KClass
24-
import kotlin.reflect.KType
2524

2625
/**
2726
* Top-level function acting as a Kotlin shortcut allowing to write

Diff for: spring-boot-project/spring-boot/src/test/kotlin/org/springframework/boot/context/properties/KotlinConfigurationPropertiesTests.kt

+13-22
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class KotlinConfigurationPropertiesTests {
3838

3939
@AfterEach
4040
fun cleanUp() {
41-
this.context.close();
41+
this.context.close()
4242
}
4343

4444
@Test //gh-18652
@@ -48,22 +48,22 @@ class KotlinConfigurationPropertiesTests {
4848
RootBeanDefinition(BingProperties::class.java))
4949
beanFactory.registerSingleton("foo", BingProperties(""))
5050
this.context.register(EnableConfigProperties::class.java)
51-
this.context.refresh();
51+
this.context.refresh()
5252
}
5353

5454
@Test
5555
fun `type with constructor bound lateinit property can be bound`() {
5656
this.context.register(EnableLateInitProperties::class.java)
57-
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "lateinit.inner.value=alpha");
58-
this.context.refresh();
57+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "lateinit.inner.value=alpha")
58+
this.context.refresh()
5959
assertThat(this.context.getBean(LateInitProperties::class.java).inner.value).isEqualTo("alpha")
6060
}
6161

6262
@Test
6363
fun `type with constructor bound lateinit property with default can be bound`() {
6464
this.context.register(EnableLateInitPropertiesWithDefault::class.java)
65-
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "lateinit-with-default.inner.bravo=two");
66-
this.context.refresh();
65+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "lateinit-with-default.inner.bravo=two")
66+
this.context.refresh()
6767
val properties = this.context.getBean(LateInitPropertiesWithDefault::class.java)
6868
assertThat(properties.inner.alpha).isEqualTo("apple")
6969
assertThat(properties.inner.bravo).isEqualTo("two")
@@ -72,20 +72,16 @@ class KotlinConfigurationPropertiesTests {
7272
@Test
7373
fun `mutable data class properties can be imported`() {
7474
this.context.register(MutableDataClassPropertiesImporter::class.java)
75-
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "mutable.prop=alpha");
76-
this.context.refresh();
75+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "mutable.prop=alpha")
76+
this.context.refresh()
7777
assertThat(this.context.getBean(MutableDataClassProperties::class.java).prop).isEqualTo("alpha")
7878
}
7979

8080
@ConfigurationProperties(prefix = "foo")
81-
class BingProperties(@Suppress("UNUSED_PARAMETER") bar: String) {
82-
83-
}
81+
class BingProperties(@Suppress("UNUSED_PARAMETER") bar: String)
8482

8583
@EnableConfigurationProperties
86-
class EnableConfigProperties {
87-
88-
}
84+
class EnableConfigProperties
8985

9086
@ConfigurationProperties("lateinit")
9187
class LateInitProperties {
@@ -97,9 +93,7 @@ class KotlinConfigurationPropertiesTests {
9793
data class Inner(val value: String)
9894

9995
@EnableConfigurationProperties(LateInitPropertiesWithDefault::class)
100-
class EnableLateInitPropertiesWithDefault {
101-
102-
}
96+
class EnableLateInitPropertiesWithDefault
10397

10498
@ConfigurationProperties("lateinit-with-default")
10599
class LateInitPropertiesWithDefault {
@@ -111,15 +105,12 @@ class KotlinConfigurationPropertiesTests {
111105
data class InnerWithDefault(val alpha: String = "apple", val bravo: String = "banana")
112106

113107
@EnableConfigurationProperties(LateInitProperties::class)
114-
class EnableLateInitProperties {
115-
116-
}
108+
class EnableLateInitProperties
117109

118110
@EnableConfigurationProperties
119111
@Configuration(proxyBeanMethods = false)
120112
@Import(MutableDataClassProperties::class)
121-
class MutableDataClassPropertiesImporter {
122-
}
113+
class MutableDataClassPropertiesImporter
123114

124115
@ConfigurationProperties(prefix = "mutable")
125116
data class MutableDataClassProperties(

Diff for: spring-boot-project/spring-boot/src/test/kotlin/org/springframework/boot/context/properties/bind/KotlinBindableRuntimeHintsRegistrarTests.kt

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import org.assertj.core.api.Assertions.assertThat
2020
import org.junit.jupiter.api.Test
2121
import org.springframework.aot.hint.MemberCategory
2222
import org.springframework.aot.hint.RuntimeHints
23-
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates
2423

2524

2625
/**

Diff for: spring-boot-project/spring-boot/src/test/kotlin/org/springframework/boot/context/properties/bind/KotlinDefaultBindConstructorProviderTests.kt

+6-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.context.properties.bind;
17+
package org.springframework.boot.context.properties.bind
1818

1919
import org.assertj.core.api.Assertions.assertThat
2020
import org.assertj.core.api.Assertions.assertThatIllegalStateException
@@ -46,7 +46,7 @@ class KotlinDefaultBindConstructorProviderTests {
4646
@Test
4747
fun `type with primary and secondary annotated constructor should use secondary constructor for binding`() {
4848
val bindConstructor = this.constructorProvider.getBindConstructor(ConstructorBindingOnSecondaryWithPrimaryConstructor::class.java, false)
49-
assertThat(bindConstructor).isNotNull();
49+
assertThat(bindConstructor).isNotNull()
5050
}
5151

5252
@Test
@@ -116,12 +116,12 @@ class KotlinDefaultBindConstructorProviderTests {
116116
@Test
117117
fun `data class with default values should use constructor binding`() {
118118
val bindConstructor = this.constructorProvider.getBindConstructor(ConstructorBindingDataClassWithDefaultValues::class.java, false)
119-
assertThat(bindConstructor).isNotNull();
119+
assertThat(bindConstructor).isNotNull()
120120
}
121121

122122
class FooProperties
123123

124-
class PrimaryWithAutowiredSecondaryProperties constructor(val name: String?, val counter: Int = 42) {
124+
class PrimaryWithAutowiredSecondaryProperties(val name: String?, val counter: Int = 42) {
125125

126126
@Autowired
127127
constructor(@Suppress("UNUSED_PARAMETER") foo: String) : this(foo, 21)
@@ -133,9 +133,7 @@ class KotlinDefaultBindConstructorProviderTests {
133133
constructor(@Suppress("UNUSED_PARAMETER") foo: String)
134134
}
135135

136-
class AutowiredPrimaryProperties @Autowired constructor(val name: String?, val counter: Int = 42) {
137-
138-
}
136+
class AutowiredPrimaryProperties @Autowired constructor(val name: String?, val counter: Int = 42)
139137

140138
class ConstructorBindingOnSecondaryAndAutowiredPrimaryProperties @Autowired constructor(val name: String?, val counter: Int = 42) {
141139

@@ -149,7 +147,7 @@ class KotlinDefaultBindConstructorProviderTests {
149147
constructor(@Suppress("UNUSED_PARAMETER") foo: String) : this(foo, 21)
150148
}
151149

152-
class ConstructorBindingOnSecondaryWithPrimaryConstructor constructor(val name: String?, val counter: Int = 42) {
150+
class ConstructorBindingOnSecondaryWithPrimaryConstructor(val name: String?, val counter: Int = 42) {
153151

154152
@ConstructorBinding
155153
constructor(@Suppress("UNUSED_PARAMETER") foo: String) : this(foo, 21)

0 commit comments

Comments
 (0)