Skip to content

Commit 943e9af

Browse files
gregturnodrotbohm
authored andcommitted
#728 - Update Kotlin DSLs to use WebMvcLinkBuilder.
1 parent e82d42f commit 943e9af

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

src/main/kotlin/org/springframework/hateoas/mvc/AffordanceBuilderDsl.kt renamed to src/main/kotlin/org/springframework/hateoas/mvc/WebMvcAffordanceBuilderDsl.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,26 @@ package org.springframework.hateoas.mvc
1818

1919
import org.springframework.hateoas.Affordance
2020
import org.springframework.hateoas.Link
21-
import org.springframework.hateoas.mvc.ControllerLinkBuilder.afford
22-
import org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn
21+
import org.springframework.hateoas.mvc.WebMvcLinkBuilder.afford
22+
import org.springframework.hateoas.mvc.WebMvcLinkBuilder.methodOn
2323

2424
/**
2525
* Create a new [Link] with additional [Affordance]s.
2626
*
2727
* @author Roland Kulcsár
28+
* @author Greg Turnquist
2829
* @since 1.0
2930
*/
30-
inline infix fun Link.andAffordances(setup: AffordanceBuilderDsl.() -> Unit): Link {
31+
inline infix fun Link.andAffordances(setup: WebMvcAffordanceBuilderDsl.() -> Unit): Link {
3132

32-
val builder = AffordanceBuilderDsl()
33+
val builder = WebMvcAffordanceBuilderDsl()
3334
builder.setup()
3435

3536
return andAffordances(builder.affordances)
3637
}
3738

3839
/**
39-
* Extract a [Link] from the [ControllerLinkBuilder] and look up the related [Affordance]. Should
40+
* Extract a [Link] from the [WebMvcLinkBuilder] and look up the related [Affordance]. Should
4041
* only be one.
4142
*
4243
* @author Roland Kulcsár
@@ -50,7 +51,7 @@ inline fun <reified C> afford(func: C.() -> Unit): Affordance = afford(methodOn(
5051
* @author Roland Kulcsár
5152
* @since 1.0
5253
*/
53-
open class AffordanceBuilderDsl(val affordances: MutableList<Affordance> = mutableListOf()) {
54+
open class WebMvcAffordanceBuilderDsl(val affordances: MutableList<Affordance> = mutableListOf()) {
5455

5556
inline fun <reified C> afford(func: C.() -> Any) {
5657

src/main/kotlin/org/springframework/hateoas/mvc/LinkBuilderDsl.kt renamed to src/main/kotlin/org/springframework/hateoas/mvc/WebMvcLinkBuilderDsl.kt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,39 @@ package org.springframework.hateoas.mvc
1919
import org.springframework.hateoas.Link
2020
import org.springframework.hateoas.LinkRelation
2121
import org.springframework.hateoas.ResourceSupport
22-
import org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo
23-
import org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn
22+
import org.springframework.hateoas.mvc.WebMvcLinkBuilder.linkTo
23+
import org.springframework.hateoas.mvc.WebMvcLinkBuilder.methodOn
2424

2525
import kotlin.reflect.KClass
2626

2727
/**
28-
* Create a [ControllerLinkBuilder] pointing to a [func] method.
28+
* Create a [WebMvcLinkBuilder] pointing to a [func] method.
2929
*
3030
* @author Roland Kulcsár
3131
* @author Oliver Drotbohm
32+
* @author Greg Turnquist
3233
* @since 1.0
3334
*/
34-
inline fun <reified C> linkTo(func: C.() -> Unit): ControllerLinkBuilder = linkTo(methodOn(C::class.java).apply(func))
35+
inline fun <reified C> linkTo(func: C.() -> Unit): WebMvcLinkBuilder = linkTo(methodOn(C::class.java).apply(func))
3536

3637
/**
3738
* Create a [Link] with the given [rel].
3839
*
3940
* @author Roland Kulcsár
4041
* @since 1.0
4142
*/
42-
infix fun ControllerLinkBuilder.withRel(rel: LinkRelation): Link = withRel(rel)
43-
infix fun ControllerLinkBuilder.withRel(rel: String): Link = withRel(rel)
43+
infix fun WebMvcLinkBuilder.withRel(rel: LinkRelation): Link = withRel(rel)
44+
infix fun WebMvcLinkBuilder.withRel(rel: String): Link = withRel(rel)
4445

4546
/**
4647
* Add [links] to the [R] resource.
4748
*
4849
* @author Roland Kulcsár
4950
* @since 1.0
5051
*/
51-
fun <C, R : ResourceSupport> R.add(controller: Class<C>, links: LinkBuilderDsl<C, R>.(R) -> Unit): R {
52+
fun <C, R : ResourceSupport> R.add(controller: Class<C>, links: WebMvcLinkBuilderDsl<C, R>.(R) -> Unit): R {
5253

53-
val builder = LinkBuilderDsl(controller, this)
54+
val builder = WebMvcLinkBuilderDsl(controller, this)
5455
builder.links(this)
5556

5657
return this
@@ -62,7 +63,7 @@ fun <C, R : ResourceSupport> R.add(controller: Class<C>, links: LinkBuilderDsl<C
6263
* @author Roland Kulcsár
6364
* @since 1.0
6465
*/
65-
fun <C : Any, R : ResourceSupport> R.add(controller: KClass<C>, links: LinkBuilderDsl<C, R>.(R) -> Unit): R {
66+
fun <C : Any, R : ResourceSupport> R.add(controller: KClass<C>, links: WebMvcLinkBuilderDsl<C, R>.(R) -> Unit): R {
6667
return add(controller.java, links)
6768
}
6869

@@ -72,24 +73,24 @@ fun <C : Any, R : ResourceSupport> R.add(controller: KClass<C>, links: LinkBuild
7273
* @author Roland Kulcsár
7374
* @since 1.0
7475
*/
75-
open class LinkBuilderDsl<C, R : ResourceSupport>(val controller: Class<C>, val resource: R) {
76+
open class WebMvcLinkBuilderDsl<C, R : ResourceSupport>(val controller: Class<C>, val resource: R) {
7677

7778
/**
78-
* Create a [ControllerLinkBuilder] pointing to [func] method.
79+
* Create a [WebMvcLinkBuilder] pointing to [func] method.
7980
*/
80-
fun <R> linkTo(func: C.() -> R): ControllerLinkBuilder = linkTo(methodOn(controller).run(func))
81+
fun <R> linkTo(func: C.() -> R): WebMvcLinkBuilder = linkTo(methodOn(controller).run(func))
8182

8283
/**
8384
* Add a link with the given [rel] to the [resource].
8485
*/
85-
infix fun ControllerLinkBuilder.withRel(rel: String): Link {
86+
infix fun WebMvcLinkBuilder.withRel(rel: String): Link {
8687
return this withRel(LinkRelation.of(rel))
8788
}
8889

8990
/**
9091
* Add a link with the given [rel] to the [resource].
9192
*/
92-
infix fun ControllerLinkBuilder.withRel(rel: LinkRelation): Link {
93+
infix fun WebMvcLinkBuilder.withRel(rel: LinkRelation): Link {
9394

9495
val link = withRel(rel)
9596
resource.add(link)

src/test/kotlin/org/springframework/hateoas/mvc/AffordanceBuilderDslUnitTest.kt renamed to src/test/kotlin/org/springframework/hateoas/mvc/WebMvcAffordanceBuilderDslUnitTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ import org.springframework.http.ResponseEntity
2323
import org.springframework.web.bind.annotation.*
2424

2525
/**
26-
* Unit tests for [LinkBuilderDsl] and [AffordanceBuilderDsl].
26+
* Unit tests for [WebMvcLinkBuilderDsl] and [WebMvcAffordanceBuilderDsl].
2727
*
2828
* @author Roland Kulcsár
29+
* @author Greg Turnquist
2930
*/
30-
class AffordanceBuilderDslUnitTest : TestUtils() {
31+
class WebMvcAffordanceBuilderDslUnitTest : TestUtils() {
3132

3233
/**
3334
* @see #715

src/test/kotlin/org/springframework/hateoas/mvc/LinkBuilderDslUnitTest.kt renamed to src/test/kotlin/org/springframework/hateoas/mvc/WebMvcLinkBuilderDslUnitTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ import org.springframework.http.ResponseEntity
2222
import org.springframework.web.bind.annotation.*
2323

2424
/**
25-
* Unit tests for [LinkBuilderDsl] and [AffordanceBuilderDsl].
25+
* Unit tests for [WebMvcLinkBuilderDsl] and [WebMvcAffordanceBuilderDsl].
2626
*
2727
* @author Roland Kulcsár
28+
* @author Greg Turnquist
2829
*/
29-
class LinkBuilderDslUnitTest : TestUtils() {
30+
class WebMvcLinkBuilderDslUnitTest : TestUtils() {
3031

3132
private val REL_PRODUCTS = "products"
3233

0 commit comments

Comments
 (0)