Skip to content

Commit

Permalink
Only use styleable view if layout not set (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
elihart authored Oct 17, 2017
1 parent 02d9f9e commit e926ae3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ private void removeMethodIfDuplicatedBySetter(Collection<AttributeInfo> attribut
}
}

TypeElement getSuperClassElement() {
return superClassElement;
}

TypeName getSuperClassName() {
return superClassName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ internal class GeneratedModelWriter(
methods: MutableList<MethodSpec>
) {

val originalClassElement = modelClassInfo.getSuperClassElement()
val originalClassElement = modelClassInfo.superClassElement
if (!isEpoxyModelWithHolder(originalClassElement)) {
return
}
Expand Down Expand Up @@ -813,9 +813,8 @@ internal class GeneratedModelWriter(
return modelInfo.getLayoutResource(resourceProcessor)
}

val superClassElement = modelInfo.getSuperClassElement()
if (implementsMethod(superClassElement, buildDefaultLayoutMethodBase(), types,
elements)) {
val superClassElement = modelInfo.superClassElement
if (implementsMethod(superClassElement, buildDefaultLayoutMethodBase(), types, elements)) {
return null
}

Expand All @@ -840,7 +839,7 @@ internal class GeneratedModelWriter(
* changed.
*/
private fun generateDataBindingMethodsIfNeeded(info: GeneratedModelInfo): Iterable<MethodSpec> {
if (!isDataBindingModel(info.getSuperClassElement())) {
if (!isDataBindingModel(info.superClassElement)) {
return emptyList()
}

Expand All @@ -852,14 +851,14 @@ internal class GeneratedModelWriter(
.build()

// If the base method is already implemented don't bother checking for the payload method
if (implementsMethod(info.getSuperClassElement(), bindVariablesMethod, types,
if (implementsMethod(info.superClassElement, bindVariablesMethod, types,
elements)) {
return emptyList()
}

val generatedModelClass = info.generatedName

val moduleName = dataBindingModuleLookup.getModuleName(info.getSuperClassElement())
val moduleName = dataBindingModuleLookup.getModuleName(info.superClassElement)

val baseMethodBuilder = bindVariablesMethod.toBuilder()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,20 @@ fun AnnotatedConstruct.hasAnyAnnotation(annotationClasses: List<Class<out Annota
}
}

fun AnnotatedConstruct.hasAnnotation(annotationClass: KClass<out Annotation>)
= hasAnyAnnotation(listOf(annotationClass.java))

inline fun <reified T : Annotation> AnnotatedConstruct.annotation(): T?
= getAnnotation(T::class.java)

/** Creates a new version of the classname where the simple name has the given suffix added to it.
*
* If there are multiple simple names they are combined into 1.
* */
fun ClassName.appendToName(suffix: String)
= ClassName.get(
packageName(),
simpleNames().joinToString( separator = "_", postfix = suffix)
simpleNames().joinToString(separator = "_", postfix = suffix)
).annotated(annotations)!!

/** Iterates through each character, allowing you to build a string by transforming the characters as needed. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ internal class ModelProcessor(
for ((_, modelInfo) in modelClassMap) {

if (modelInfo is BasicGeneratedModelInfo
&& modelInfo.superClassElement.annotation<EpoxyModelClass>()?.layout == 0
&& modelInfo.boundObjectTypeElement?.hasStyleableAnnotation(elements) == true) {
styleableModelsToWrite.add(modelInfo)
} else {
Expand Down

0 comments on commit e926ae3

Please sign in to comment.