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

Fix grid layout manager #139

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add MethodSignature class instead of string concatenation
  • Loading branch information
sgrekov committed Jun 9, 2019
commit fd99d94dec08a7cb71f4d1b4c148bb91c740910d
32 changes: 17 additions & 15 deletions buildSrc/src/main/kotlin/trikita/anvilgen/NullabilityHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import java.net.URLClassLoader

class NullabilityHolder(isSourceSdk: Boolean) {

val nullabilityMap: MutableMap<String, Boolean?> = HashMap()
var nullableLiteral : String
var nonNullableLiteral : String
val nullabilityMap: MutableMap<MethodSignature, Boolean?> = HashMap()
var nullableLiteral: String
var nonNullableLiteral: String

init {
if (isSourceSdk){
if (isSourceSdk) {
nullableLiteral = "Landroidx/annotation/RecentlyNullable;"
nonNullableLiteral = "Landroidx/annotation/RecentlyNonNull;"
} else {
Expand All @@ -27,7 +27,7 @@ class NullabilityHolder(isSourceSdk: Boolean) {
val cn = ClassNode()
val cr = try {
ClassReader(loader.getResourceAsStream(rawClassName))
} catch (io : IOException) {
} catch (io: IOException) {
return
}

Expand All @@ -43,11 +43,10 @@ class NullabilityHolder(isSourceSdk: Boolean) {

val hasNullable = hasNullableOrNonNullAnnotation(methodNode.invisibleParameterAnnotations[0])
val argType = convertTypeNameFromRaw(methodNode.localVariables[1].desc)
println("++++++++++++++++++++++++++++++")
println("class: $className method: ${methodNode.name} param name ${methodNode.localVariables[1].name} type $argType : hasNullableOrNonNullAnnotation : $hasNullable")
val formattedMethodName = formatMethodName(methodNode.name, 1)
formattedMethodName?.let {
nullabilityMap["$className\$${it.formattedName}\$$argType"] = hasNullable

nullabilityMap[MethodSignature(className, it.formattedName, argType)] = hasNullable
}
}
}
Expand All @@ -70,7 +69,7 @@ class NullabilityHolder(isSourceSdk: Boolean) {
var anNode: AnnotationNode?
for (annotation in annotationList) {
anNode = annotation as AnnotationNode
when (anNode.desc){
when (anNode.desc) {
nullableLiteral -> return true
nonNullableLiteral -> return false
}
Expand All @@ -82,15 +81,18 @@ class NullabilityHolder(isSourceSdk: Boolean) {
fun isParameterNullable(m: Method): Boolean? {
val formattedMethodName = formatMethodName(m.name, 1)
return formattedMethodName?.let {
val key = "${m.declaringClass.canonicalName}\$${it.formattedName}\$${m.parameters[0].type.canonicalName}"
nullabilityMap[key]
nullabilityMap[MethodSignature(
m.declaringClass.canonicalName,
it.formattedName,
m.parameters[0].type.canonicalName
)]
}
}

fun isParameterNullable(className: String, methodName: String, argType : String ): Boolean? {
val key = "$className\$$methodName\$$argType"
return nullabilityMap[key]
fun isParameterNullable(className: String, methodName: String, argType: String): Boolean? {
return nullabilityMap[MethodSignature(className, methodName, argType)]
}

}

}
data class MethodSignature(val className: String, val methodName: String, val firstArgType: String)