org.jetbrains.android.anko.utils.ClassTreeUtils.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of anko-generator Show documentation
Show all versions of anko-generator Show documentation
The generator module from Anko.
The newest version!
/*
* Copyright 2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.android.anko.utils
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode
interface ClassTreeUtils {
val classTree: ClassTree
fun isExcluded(node: ClassNode): Boolean
fun isExcluded(node: MethodNodeWithClass): Boolean
fun findAvailableMethods(availableClasses: List): List {
return availableClasses.flatMap { classNode ->
classNode.methods
?.map { MethodNodeWithClass(classNode, it) }
?.filter { !isExcluded(it) }
?: emptyList()
}
}
val ClassNode.isView: Boolean
get() {
val isSuccessor = classTree.isSuccessorOf(this, "android/view/View") || this.name == "android/view/View"
return isSuccessor && !isInner
}
val ClassNode.isLayoutParams: Boolean
get() {
return isInner && (classTree.isSuccessorOf(
this,
"android/view/ViewGroup\$LayoutParams"
) || this.name == "android/view/ViewGroup\$LayoutParams")
}
val ClassNode.isViewGroup: Boolean
get() {
return !isInner && (classTree.isSuccessorOf(
this,
"android/view/ViewGroup"
) || this.name == "android/view/ViewGroup")
}
fun ClassNode.resolveAllMethods(): List {
val node = classTree.findNode(this)
fun allMethodsTo(node: ClassTreeNode?, list: MutableList) {
if (node == null) return
list.addAll(node.data.methods)
allMethodsTo(node.parent, list)
}
val list = arrayListOf()
allMethodsTo(node, list)
return list
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy