Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a858a716 authored by Paul Duffin's avatar Paul Duffin
Browse files

Use CallableItem in place of MethodItem

The `MethodItem` type represents both a normal method as well as being
the super type of `ConstructorItem`. That organization causes a number
of issues in Metalava and has lead to quite a few issues where code
that only expected to be run on methods and not constructors was run on
both. So, a new type `CallableItem` has been added that will eventually
become the super type of both `MethodItem` and `ConstructorItem` and
`ConstructorItem` will no longer extend `MethodItem`.

This change prepares this code for that change.

Bug: 352481366
Test: ./gradlew
Change-Id: I9f2f60ce60337db55246a43e23285921a895519b
parent c3eca001
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -16,9 +16,9 @@

package android.platform.coverage

import com.android.tools.metalava.model.CallableItem
import com.android.tools.metalava.model.ClassItem
import com.android.tools.metalava.model.Item
import com.android.tools.metalava.model.MethodItem
import com.android.tools.metalava.model.text.ApiFile
import java.io.File
import java.io.FileWriter
@@ -40,24 +40,24 @@ fun main(args: Array<String>) {

fun extractFlaggedApisFromClass(
    classItem: ClassItem,
    methods: List<MethodItem>,
    callables: List<CallableItem>,
    packageName: String,
    builder: FlagApiMap.Builder
) {
    if (methods.isEmpty()) return
    if (callables.isEmpty()) return
    val classFlag = getClassFlag(classItem)
    for (method in methods) {
        val methodFlag = getFlagAnnotation(method) ?: classFlag
    for (callable in callables) {
        val callableFlag = getFlagAnnotation(callable) ?: classFlag
        val api =
            JavaMethod.newBuilder()
                .setPackageName(packageName)
                .setClassName(classItem.fullName())
                .setMethodName(method.name())
        for (param in method.parameters()) {
                .setMethodName(callable.name())
        for (param in callable.parameters()) {
            api.addParameters(param.type().toTypeString())
        }
        if (methodFlag != null) {
            addFlaggedApi(builder, api, methodFlag)
        if (callableFlag != null) {
            addFlaggedApi(builder, api, callableFlag)
        }
    }
}