Skip to content

Commit

Permalink
Updated the package name of generated model files for interface class (
Browse files Browse the repository at this point in the history
…#1142)

* Updated package name of interface class

* Nit

* Fix typo

Co-authored-by: Eli Hart <eli.hart@airbnb.com>

* Nit

Co-authored-by: Vinay_Gaba <vinay.gaba@airbnb.com>
Co-authored-by: Eli Hart <eli.hart@airbnb.com>
  • Loading branch information
3 people authored Feb 27, 2021
1 parent ddd9dd2 commit fa61cfb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class GeneratedModelWriter(
asyncable: Asyncable
) {

val modelInterfaceWriter = ModelBuilderInterfaceWriter(filer, types, asyncable)
val modelInterfaceWriter =
ModelBuilderInterfaceWriter(filer, types, asyncable, configManager, elements)

open class BuilderHooks {
open fun beforeFinalBuild(builder: TypeSpec.Builder) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.util.concurrent.ConcurrentHashMap
import javax.annotation.processing.Filer
import javax.lang.model.element.Modifier
import javax.lang.model.element.TypeElement
import javax.lang.model.util.Elements
import javax.lang.model.util.Types

const val MODEL_BUILDER_INTERFACE_SUFFIX = "Builder"
Expand All @@ -24,7 +25,9 @@ const val MODEL_BUILDER_INTERFACE_SUFFIX = "Builder"
class ModelBuilderInterfaceWriter(
private val filer: Filer,
val types: Types,
val asyncable: Asyncable
val asyncable: Asyncable,
val configManager: ConfigManager,
val elements: Elements
) : Asyncable by asyncable {

private val viewInterfacesToGenerate = ConcurrentHashMap<ClassName, InterfaceDetails>()
Expand Down Expand Up @@ -156,7 +159,11 @@ class ModelBuilderInterfaceWriter(
}
}

JavaFile.builder(interfaceName.packageName(), interfaceSpec)
val implementingViewTypeElement = details.implementingViews.firstOrNull()
val packageName = implementingViewTypeElement?.let {
configManager.getModelViewConfig(it)?.rClass?.packageName()
} ?: interfaceName.packageName()
JavaFile.builder(packageName, interfaceSpec)
.build()
.writeSynchronized(filer)
}
Expand Down

0 comments on commit fa61cfb

Please sign in to comment.