-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from teogor/feature/class-name-format
Introduce Support for Platform-Specific Class Name Formats
- Loading branch information
Showing
8 changed files
with
288 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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
36 changes: 36 additions & 0 deletions
36
crosslens-core/src/androidMain/kotlin/dev/teogor/crosslens/core/KClassKtx.android.kt
This file contains 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,36 @@ | ||
/* | ||
* Copyright 2024 Teogor (Teodor Grigor) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.teogor.crosslens.core | ||
|
||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Provides the class name in a specified format. The [format] parameter allows for different | ||
* naming conventions, including fully qualified names, simple names, and platform-specific | ||
* formats. | ||
* | ||
* @param format Specifies the format for the class name. Defaults to [NameFormat.QUALIFIED]. | ||
* @return The class name as a [String] in the specified format, or `null` if the name cannot | ||
* be determined. | ||
*/ | ||
public actual fun KClass<*>.getFormattedName(format: NameFormat): String? { | ||
return when (format) { | ||
NameFormat.QUALIFIED -> qualifiedName | ||
NameFormat.SIMPLE -> simpleName | ||
NameFormat.MULTIPLATFORM -> qualifiedName | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
crosslens-core/src/commonMain/kotlin/dev/teogor/crosslens/core/KClassKtx.common.kt
This file contains 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,72 @@ | ||
/* | ||
* Copyright 2024 Teogor (Teodor Grigor) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.teogor.crosslens.core | ||
|
||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Defines the various formats for class name representation. | ||
*/ | ||
public enum class NameFormat { | ||
/** | ||
* Fully qualified name of the class, including the package. | ||
*/ | ||
QUALIFIED, | ||
|
||
/** | ||
* Simple name of the class, without the package. | ||
*/ | ||
SIMPLE, | ||
|
||
/** | ||
* A platform-specific name format. This can be used to implement custom naming | ||
* conventions that may vary by platform or environment. | ||
*/ | ||
MULTIPLATFORM | ||
} | ||
|
||
/** | ||
* Provides the class name in a specified format. The [format] parameter allows for different | ||
* naming conventions, including fully qualified names, simple names, and platform-specific | ||
* formats. | ||
* | ||
* @param format Specifies the format for the class name. Defaults to [NameFormat.QUALIFIED]. | ||
* @return The class name as a [String] in the specified format, or `null` if the name cannot | ||
* be determined. | ||
*/ | ||
public expect fun KClass<*>.getFormattedName(format: NameFormat = NameFormat.QUALIFIED): String? | ||
|
||
/** | ||
* Extension property that provides the platform-specific name for the class. | ||
* | ||
* This property retrieves the class name in a format that is tailored to be | ||
* appropriate for the current platform or environment. It is a shorthand for | ||
* calling [getFormattedName] with the [NameFormat.MULTIPLATFORM] format. | ||
* | ||
* The `MULTIPLATFORM` format is intended to support naming conventions that may vary | ||
* depending on the platform or use case. This can be useful when different platforms | ||
* require different representations of class names for various reasons, such as logging, | ||
* serialization, or platform-specific APIs. | ||
* | ||
* @return The platform-specific name of the class as a [String], or `null` if the name | ||
* cannot be determined or is not applicable in the current context. | ||
* | ||
* @see getFormattedName | ||
* @see NameFormat.MULTIPLATFORM | ||
*/ | ||
public val KClass<*>.multiplatformName: String? | ||
get() = getFormattedName(NameFormat.MULTIPLATFORM) |
36 changes: 36 additions & 0 deletions
36
crosslens-core/src/jsMain/kotlin/dev/teogor/crosslens/core/KClassKtx.js.kt
This file contains 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,36 @@ | ||
/* | ||
* Copyright 2024 Teogor (Teodor Grigor) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.teogor.crosslens.core | ||
|
||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Provides the class name in a specified format. The [format] parameter allows for different | ||
* naming conventions, including fully qualified names, simple names, and platform-specific | ||
* formats. | ||
* | ||
* @param format Specifies the format for the class name. Defaults to [NameFormat.QUALIFIED]. | ||
* @return The class name as a [String] in the specified format, or `null` if the name cannot | ||
* be determined. | ||
*/ | ||
public actual fun KClass<*>.getFormattedName(format: NameFormat): String? { | ||
return when (format) { | ||
NameFormat.QUALIFIED -> simpleName | ||
NameFormat.SIMPLE -> simpleName | ||
NameFormat.MULTIPLATFORM -> simpleName | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
crosslens-core/src/jvmMain/kotlin/dev/teogor/crosslens/core/KClassKtx.jvm.kt
This file contains 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,36 @@ | ||
/* | ||
* Copyright 2024 Teogor (Teodor Grigor) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.teogor.crosslens.core | ||
|
||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Provides the class name in a specified format. The [format] parameter allows for different | ||
* naming conventions, including fully qualified names, simple names, and platform-specific | ||
* formats. | ||
* | ||
* @param format Specifies the format for the class name. Defaults to [NameFormat.QUALIFIED]. | ||
* @return The class name as a [String] in the specified format, or `null` if the name cannot | ||
* be determined. | ||
*/ | ||
public actual fun KClass<*>.getFormattedName(format: NameFormat): String? { | ||
return when (format) { | ||
NameFormat.QUALIFIED -> qualifiedName | ||
NameFormat.SIMPLE -> simpleName | ||
NameFormat.MULTIPLATFORM -> qualifiedName | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
crosslens-core/src/nativeMain/kotlin/dev/teogor/crosslens/core/KClassKtx.native.kt
This file contains 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,36 @@ | ||
/* | ||
* Copyright 2024 Teogor (Teodor Grigor) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.teogor.crosslens.core | ||
|
||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Provides the class name in a specified format. The [format] parameter allows for different | ||
* naming conventions, including fully qualified names, simple names, and platform-specific | ||
* formats. | ||
* | ||
* @param format Specifies the format for the class name. Defaults to [NameFormat.QUALIFIED]. | ||
* @return The class name as a [String] in the specified format, or `null` if the name cannot | ||
* be determined. | ||
*/ | ||
public actual fun KClass<*>.getFormattedName(format: NameFormat): String? { | ||
return when (format) { | ||
NameFormat.QUALIFIED -> qualifiedName | ||
NameFormat.SIMPLE -> simpleName | ||
NameFormat.MULTIPLATFORM -> qualifiedName | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
crosslens-core/src/wasmJsMain/kotlin/dev/teogor/crosslens/core/KClassKtx.wasmJs.kt
This file contains 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,36 @@ | ||
/* | ||
* Copyright 2024 Teogor (Teodor Grigor) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.teogor.crosslens.core | ||
|
||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Provides the class name in a specified format. The [format] parameter allows for different | ||
* naming conventions, including fully qualified names, simple names, and platform-specific | ||
* formats. | ||
* | ||
* @param format Specifies the format for the class name. Defaults to [NameFormat.QUALIFIED]. | ||
* @return The class name as a [String] in the specified format, or `null` if the name cannot | ||
* be determined. | ||
*/ | ||
public actual fun KClass<*>.getFormattedName(format: NameFormat): String? { | ||
return when (format) { | ||
NameFormat.QUALIFIED -> simpleName | ||
NameFormat.SIMPLE -> simpleName | ||
NameFormat.MULTIPLATFORM -> simpleName | ||
} | ||
} |