• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.tools.metalava.cli.signature
18 
19 import com.android.tools.metalava.model.CallableItem
20 import com.android.tools.metalava.model.ClassItem
21 import com.android.tools.metalava.model.ConstructorItem
22 import com.android.tools.metalava.model.DelegatedVisitor
23 import com.android.tools.metalava.model.FieldItem
24 import com.android.tools.metalava.model.MethodItem
25 import java.io.PrintWriter
26 
27 internal class DexApiWriter(
28     private val writer: PrintWriter,
29 ) : DelegatedVisitor {
30 
visitClassnull31     override fun visitClass(cls: ClassItem) {
32         writer.print(cls.type().internalName())
33         writer.print("\n")
34     }
35 
visitConstructornull36     override fun visitConstructor(constructor: ConstructorItem) {
37         writeCallable(constructor)
38     }
39 
visitMethodnull40     override fun visitMethod(method: MethodItem) {
41         if (method.inheritedFromAncestor) {
42             return
43         }
44 
45         writeCallable(method)
46     }
47 
writeCallablenull48     private fun writeCallable(callable: CallableItem) {
49         writer.print(callable.containingClass().type().internalName())
50         writer.print("->")
51         writer.print(callable.internalName())
52         writer.print("(")
53         for (pi in callable.parameters()) {
54             writer.print(pi.type().internalName())
55         }
56         writer.print(")")
57         if (callable.isConstructor()) {
58             writer.print("V")
59         } else {
60             val returnType = callable.returnType()
61             writer.print(returnType.internalName())
62         }
63         writer.print("\n")
64     }
65 
visitFieldnull66     override fun visitField(field: FieldItem) {
67         val cls = field.containingClass()
68 
69         writer.print(cls.type().internalName())
70         writer.print("->")
71         writer.print(field.name())
72         writer.print(":")
73         writer.print(field.type().internalName())
74         writer.print("\n")
75     }
76 }
77