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 = "",
|
suffix: String = "",
|
||||||
relatedPath: String = "",
|
relatedPath: String = "",
|
||||||
force: Boolean = false,
|
force: Boolean = false,
|
||||||
|
forceUppercase: Boolean = true,
|
||||||
fileSpecBuilder: () -> FileSpec
|
fileSpecBuilder: () -> FileSpec
|
||||||
) {
|
) {
|
||||||
val containingFile = containingFile!!
|
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(
|
File(
|
||||||
File(containingFile.filePath).parent,
|
File(containingFile.filePath).parent,
|
||||||
relatedPath
|
relatedPath
|
||||||
),
|
),
|
||||||
"$prefix${simpleName.asString()}$suffix.kt"
|
"$prefix${simpleName}$suffix.kt"
|
||||||
).takeIf { force || !it.exists() } ?.apply {
|
).takeIf { force || !it.exists() } ?.apply {
|
||||||
parentFile.mkdirs()
|
parentFile.mkdirs()
|
||||||
val fileSpec = fileSpecBuilder()
|
val fileSpec = fileSpecBuilder()
|
||||||
|
@@ -77,6 +77,11 @@ class Processor(
|
|||||||
if (it.isVararg) {
|
if (it.isVararg) {
|
||||||
addModifiers(KModifier.VARARG)
|
addModifiers(KModifier.VARARG)
|
||||||
}
|
}
|
||||||
|
it.annotations.forEach {
|
||||||
|
if (it.shortName.asString() == GenerationVariant::class.simpleName) return@forEach
|
||||||
|
|
||||||
|
addAnnotation(it.toAnnotationSpec(omitDefaultValues = false))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.build() to it.hasDefault
|
.build() to it.hasDefault
|
||||||
}
|
}
|
||||||
@@ -92,11 +97,16 @@ class Processor(
|
|||||||
val funSpec = FunSpec.builder(ksFunctionDeclaration.simpleName.asString()).apply {
|
val funSpec = FunSpec.builder(ksFunctionDeclaration.simpleName.asString()).apply {
|
||||||
modifiers.addAll(ksFunctionDeclaration.modifiers.mapNotNull { it.toKModifier() })
|
modifiers.addAll(ksFunctionDeclaration.modifiers.mapNotNull { it.toKModifier() })
|
||||||
ksFunctionDeclaration.annotations.forEach {
|
ksFunctionDeclaration.annotations.forEach {
|
||||||
|
if (it.shortName.asString() == GenerateVariations::class.simpleName) return@forEach
|
||||||
|
|
||||||
addAnnotation(it.toAnnotationSpec(omitDefaultValues = false))
|
addAnnotation(it.toAnnotationSpec(omitDefaultValues = false))
|
||||||
}
|
}
|
||||||
ksFunctionDeclaration.extensionReceiver ?.let {
|
ksFunctionDeclaration.extensionReceiver ?.let {
|
||||||
receiver(it.toTypeName())
|
receiver(it.toTypeName())
|
||||||
}
|
}
|
||||||
|
ksFunctionDeclaration.returnType ?.let {
|
||||||
|
returns(it.toTypeName())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
baseFunctionParameters.forEach { (parameter, hasDefault) ->
|
baseFunctionParameters.forEach { (parameter, hasDefault) ->
|
||||||
if (hasDefault) {
|
if (hasDefault) {
|
||||||
@@ -138,6 +148,7 @@ class Processor(
|
|||||||
accumulatedGeneration.receiverType ?.let {
|
accumulatedGeneration.receiverType ?.let {
|
||||||
receiver(it)
|
receiver(it)
|
||||||
}
|
}
|
||||||
|
returns(accumulatedGeneration.returnType)
|
||||||
accumulatedGeneration.parameters.forEach {
|
accumulatedGeneration.parameters.forEach {
|
||||||
val actualName = if (variation.argName.isEmpty()) it.name else variation.argName
|
val actualName = if (variation.argName.isEmpty()) it.name else variation.argName
|
||||||
parameters.add(
|
parameters.add(
|
||||||
@@ -169,8 +180,15 @@ class Processor(
|
|||||||
defaults[it.name] = defaultValueString
|
defaults[it.name] = defaultValueString
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
it.toBuilder()
|
it.toBuilder().apply {
|
||||||
|
defaults[it.name] = it.name
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
.apply {
|
||||||
|
it.annotations.forEach {
|
||||||
|
addAnnotation(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -206,7 +224,7 @@ class Processor(
|
|||||||
it.writeFile(prefix = prefix, suffix = "GeneratedVariation") {
|
it.writeFile(prefix = prefix, suffix = "GeneratedVariation") {
|
||||||
FileSpec.builder(
|
FileSpec.builder(
|
||||||
it.packageName.asString(),
|
it.packageName.asString(),
|
||||||
"${it.simpleName.getShortName()}GeneratedVariation"
|
"${it.simpleName.getShortName().let { it.replaceFirst(it.first().toString(), it.first().uppercase()) }}GeneratedVariation"
|
||||||
).apply {
|
).apply {
|
||||||
addFileComment(
|
addFileComment(
|
||||||
"""
|
"""
|
||||||
|
@@ -47,3 +47,15 @@ public suspend fun SimpleType.sample2(
|
|||||||
): Unit = sample2(
|
): Unit = sample2(
|
||||||
arg1 = arg1, arg2 = with(arg22) {toInt()}, arg3 = arg3
|
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