From 43590c37570863c44cc263b2c0b07ab7e38d9fdc Mon Sep 17 00:00:00 2001 From: Daniel Pitts Date: Sun, 1 Oct 2023 14:42:04 -0700 Subject: [PATCH] Proof of concept: Some niceties for Kotlin programmers. --- .idea/kotlinc.xml | 2 +- .idea/libraries/KotlinJavaRuntime.xml | 21 +++++++++- flexmark-util-data/pom.xml | 14 +++++++ .../flexmark/util/data/DataKeyDelegate.kt | 16 ++++++++ .../flexmark/util/data/ExtensionDelegates.kt | 4 ++ .../util/data/NullableDataKeyDelegate.kt | 13 ++++++ .../flexmark/util/data/SharedDataKeys.kt | 41 +++++++++++++++++++ pom.xml | 29 +++++++++++++ 8 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/DataKeyDelegate.kt create mode 100644 flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/ExtensionDelegates.kt create mode 100644 flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/NullableDataKeyDelegate.kt create mode 100644 flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/SharedDataKeys.kt diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index 9b02d599e7..0dd4b35463 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/.idea/libraries/KotlinJavaRuntime.xml b/.idea/libraries/KotlinJavaRuntime.xml index 1a7265de21..9015f1add7 100644 --- a/.idea/libraries/KotlinJavaRuntime.xml +++ b/.idea/libraries/KotlinJavaRuntime.xml @@ -1,19 +1,36 @@ - + + + + + + + - + + + + + + + + + + + + \ No newline at end of file diff --git a/flexmark-util-data/pom.xml b/flexmark-util-data/pom.xml index ea0491bfcf..603d860159 100644 --- a/flexmark-util-data/pom.xml +++ b/flexmark-util-data/pom.xml @@ -12,6 +12,10 @@ flexmark-java data utility classes + + org.jetbrains.kotlin + kotlin-stdlib + com.vladsch.flexmark flexmark-util-misc @@ -28,4 +32,14 @@ 24.0.1 + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + + diff --git a/flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/DataKeyDelegate.kt b/flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/DataKeyDelegate.kt new file mode 100644 index 0000000000..6af05c8fca --- /dev/null +++ b/flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/DataKeyDelegate.kt @@ -0,0 +1,16 @@ +package com.vladsch.flexmark.util.data + +import kotlin.reflect.KProperty + +@JvmInline +value class DataKeyDelegate(private val key: DataKey) { + + operator fun setValue(thisRef: MutableDataHolder, property: KProperty<*>, value: T) { + key.set(thisRef, value) + } + + operator fun getValue(thisRef: MutableDataHolder, property: KProperty<*>): T = + key.get(thisRef) +} + +fun key(key: DataKey) = DataKeyDelegate(key) \ No newline at end of file diff --git a/flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/ExtensionDelegates.kt b/flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/ExtensionDelegates.kt new file mode 100644 index 0000000000..c0bc3841fb --- /dev/null +++ b/flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/ExtensionDelegates.kt @@ -0,0 +1,4 @@ +package com.vladsch.flexmark.util.data + +import com.vladsch.flexmark.util.misc.Extension + diff --git a/flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/NullableDataKeyDelegate.kt b/flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/NullableDataKeyDelegate.kt new file mode 100644 index 0000000000..3c55b41cc7 --- /dev/null +++ b/flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/NullableDataKeyDelegate.kt @@ -0,0 +1,13 @@ +package com.vladsch.flexmark.util.data + +import kotlin.reflect.KProperty + +@JvmInline +value class NullableDataKeyDelegate(private val key: NullableDataKey) { + operator fun setValue(thisRef: MutableDataHolder, property: KProperty<*>, value: T) { + key.set(thisRef, value) + } + + operator fun getValue(thisRef: MutableDataHolder, property: KProperty<*>): T? = + key.get(thisRef) +} \ No newline at end of file diff --git a/flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/SharedDataKeys.kt b/flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/SharedDataKeys.kt new file mode 100644 index 0000000000..07435ba55f --- /dev/null +++ b/flexmark-util-data/src/main/java/com/vladsch/flexmark/util/data/SharedDataKeys.kt @@ -0,0 +1,41 @@ +package com.vladsch.flexmark.util.data + +import com.vladsch.flexmark.util.misc.Extension + +fun MutableDataHolder.addExtensions(vararg extensions: Extension) { + this.extensions += listOf(*extensions) +} + +var MutableDataHolder.extensions: Collection by key(SharedDataKeys.EXTENSIONS) +var MutableDataHolder.headingNoAtxSpace: Boolean by key(SharedDataKeys.HEADING_NO_ATX_SPACE) +var MutableDataHolder.escapeHeadingNoAtxSpace: Boolean by key(SharedDataKeys.ESCAPE_HEADING_NO_ATX_SPACE) +var MutableDataHolder.htmlForTranslator: Boolean by key(SharedDataKeys.HTML_FOR_TRANSLATOR) +var MutableDataHolder.intellijDummyIdentifier: Boolean by key(SharedDataKeys.INTELLIJ_DUMMY_IDENTIFIER) +var MutableDataHolder.parseInnerHtmlComments: Boolean by key(SharedDataKeys.PARSE_INNER_HTML_COMMENTS) +var MutableDataHolder.blankLinesInAst: Boolean by key(SharedDataKeys.BLANK_LINES_IN_AST) +var MutableDataHolder.translationHtmlBlockTagPattern: String by key(SharedDataKeys.TRANSLATION_HTML_BLOCK_TAG_PATTERN) +var MutableDataHolder.translationHtmlInlineTagPattern: String by key(SharedDataKeys.TRANSLATION_HTML_INLINE_TAG_PATTERN) +var MutableDataHolder.translationAutolinkTagPattern: String by key(SharedDataKeys.TRANSLATION_AUTOLINK_TAG_PATTERN) +var MutableDataHolder.rendererMaxTrailingBlankLines: Int by key(SharedDataKeys.RENDERER_MAX_TRAILING_BLANK_LINES) +var MutableDataHolder.rendererMaxBlankLines: Int by key(SharedDataKeys.RENDERER_MAX_BLANK_LINES) +var MutableDataHolder.indentSize: Int by key(SharedDataKeys.INDENT_SIZE) +var MutableDataHolder.percentEncodeUrls: Boolean by key(SharedDataKeys.PERCENT_ENCODE_URLS) +var MutableDataHolder.headerIdGeneratorResolveDupes: Boolean by key(SharedDataKeys.HEADER_ID_GENERATOR_RESOLVE_DUPES) +var MutableDataHolder.headerIdGeneratorToDashChars: String by key(SharedDataKeys.HEADER_ID_GENERATOR_TO_DASH_CHARS) +var MutableDataHolder.headerIdGeneratorNonDashChars: String by key(SharedDataKeys.HEADER_ID_GENERATOR_NON_DASH_CHARS) +var MutableDataHolder.headerIdGeneratorNoDupedDashes: Boolean by key(SharedDataKeys.HEADER_ID_GENERATOR_NO_DUPED_DASHES) +var MutableDataHolder.headerIdGeneratorNonAsciiToLowercase: Boolean by key(SharedDataKeys.HEADER_ID_GENERATOR_NON_ASCII_TO_LOWERCASE) +var MutableDataHolder.headerIdRefTextTrimLeadingSpaces: Boolean by key(SharedDataKeys.HEADER_ID_REF_TEXT_TRIM_LEADING_SPACES) +var MutableDataHolder.headerIdRefTextTrimTrailingSpaces: Boolean by key(SharedDataKeys.HEADER_ID_REF_TEXT_TRIM_TRAILING_SPACES) +var MutableDataHolder.headerIdAddEmojiShortcut: Boolean by key(SharedDataKeys.HEADER_ID_ADD_EMOJI_SHORTCUT) +var MutableDataHolder.renderHeaderId: Boolean by key(SharedDataKeys.RENDER_HEADER_ID) +var MutableDataHolder.generateHeaderId: Boolean by key(SharedDataKeys.GENERATE_HEADER_ID) +var MutableDataHolder.doNotRenderLinks: Boolean by key(SharedDataKeys.DO_NOT_RENDER_LINKS) +var MutableDataHolder.formatterMaxBlankLines: Int by key(SharedDataKeys.FORMATTER_MAX_BLANK_LINES) +var MutableDataHolder.formatterMaxTrailingBlankLines: Int by key(SharedDataKeys.FORMATTER_MAX_TRAILING_BLANK_LINES) +var MutableDataHolder.blockQuoteBlankLines: Boolean by key(SharedDataKeys.BLOCK_QUOTE_BLANK_LINES) +var MutableDataHolder.applySpecialLeadInHandlers: Boolean by key(SharedDataKeys.APPLY_SPECIAL_LEAD_IN_HANDLERS) +var MutableDataHolder.escapeSpecialChars: Boolean by key(SharedDataKeys.ESCAPE_SPECIAL_CHARS) +var MutableDataHolder.escapeNumberedLeadIn: Boolean by key(SharedDataKeys.ESCAPE_NUMBERED_LEAD_IN) +var MutableDataHolder.unescapeSpecialChars: Boolean by key(SharedDataKeys.UNESCAPE_SPECIAL_CHARS) +var MutableDataHolder.runningTests: Boolean by key(SharedDataKeys.RUNNING_TESTS) diff --git a/pom.xml b/pom.xml index 3a2a62832b..b168a2f358 100644 --- a/pom.xml +++ b/pom.xml @@ -89,6 +89,7 @@ ${project.basedir}/target/apidocs/ false + 1.9.10 @@ -136,6 +137,27 @@ + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + + compile + + compile + + + + + test-compile + + test-compile + + + + @@ -534,6 +556,13 @@ ${project.version} + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + junit