• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * 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.model
18 
19 import com.android.tools.metalava.model.visitors.ItemVisitor
20 import com.android.tools.metalava.model.visitors.TypeVisitor
21 
22 interface PropertyItem : MemberItem {
23     /** The getter for this property, if it exists; inverse of [MethodItem.property] */
24     val getter: MethodItem?
25         get() = null
26 
27     /** The setter for this property, if it exists; inverse of [MethodItem.property] */
28     val setter: MethodItem?
29         get() = null
30 
31     /** The backing field for this property, if it exists; inverse of [FieldItem.property] */
32     val backingField: FieldItem?
33         get() = null
34 
35     /**
36      * The constructor parameter for this property, if declared in a primary constructor; inverse
37      * of [ParameterItem.property]
38      */
39     val constructorParameter: ParameterItem?
40         get() = null
41 
42     /** The type of this property */
43     override fun type(): TypeItem
44 
45     override fun accept(visitor: ItemVisitor) {
46         if (visitor.skip(this)) {
47             return
48         }
49 
50         visitor.visitItem(this)
51         visitor.visitProperty(this)
52 
53         visitor.afterVisitProperty(this)
54         visitor.afterVisitItem(this)
55     }
56 
57     override fun acceptTypes(visitor: TypeVisitor) {
58         if (visitor.skip(this)) {
59             return
60         }
61 
62         val type = type()
63         visitor.visitType(type, this)
64         visitor.afterVisitType(type, this)
65     }
66 
67     override fun hasNullnessInfo(): Boolean {
68         if (!requiresNullnessInfo()) {
69             return true
70         }
71 
72         return modifiers.hasNullnessInfo()
73     }
74 
75     override fun requiresNullnessInfo(): Boolean {
76         if (type().primitive) {
77             return false
78         }
79 
80         return true
81     }
82 
83     companion object {
84         val comparator: java.util.Comparator<PropertyItem> = Comparator { a, b -> a.name().compareTo(b.name()) }
85     }
86 }
87