All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.flyjingfish.android_aop_plugin.beans.AopMatchCut.kt Maven / Gradle / Ivy

Go to download

Lightweight Aop for Android platform, you deserve it, action is worse than your heartbeat

There is a newer version: 2.2.8
Show newest version
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
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy