Git Product home page Git Product logo

Comments (6)

JakeWharton avatar JakeWharton commented on July 17, 2024 2

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.

JakeWharton avatar JakeWharton commented on July 17, 2024 1

Yeah just a typo

from kotlinpoet.

tamimattafi avatar tamimattafi commented on July 17, 2024

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.

tamimattafi avatar tamimattafi commented on July 17, 2024

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.

Egorand avatar Egorand commented on July 17, 2024

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.

tamimattafi avatar tamimattafi commented on July 17, 2024

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.