Skip to content

Commit

Permalink
Add @UiThread annotation to applies and builders
Browse files Browse the repository at this point in the history
  • Loading branch information
ngsilverman committed Sep 2, 2017
1 parent 6c4124e commit 3695c72
Show file tree
Hide file tree
Showing 7 changed files with 782 additions and 711 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ import javax.annotation.processing.*
import javax.lang.model.element.*
import javax.lang.model.type.*
import javax.lang.model.util.*
import kotlin.Boolean
import kotlin.String
import kotlin.apply
import kotlin.check
import kotlin.let

// TODO Add @UiThread annotation to StyleApplier classes
internal object StyleAppliersWriter {

val styleablesTree = StyleablesTree()
Expand All @@ -40,6 +35,7 @@ internal object StyleAppliersWriter {
val styleApplierClassName = styleableInfo.styleApplierClassName()

val styleTypeBuilder = TypeSpec.classBuilder(styleApplierClassName)
.addAnnotation(ClassNames.ANDROID_UI_THREAD)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.superclass(ParameterizedTypeName.get(ParisProcessor.STYLE_APPLIER_CLASS_NAME, TypeName.get(styleableInfo.elementType), TypeName.get(styleableInfo.viewElementType)))
.addMethod(buildConstructorMethod(styleableInfo))
Expand Down Expand Up @@ -297,6 +293,7 @@ internal object StyleAppliersWriter {
// StyleBuilder inner class
val styleBuilderClassName = styleApplierClassName.nestedClass("StyleBuilder")
val styleBuilderTypeBuilder = TypeSpec.classBuilder(styleBuilderClassName)
.addAnnotation(ClassNames.ANDROID_UI_THREAD)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.superclass(ParameterizedTypeName.get(baseClassName, styleBuilderClassName, styleApplierClassName))
.addMethod(buildStyleBuilderApplierConstructorMethod(styleApplierClassName))
Expand Down Expand Up @@ -338,10 +335,10 @@ internal object StyleAppliersWriter {
StyleInfo.Kind.FIELD -> builder.addStatement("add(\$T.\$L)", styleInfo.enclosingElement, styleInfo.elementName)
StyleInfo.Kind.METHOD -> {
builder
.addStatement("consumeSimpleStyleBuilder()")
.addStatement("consumeProgrammaticStyleBuilder()")
.addStatement("debugName(\$S)", styleInfo.formattedName)
.addStatement("\$T.\$L(this)", styleInfo.enclosingElement, styleInfo.elementName)
.addStatement("consumeSimpleStyleBuilder()")
.addStatement("consumeProgrammaticStyleBuilder()")
}
StyleInfo.Kind.STYLE_RES -> {
builder.addStatement("add(\$L)", styleInfo.styleResourceCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ internal object ClassNames {
val ANDROID_INTEGER_RES = "android.support.annotation.IntegerRes".className()
val ANDROID_STRING_RES = "android.support.annotation.StringRes".className()
val ANDROID_STYLE_RES = "android.support.annotation.StyleRes".className()
val ANDROID_UI_THREAD = "android.support.annotation.UiThread".className()
}
Loading

0 comments on commit 3695c72

Please sign in to comment.