Comments (6)
Their classname includes backticks. I think this is working as expected as backticks aren't allowed as part of a name.
I would not rely on TypeSpec.toString()
for a class name as we can change that format over time and it could possible include things like type parameters or wildcards. Instead, do a subtype check for ClassName
and then extract the package name and simple names and combine them manually.
from kotlinpoet.
Yeah just a typo
from kotlinpoet.
As part of the behavior check with other words, changing the word data
in the package name to info
(As an example) gives this result:
public object ComAttafitamimKabinLocalEntitiesInfoGenderKotlinStringAdapter :
ColumnAdapter<Gender, String> {
override fun decode(databaseValue: String): Gender = enumValueOf(databaseValue)
override fun encode(`value`: Gender): String = value.name
}
private val comAttafitamimKabinLocalEntitiesInfoGenderKotlinStringAdapter:
ColumnAdapter<Gender, String> = ComAttafitamimKabinLocalEntitiesInfoGenderKotlinStringAdapter
Which is accepted by the compiler
from kotlinpoet.
By further investigation, I found out that the escaping is returned from TypeName.toString()
which is created by calling KSType.toTypeName()
or KSClassDeclaration.toClassName()
As a workaround, I'm removing "``" from the output of toString()
from kotlinpoet.
To Reproduce
Simply generate a class or property with the word "Data" in its name
Can you please include the actual code you're executing? The following unit test passes for me (note that data
inside the package name is indeed escaped, which is expected):
@Test fun nameIncludesData() {
val source = FileSpec.builder("com.squareup.data", "TestData")
.addType(TypeSpec.classBuilder("TestData").build())
.build()
assertThat(source.toString()).isEqualTo("""
package com.squareup.`data`
public class TestData
""".trimIndent())
}
And just to confirm, are you actually using version 1.6.0 of the library, or 1.16.0? 1.16.0 is the latest.
from kotlinpoet.
@Egorand I misspelled the version, it is 1.16.0 indeed.
Your code in the unit test works fine for me too, as I mentioned in my third comment, the backticks come from TypeName.toString()
.
@JakeWharton I didn't use TypeSpec
, but rather TypeName
, but I agree that it isn't safe to rely on toString()
. I will consider using a combination of ClassName
and typeParameters
in the future to get the full name, including generics.
I close the issue since it's the expected behavior, thank you for the quick reply!
from kotlinpoet.
Related Issues (20)
- Chained constructor call is not formatted correctly
- Move Gradle Wrapper validation to its own action
- Can't generate @get:JvmName annotation for property HOT 5
- Can we add IDE highlighting to addStatement or similar statements HOT 4
- kotlin.* imports in generated classes HOT 1
- There is no way to add format strings to the code HOT 2
- Support at least few Kotlin API targets via apiVersion to simplify migrations
- Split the KotlinPoet documentation page into multiple subpages
- addKdoc not working as expected when property is involved HOT 2
- com.squareup:kotlinpoet 1.15.3 missing class files. HOT 3
- callSuperConstructor does not generate code for its parameters HOT 2
- Code generated with ksp interop's toAnnotationSpec() generates code that fails to compile when passed an OptIn annotation HOT 1
- Integration with okio's file system HOT 4
- Aliased imports not working for nested classes and generate unused imports and usage of FQNs HOT 2
- Aliased imports not used when generating code in same package for which the aliased import is defined HOT 1
- Reference Kotlinpoet created class in another class.
- Comments outside of code block HOT 1
- Wrap supertype/superinterfaces like parameters
- The get / set index access operator overloads are incorrectly escaped HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotlinpoet.