Skip to content

Commit

Permalink
Improve layouts test coverage, enable Kotlin explicitApi
Browse files Browse the repository at this point in the history
  • Loading branch information
hanggrian committed Aug 14, 2024
1 parent 11e5c2a commit e129254
Show file tree
Hide file tree
Showing 492 changed files with 4,730 additions and 4,236 deletions.
12 changes: 9 additions & 3 deletions codegen/src/main/kotlin/com/hanggrian/ktfx/codegen/Generator.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.hanggrian.ktfx.codegen

import com.hanggrian.ktfx.codegen.layouts.ControlsFx
import com.hanggrian.ktfx.codegen.layouts.JFoenix
import com.hanggrian.ktfx.codegen.layouts.JavaFx
import com.hanggrian.ktfx.codegen.layouts.LayoutsFactory
import com.hanggrian.ktfx.codegen.layouts.LayoutsWriter

object Generator {
@JvmStatic
fun main(args: Array<String>) {
// LayoutsWriter.write(LayoutsFactory.JavaFx)
// LayoutsWriter.write(LayoutsFactory.ControlsFx)
// LayoutsWriter.write(LayoutsFactory.JFoenix)
LayoutsWriter.write(LayoutsFactory.JavaFx)
LayoutsWriter.write(LayoutsFactory.ControlsFx)
LayoutsWriter.write(LayoutsFactory.JFoenix)
// CoroutinesWriter.write(CoroutinesFactory.JavaFx)
// CoroutinesWriter.write(CoroutinesFactory.ControlsFx)
// CoroutinesWriter.write(CoroutinesFactory.JFoenix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ val LayoutsFactory.Companion.ControlsFx: LayoutsFactory
}
GridView::class(T) { items(T) }
HiddenSidesPane::class(customClass = true)
HyperlinkLabel::class { text() }
HyperlinkLabel::class { nullText() }
InfoOverlay::class(customClass = true) {
content()
text()
nullText()
}
ListSelectionView::class(T)
MaskerPane::class()
Expand Down Expand Up @@ -106,7 +106,7 @@ val LayoutsFactory.Companion.ControlsFx: LayoutsFactory
TaskProgressView::class(
"T".genericsBy(Task::class.name.parameterizedBy("*".generics)),
)
ToggleSwitch::class { text() }
ToggleSwitch::class { nullText() }
WorldMapView::class()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ val LayoutsFactory.Companion.JFoenix: LayoutsFactory
init {
JFXBadge::class(customClass = true)
JFXButton::class {
text()
nullText()
graphic()
}
JFXCheckBox::class { text() }
JFXCheckBox::class { nullText() }
JFXChip::class(T) {
chipView()
item()
Expand Down Expand Up @@ -95,14 +95,14 @@ val LayoutsFactory.Companion.JFoenix: LayoutsFactory
JFXNodesList::class(customClass = true)
JFXPasswordField::class()
JFXProgressBar::class { progress() }
JFXRadioButton::class { text() }
JFXRadioButton::class { nullText() }
JFXRippler::class(customClass = true)
JFXScrollPane::class(customClass = true)
JFXSlider::class { slider("50.0") }
JFXSpinner::class { progress() }
JFXTabPane::class(customClass = true)
JFXTextArea::class { text() }
JFXTextField::class { text() }
JFXTextArea::class { emptyText() }
JFXTextField::class { emptyText() }
JFXTimePicker::class {
"time"(LocalTime::class.name.nullable()) { defaultValue("null") }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ val LayoutsFactory.Companion.JavaFx: LayoutsFactory
// javafx.scene.control
Accordion::class(customClass = true)
Button::class {
text()
nullText()
graphic()
}
ButtonBar::class(customClass = true) {
"buttonOrder"(STRING.nullable()) { defaultValue("null") }
}
CheckBox::class { text() }
CheckBox::class { nullText() }
CheckMenuItem::class {
text()
nullText()
graphic()
}
ChoiceBox::class(T) { items(T) }
Expand All @@ -168,11 +168,11 @@ val LayoutsFactory.Companion.JavaFx: LayoutsFactory
}
DatePicker::class { date() }
Hyperlink::class {
text()
nullText()
graphic()
}
Label::class {
text()
nullText()
graphic()
}
ListView::class(T) { items(T) }
Expand All @@ -182,11 +182,11 @@ val LayoutsFactory.Companion.JavaFx: LayoutsFactory
}
MenuBar::class(customClass = true)
MenuButton::class(customClass = true) {
text()
nullText()
graphic()
}
MenuItem::class {
text()
nullText()
graphic()
}
Pagination::class {
Expand All @@ -198,9 +198,9 @@ val LayoutsFactory.Companion.JavaFx: LayoutsFactory
PasswordField::class()
ProgressBar::class { progress() }
ProgressIndicator::class { progress() }
RadioButton::class { text() }
RadioButton::class { nullText() }
RadioMenuItem::class {
text()
nullText()
graphic()
}
ScrollBar::class()
Expand All @@ -212,7 +212,7 @@ val LayoutsFactory.Companion.JavaFx: LayoutsFactory
SplitMenuButton::class(customClass = true)
SplitPane::class(customClass = true)
Tab::class(customClass = true) {
text()
nullText()
content()
}
TableView::class(S) { items(S) }
Expand All @@ -223,7 +223,7 @@ val LayoutsFactory.Companion.JavaFx: LayoutsFactory
"title"(STRING.nullable()) { defaultValue("null") }
}
ToggleButton::class {
text()
nullText()
graphic()
}
ToolBar::class(customClass = true)
Expand Down Expand Up @@ -367,7 +367,7 @@ val LayoutsFactory.Companion.JavaFx: LayoutsFactory
VLineTo::class { y() }

// javafx.scene.text
Text::class { text() }
Text::class { nullText() }
TextFlow::class(customClass = true)

// javafx.scene.web
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ data class LayoutsEntry(
val customTypeName: TypeName
get() =
typeName.takeUnless { isCustomClass }
?: classNamed(
packageName,
when {
simpleName.startsWith("JFX") -> "KtfxJfx${simpleName.substringAfter("JFX")}"
else -> "Ktfx$simpleName"
},
)
?: classNamed(packageName, "Ktfx${simpleName.replace("JFX", "Jfx")}")

val containerClassNames: List<ClassName>
get() =
Expand All @@ -70,7 +64,13 @@ data class LayoutsEntry(
}
}.joinToString("")

val styledFunctionName: String get() = "styled$simpleName"
val styledFunctionName: String
get() =
"styled${
simpleName
.replace("JFX", "Jfx")
.replace("SVG", "Svg")
}"

val isSupportStyledFunction: Boolean
get() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ open class LayoutsFactory(val path: String, val packageName: String, val classNa
}

companion object {
fun ParameterSpecHandlerScope.text() = "text"(STRING.nullable()) { defaultValue("null") }
fun ParameterSpecHandlerScope.nullText() =
"text"(STRING.nullable()) { defaultValue("null") }

fun ParameterSpecHandlerScope.emptyText() = "text"(STRING) { defaultValue("\"\"") }

fun ParameterSpecHandlerScope.graphic() =
"graphic"(Node::class.name.nullable()) { defaultValue("null") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ object LayoutsWriter {
entry.functionName {
entry.typeVarNames.forEach { typeVariables += it }
receiver = containerClassName
modifiers(INLINE)
kdoc(
entry.getFileComment(
add = true,
Expand Down Expand Up @@ -78,7 +79,6 @@ object LayoutsWriter {
entry.functionName {
entry.typeVarNames.forEach { typeVariables += it }
if (containerClassName != null) receiver = containerClassName
modifiers(INLINE)
kdoc(
entry.getFileComment(
add = containerClassName != null,
Expand Down Expand Up @@ -125,6 +125,7 @@ object LayoutsWriter {
entry.styledFunctionName {
entry.typeVarNames.forEach { typeVariables += it }
if (containerClassName != null) receiver = containerClassName
modifiers(INLINE)
kdoc(
entry.getFileComment(
add = containerClassName != null,
Expand All @@ -150,15 +151,14 @@ object LayoutsWriter {
namedArgument = true,
commaSuffix = true,
)
}styleClass = *styleClass, id = id) { }",
}styleClass = styleClass, id = id) { }",
)
}
}
entry.fullContainerClassNames.forEach { containerClassName ->
entry.styledFunctionName {
entry.typeVarNames.forEach { typeVariables += it }
if (containerClassName != null) receiver = containerClassName
modifiers(INLINE)
kdoc(
entry.getFileComment(
add = containerClassName != null,
Expand Down
2 changes: 2 additions & 0 deletions ktfx-commons/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ plugins {

javafx.modules("javafx.controls", "javafx.swing")

kotlin.explicitApi()

dependencies {
ktlintRuleset(libs.rulebook.ktlint)

Expand Down
7 changes: 4 additions & 3 deletions ktfx-commons/src/main/kotlin/ktfx/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import javafx.application.Application
import javafx.application.HostServices

/** Launch a JavaFX application with reified type. */
inline fun <reified T : Application> launchApplication(vararg args: String): Unit =
public inline fun <reified T : Application> launchApplication(vararg args: String): Unit =
Application.launch(T::class.java, *args)

/**
* Resolves the specified relative URI against the code base URI and returns the resolved URI.
*/
inline fun HostServices.resolveCodeUri(rel: String): String = resolveURI(codeBase, rel)
public inline fun HostServices.resolveCodeUri(rel: String): String = resolveURI(codeBase, rel)

/**
* Resolves the specified relative URI against the document base URI and returns the resolved URI.
*/
inline fun HostServices.resolveDocumentUri(rel: String): String = resolveURI(documentBase, rel)
public inline fun HostServices.resolveDocumentUri(rel: String): String =
resolveURI(documentBase, rel)
3 changes: 1 addition & 2 deletions ktfx-commons/src/main/kotlin/ktfx/Callback.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ package ktfx
import javafx.util.Callback

/** Converts the object provided into its string form. */
@Suppress("NOTHING_TO_INLINE")
inline operator fun <P, R> Callback<P, R>.invoke(obj: P): R = call(obj)
public inline operator fun <P, R> Callback<P, R>.invoke(obj: P): R = call(obj)
9 changes: 5 additions & 4 deletions ktfx-commons/src/main/kotlin/ktfx/Pair.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ package ktfx
* This method allows to use destructuring declarations when working with pairs
* (e.g.: `val (first, second) = myPair`).
*/
inline operator fun <F, S> javafx.util.Pair<F, S>.component1(): F? = key
public inline operator fun <F, S> javafx.util.Pair<F, S>.component1(): F? = key

/**
* Returns the value component of the pair.
*
* This method allows to use destructuring declarations when working with pairs
* (e.g.: `val (first, second) = myPair`).
*/
inline operator fun <F, S> javafx.util.Pair<F, S>.component2(): S? = value
public inline operator fun <F, S> javafx.util.Pair<F, S>.component2(): S? = value

/** Returns this [Pair] as a [kotlin.Pair]. */
inline fun <F, S> javafx.util.Pair<F, S>.toKotlinPair(): Pair<F, S> = Pair(key, value)
public inline fun <F, S> javafx.util.Pair<F, S>.toKotlinPair(): Pair<F, S> = Pair(key, value)

/** Returns this [kotlin.Pair] as a JavaFX [Pair]. */
inline fun <F, S> Pair<F, S>.toFxPair(): javafx.util.Pair<F, S> = javafx.util.Pair(first, second)
public inline fun <F, S> Pair<F, S>.toFxPair(): javafx.util.Pair<F, S> =
javafx.util.Pair(first, second)
18 changes: 9 additions & 9 deletions ktfx-commons/src/main/kotlin/ktfx/Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/** Returns true if the calling thread is the JavaFX thread. */
inline fun isFxThread(): Boolean = Platform.isFxApplicationThread()
public inline fun isFxThread(): Boolean = Platform.isFxApplicationThread()

/** Queries whether a specific conditional feature is supported by the platform. */
inline fun ConditionalFeature.isSupported(): Boolean = Platform.isSupported(this)
public inline fun ConditionalFeature.isSupported(): Boolean = Platform.isSupported(this)

/**
* Calls the specified function [block] in JavaFX thread.
*
* @see kotlin.run
*/
inline fun runLater(crossinline block: () -> Unit) {
public inline fun runLater(crossinline block: () -> Unit) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
Platform.runLater { block() }
}
Expand All @@ -30,7 +30,7 @@ inline fun runLater(crossinline block: () -> Unit) {
*
* @see kotlin.run
*/
inline fun <T> T.runLater(crossinline block: T.() -> Unit) {
public inline fun <T> T.runLater(crossinline block: T.() -> Unit) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
Platform.runLater { block() }
}
Expand All @@ -40,7 +40,7 @@ inline fun <T> T.runLater(crossinline block: T.() -> Unit) {
*
* @see kotlin.with
*/
inline fun <T> withLater(receiver: T, crossinline block: T.() -> Unit) {
public inline fun <T> withLater(receiver: T, crossinline block: T.() -> Unit) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
Platform.runLater { receiver.block() }
}
Expand All @@ -51,7 +51,7 @@ inline fun <T> withLater(receiver: T, crossinline block: T.() -> Unit) {
*
* @see kotlin.apply
*/
inline fun <T> T.applyLater(crossinline block: T.() -> Unit): T {
public inline fun <T> T.applyLater(crossinline block: T.() -> Unit): T {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
Platform.runLater { block() }
return this
Expand All @@ -63,7 +63,7 @@ inline fun <T> T.applyLater(crossinline block: T.() -> Unit): T {
*
* @see kotlin.also
*/
inline fun <T> T.alsoLater(crossinline block: (T) -> Unit): T {
public inline fun <T> T.alsoLater(crossinline block: (T) -> Unit): T {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
Platform.runLater { block(this) }
return this
Expand All @@ -74,7 +74,7 @@ inline fun <T> T.alsoLater(crossinline block: (T) -> Unit): T {
*
* @see kotlin.let
*/
inline fun <T> T.letLater(crossinline block: (T) -> Unit) {
public inline fun <T> T.letLater(crossinline block: (T) -> Unit) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
Platform.runLater { block(this) }
}
Expand All @@ -84,7 +84,7 @@ inline fun <T> T.letLater(crossinline block: (T) -> Unit) {
*
* @see kotlin.repeat
*/
inline fun repeatLater(times: Int, crossinline action: (Int) -> Unit) {
public inline fun repeatLater(times: Int, crossinline action: (Int) -> Unit) {
contract { callsInPlace(action) }
Platform.runLater { for (index in 0 until times) action(index) }
}
Loading

0 comments on commit e129254

Please sign in to comment.