mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-15 13:29:38 +00:00
fixes and forcing uppercase for new files
This commit is contained in:
@@ -12,15 +12,22 @@ fun KSDeclaration.writeFile(
|
||||
suffix: String = "",
|
||||
relatedPath: String = "",
|
||||
force: Boolean = false,
|
||||
forceUppercase: Boolean = true,
|
||||
fileSpecBuilder: () -> FileSpec
|
||||
) {
|
||||
val containingFile = containingFile!!
|
||||
val simpleName = if (forceUppercase) {
|
||||
val rawSimpleName = simpleName.asString()
|
||||
rawSimpleName.replaceFirst(rawSimpleName.first().toString(), rawSimpleName.first().uppercase())
|
||||
} else {
|
||||
simpleName.asString()
|
||||
}
|
||||
File(
|
||||
File(
|
||||
File(containingFile.filePath).parent,
|
||||
relatedPath
|
||||
),
|
||||
"$prefix${simpleName.asString()}$suffix.kt"
|
||||
"$prefix${simpleName}$suffix.kt"
|
||||
).takeIf { force || !it.exists() } ?.apply {
|
||||
parentFile.mkdirs()
|
||||
val fileSpec = fileSpecBuilder()
|
||||
|
@@ -77,6 +77,11 @@ class Processor(
|
||||
if (it.isVararg) {
|
||||
addModifiers(KModifier.VARARG)
|
||||
}
|
||||
it.annotations.forEach {
|
||||
if (it.shortName.asString() == GenerationVariant::class.simpleName) return@forEach
|
||||
|
||||
addAnnotation(it.toAnnotationSpec(omitDefaultValues = false))
|
||||
}
|
||||
}
|
||||
.build() to it.hasDefault
|
||||
}
|
||||
@@ -92,11 +97,16 @@ class Processor(
|
||||
val funSpec = FunSpec.builder(ksFunctionDeclaration.simpleName.asString()).apply {
|
||||
modifiers.addAll(ksFunctionDeclaration.modifiers.mapNotNull { it.toKModifier() })
|
||||
ksFunctionDeclaration.annotations.forEach {
|
||||
if (it.shortName.asString() == GenerateVariations::class.simpleName) return@forEach
|
||||
|
||||
addAnnotation(it.toAnnotationSpec(omitDefaultValues = false))
|
||||
}
|
||||
ksFunctionDeclaration.extensionReceiver ?.let {
|
||||
receiver(it.toTypeName())
|
||||
}
|
||||
ksFunctionDeclaration.returnType ?.let {
|
||||
returns(it.toTypeName())
|
||||
}
|
||||
}
|
||||
baseFunctionParameters.forEach { (parameter, hasDefault) ->
|
||||
if (hasDefault) {
|
||||
@@ -138,6 +148,7 @@ class Processor(
|
||||
accumulatedGeneration.receiverType ?.let {
|
||||
receiver(it)
|
||||
}
|
||||
returns(accumulatedGeneration.returnType)
|
||||
accumulatedGeneration.parameters.forEach {
|
||||
val actualName = if (variation.argName.isEmpty()) it.name else variation.argName
|
||||
parameters.add(
|
||||
@@ -169,8 +180,15 @@ class Processor(
|
||||
defaults[it.name] = defaultValueString
|
||||
}
|
||||
} else {
|
||||
it.toBuilder()
|
||||
it.toBuilder().apply {
|
||||
defaults[it.name] = it.name
|
||||
}
|
||||
})
|
||||
.apply {
|
||||
it.annotations.forEach {
|
||||
addAnnotation(it)
|
||||
}
|
||||
}
|
||||
.build()
|
||||
)
|
||||
}
|
||||
@@ -206,7 +224,7 @@ class Processor(
|
||||
it.writeFile(prefix = prefix, suffix = "GeneratedVariation") {
|
||||
FileSpec.builder(
|
||||
it.packageName.asString(),
|
||||
"${it.simpleName.getShortName()}GeneratedVariation"
|
||||
"${it.simpleName.getShortName().let { it.replaceFirst(it.first().toString(), it.first().uppercase()) }}GeneratedVariation"
|
||||
).apply {
|
||||
addFileComment(
|
||||
"""
|
||||
|
@@ -47,3 +47,15 @@ public suspend fun SimpleType.sample2(
|
||||
): Unit = sample2(
|
||||
arg1 = arg1, arg2 = with(arg22) {toInt()}, arg3 = arg3
|
||||
)
|
||||
|
||||
public suspend fun SimpleType.sample2(arg12: Int, arg22: String): Unit = sample2(
|
||||
arg12 = arg12, arg2 = with(arg22) {toInt()}
|
||||
)
|
||||
|
||||
public suspend fun SimpleType.sample2(
|
||||
arg12: Int,
|
||||
arg22: String,
|
||||
arg3: Boolean,
|
||||
): Unit = sample2(
|
||||
arg12 = arg12, arg2 = with(arg22) {toInt()}, arg3 = arg3
|
||||
)
|
Reference in New Issue
Block a user