com.flyjingfish.android_aop_plugin.beans.AopMatchCut.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of android-aop-plugin Show documentation
Show all versions of android-aop-plugin Show documentation
Lightweight Aop for Android platform, you deserve it, action is worse than your heartbeat
package com.flyjingfish.android_aop_plugin.beans
import java.util.regex.Pattern
data class AopMatchCut(val baseClassName:String, val methodNames:Array,val cutClassName:String,val matchType:String = "EXTENDS",val excludeClass:Array?, val overrideMethod: Boolean = false) {
enum class MatchType{
EXTENDS,SELF,DIRECT_EXTENDS,LEAF_EXTENDS
}
fun isMatchAllMethod():Boolean{
return methodNames.size == 1 && methodNames[0] == "*"
}
private val AllClassnamePattern = Pattern.compile(".\\*$")
fun isMatchPackageName():Boolean{
return matchType == MatchType.SELF.name && isPackageName()
}
fun isPackageName():Boolean{
val fanMatcher = AllClassnamePattern.matcher(baseClassName)
return fanMatcher.find()
}
fun isMatchPackageNameFor(className:String):Boolean{
if (!isMatchPackageName()){
return false
}
val matchPackageName = getMatchPackageName()
if ((matchPackageName.replace(".","")).isEmpty()){
return false
}
val filter = if (matchPackageName.endsWith(".")){
matchPackageName
}else {
"$matchPackageName."
}
return className.startsWith(filter)
}
private fun getMatchPackageName():String{
val fanMatcher = AllClassnamePattern.matcher(baseClassName)
return if (fanMatcher.find()){
fanMatcher.replaceAll("")
}else{
baseClassName
}
}
}