Skip to content

Commit

Permalink
Merge pull request #3 from teogor/feature/class-name-format
Browse files Browse the repository at this point in the history
Introduce Support for Platform-Specific Class Name Formats
  • Loading branch information
teogor authored Sep 2, 2024
2 parents 7d8db41 + fb50680 commit c86502b
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crosslens-core/api/android/crosslens-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ public final class dev/teogor/crosslens/core/HashCodeBuilderKt {
public static final fun lazyHashCode (Lkotlin/jvm/functions/Function0;)Lkotlin/Lazy;
}

public final class dev/teogor/crosslens/core/KClassKtx_androidKt {
public static final fun getFormattedName (Lkotlin/reflect/KClass;Ldev/teogor/crosslens/core/NameFormat;)Ljava/lang/String;
public static synthetic fun getFormattedName$default (Lkotlin/reflect/KClass;Ldev/teogor/crosslens/core/NameFormat;ILjava/lang/Object;)Ljava/lang/String;
}

public final class dev/teogor/crosslens/core/KClassKtx_commonKt {
public static final fun getMultiplatformName (Lkotlin/reflect/KClass;)Ljava/lang/String;
}

public final class dev/teogor/crosslens/core/NameFormat : java/lang/Enum {
public static final field MULTIPLATFORM Ldev/teogor/crosslens/core/NameFormat;
public static final field QUALIFIED Ldev/teogor/crosslens/core/NameFormat;
public static final field SIMPLE Ldev/teogor/crosslens/core/NameFormat;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Ldev/teogor/crosslens/core/NameFormat;
public static fun values ()[Ldev/teogor/crosslens/core/NameFormat;
}

public final class dev/teogor/crosslens/core/startup/ActivityInitializer : androidx/startup/Initializer {
public fun <init> ()V
public synthetic fun create (Landroid/content/Context;)Ljava/lang/Object;
Expand Down
18 changes: 18 additions & 0 deletions crosslens-core/api/jvm/crosslens-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,21 @@ public final class dev/teogor/crosslens/core/HashCodeBuilderKt {
public static final fun lazyHashCode (Lkotlin/jvm/functions/Function0;)Lkotlin/Lazy;
}

public final class dev/teogor/crosslens/core/KClassKtx_commonKt {
public static final fun getMultiplatformName (Lkotlin/reflect/KClass;)Ljava/lang/String;
}

public final class dev/teogor/crosslens/core/KClassKtx_jvmKt {
public static final fun getFormattedName (Lkotlin/reflect/KClass;Ldev/teogor/crosslens/core/NameFormat;)Ljava/lang/String;
public static synthetic fun getFormattedName$default (Lkotlin/reflect/KClass;Ldev/teogor/crosslens/core/NameFormat;ILjava/lang/Object;)Ljava/lang/String;
}

public final class dev/teogor/crosslens/core/NameFormat : java/lang/Enum {
public static final field MULTIPLATFORM Ldev/teogor/crosslens/core/NameFormat;
public static final field QUALIFIED Ldev/teogor/crosslens/core/NameFormat;
public static final field SIMPLE Ldev/teogor/crosslens/core/NameFormat;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Ldev/teogor/crosslens/core/NameFormat;
public static fun values ()[Ldev/teogor/crosslens/core/NameFormat;
}

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
}
}
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)
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
}
}
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
}
}
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
}
}
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
}
}

0 comments on commit c86502b

Please sign in to comment.