-
-
Notifications
You must be signed in to change notification settings - Fork 72
Add Kotlin DSL support for delegations #482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bf86f2b
Add Kotlin DSL support for delegations
DerEchtePilz c8ac59c
Set scope to provided for commandapi-core dependency
DerEchtePilz 0c728a0
Change version to use project.version
DerEchtePilz 3f6ae42
Adds tests for Kotlin DSL delegations
DerEchtePilz 40e2a64
Improve delegation test by checking for correct values (just to be sure)
DerEchtePilz 3dafcf8
Merge branch 'dev/dev' into dev/kotlindsl-delegations
DerEchtePilz c2a5cdd
Update global changelog
DerEchtePilz a1898ad
Add documentation for Kotlin DSL delegations
DerEchtePilz 3bbc1c9
Provide additional information about delegation usage
DerEchtePilz 73d77b9
Merge branch 'dev/dev' into dev/kotlindsl-delegations
DerEchtePilz 331d302
Fix MarkdownLint complaint
DerEchtePilz c93b9ce
Fix new MarkdownLint complaint
DerEchtePilz 3e08f47
Change term 'delegated' to 'delegated properties'. Provide a link to …
DerEchtePilz a654182
Remove Velocity dependency information in kotlinintro.md
DerEchtePilz 6992a42
Move delegated properties documentation to a new page
DerEchtePilz 0fb9cd2
Make delegated properties Kotlin example not use the Kotlin DSL examp…
DerEchtePilz c7eff6a
Merge branch 'dev/dev' into dev/kotlindsl-delegations
DerEchtePilz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 0 additions & 3 deletions
3
...umentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>dev.jorel</groupId> | ||
<artifactId>commandapi-kotlin</artifactId> | ||
<version>9.2.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>commandapi-core-kotlin</artifactId> | ||
|
||
<build> | ||
<sourceDirectory>src/main/kotlin</sourceDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<version>${kotlin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>compile</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>test-compile</id> | ||
<phase>test-compile</phase> | ||
<goals> | ||
<goal>test-compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<jvmTarget>16</jvmTarget> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>empty-javadoc-jar</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
<configuration> | ||
<classifier>javadoc</classifier> | < 6D4E /tr>||
<classesDirectory>${basedir}/javadoc</classesDirectory> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<version>${kotlin.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>dev.jorel</groupId> | ||
<artifactId>commandapi-core</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
7 changes: 7 additions & 0 deletions
7
...in/commandapi-core-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPIDSL.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.jorel.commandapi.kotlindsl | ||
|
||
import dev.jorel.commandapi.executors.CommandArguments | ||
import kotlin.reflect.KProperty | ||
|
||
// CommandArguments DSL | ||
9E7A td> | inline operator fun <reified T> CommandArguments.getValue(nothing: Nothing?, property: KProperty<*>) = this[property.name] as T |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>dev.jorel</groupId> | ||
<artifactId>commandapi</artifactId> | ||
<version>9.2.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>commandapi-kotlin</artifactId> | ||
<packaging>pom</packaging> | ||
|
||
</project> |
113 changes: 0 additions & 113 deletions
113
commandapi-platforms/commandapi-bukkit/commandapi-bukkit-kotlin/.gitignore
This file was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
...-bukkit-kotlin-test/src/test/kotlin/dev/jorel/commandapi/test/dsltests/DelegationTests.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package dev.jorel.commandapi.test.dsltests | ||
|
||
import be.seeseemelk.mockbukkit.entity.PlayerMock | ||
import dev.jorel.commandapi.executors.CommandArguments | ||
import dev.jorel.commandapi.kotlindsl.* | ||
import dev.jorel.commandapi.test.Mut | ||
import dev.jorel.commandapi.test.TestBase | ||
import org.bukkit.entity.Player | ||
import org.junit.jupiter.api.AfterEach | ||
import org.junit.jupiter.api.Assertions.assertDoesNotThrow | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import java.lang.NullPointerException | ||
|
||
class DelegationTests : TestBase() { | ||
|
||
/********* | ||
* Setup * | ||
*********/ | ||
|
||
@BeforeEach | ||
override fun setUp() { | ||
super.setUp() | ||
} | ||
|
||
@AfterEach | ||
override fun tearDown() { | ||
super.tearDown() | ||
} | ||
|
||
/********* | ||
* Tests * | ||
*********/ | ||
|
||
@Test | ||
fun failingDelegationTestWithKotlinDSL() { | ||
val results: Mut<Any> = Mut.of() | ||
|
||
commandAPICommand("test") { | ||
stringArgument("string") | ||
playerArgument("target") | ||
playerExecutor { _, args -> | ||
val string: String by args | ||
val player: Player by args | ||
results.set(string) | ||
results.set(player) | ||
} | ||
} | ||
|
||
val player: PlayerMock = server.addPlayer("Player1") | ||
|
||
// This should throw an exception because the 'Player1' is assigned | ||
// to a variable that does not match the node name | ||
assertThrows<NullPointerException> { | ||
server.dispatchCommand(player, "test testString Player1") | ||
} | ||
} | ||
|
||
@Test | ||
fun passingDelegationTestWithKotlinDSL() { | ||
commandAPICommand("test") { | ||
stringArgument("string") | ||
playerArgument("target") | ||
playerExecutor { _, args -> | ||
val string: String by args | ||
val target: Player by args | ||
} | ||
} | ||
|
||
val player: PlayerMock = server.addPlayer("Player1") | ||
|
||
assertDoesNotThrow { | ||
server.dispatchCommand(player, "test testString Player1") | ||
} | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.