Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use a common name in different nested classes #1

Open
arekolek opened this issue Feb 26, 2023 · 3 comments
Open

Can't use a common name in different nested classes #1

arekolek opened this issue Feb 26, 2023 · 3 comments

Comments

@arekolek
Copy link
Contributor

arekolek commented Feb 26, 2023

This code

@Fixture
data class Foo(val baz: Baz) {
    @Fixture
    data class Baz(val text: String)
}

@Fixture
data class Bar(val baz: Baz) {
    @Fixture
    data class Baz(val number: Int)
}

produces an error because of Baz:

> Task :kspKotlin FAILED
e: [ksp] kotlin.io.FileAlreadyExistsException: build/generated/ksp/main/kotlin/com/example/model/BazFixture.kt
        at com.google.devtools.ksp.processing.impl.CodeGeneratorImpl.createNewFile(CodeGeneratorImpl.kt:117)
        at com.google.devtools.ksp.processing.impl.CodeGeneratorImpl.createNewFile(CodeGeneratorImpl.kt:67)
        at com.google.devtools.ksp.processing.CodeGenerator.createNewFile$default(CodeGenerator.kt:59)
        at com.google.devtools.ksp.processing.CodeGenerator$DefaultImpls.createNewFile$default(CodeGenerator.kt:59)
        at com.squareup.kotlinpoet.ksp.OriginatingKSFilesKt.writeTo(originatingKSFiles.kt:140)
        at com.squareup.kotlinpoet.ksp.OriginatingKSFilesKt.writeTo(originatingKSFiles.kt:122)
        at com.squareup.kotlinpoet.ksp.OriginatingKSFilesKt.writeTo$default(originatingKSFiles.kt:116)
        at com.theblueground.fixtures.FixtureBuilderGenerator.generate(FixtureBuilderGenerator.kt:44)
        at com.theblueground.fixtures.FixtureProcessor.finish(FixtureProcessor.kt:106)
        at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$10$1.invoke(KotlinSymbolProcessingExtension.kt:322)
        at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$10$1.invoke(KotlinSymbolProcessingExtension.kt:321)
        at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.handleException(KotlinSymbolProcessingExtension.kt:390)
        at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:321)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:123)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:99)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:257)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:42)
        at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:248)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:88)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:47)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:167)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:53)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:101)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:47)
        at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1645)
        at jdk.internal.reflect.GeneratedMethodAccessor103.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
        at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
        at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
        at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
        at java.base/java.lang.Thread.run(Thread.java:832)

e: Error occurred in KSP, check log for detail

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':kspKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details
@St4B
Copy link
Collaborator

St4B commented Mar 9, 2023

@arekolek Thank you for your feedback! :) This is something that we did not take into account. We will implement a solution though and release a version.

@arekolek
Copy link
Contributor Author

@St4B I see fix is merged, but is it released?

@St4B
Copy link
Collaborator

St4B commented Nov 16, 2023

@arekolek We have released an alpha version (1.0.8-alpha01). There might be some breaking changes.

From now on, if a file contains multiple classes annotated with @Fixture, then the generated functions will be placed in a single file. (Previously we created a file for every generated function).

Additionally, for inner classes, the naming convention is to use the outer class name too. In your example, two functions will be created:

  • createFooBaz()
  • createBarBaz()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants