@@ -93,33 +93,10 @@ class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private v
93
93
file.accept(IrVisitorLookup (psi2Ir, ownerPsi, file), owners)
94
94
95
95
for (ownerIr in owners) {
96
- val ownerLabel =
97
- if (ownerIr == file)
98
- fileLabel
99
- else {
100
- if (ownerIr is IrValueParameter && ownerIr.index == - 1 ) {
101
- // Don't attribute comments to the implicit `this` parameter of a function.
102
- continue
103
- }
104
- val label: String
105
- val existingLabel = if (ownerIr is IrVariable ) {
106
- label = " variable ${ownerIr.name.asString()} "
107
- tw.getExistingVariableLabelFor(ownerIr)
108
- } else if (ownerIr is IrFunction && ownerIr.isLocalFunction()) {
109
- label = " local function ${ownerIr.name.asString()} "
110
- fileExtractor.getExistingLocallyVisibleFunctionLabel(ownerIr)
111
- }
112
- else {
113
- label = getLabel(ownerIr) ? : continue
114
- tw.getExistingLabelFor<DbTop >(label)
115
- }
116
- if (existingLabel == null ) {
117
- logger.warn(" Couldn't get existing label for $label " )
118
- continue
119
- }
120
- existingLabel
121
- }
122
- tw.writeKtCommentOwners(commentLabel, ownerLabel)
96
+ val ownerLabel = getLabel(ownerIr)
97
+ if (ownerLabel != null ) {
98
+ tw.writeKtCommentOwners(commentLabel, ownerLabel)
99
+ }
123
100
}
124
101
}
125
102
@@ -131,7 +108,37 @@ class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private v
131
108
return owner
132
109
}
133
110
134
- private fun getLabel (element : IrElement ) : String? {
111
+ private fun getLabel (element : IrElement ): Label <out DbTop >? {
112
+ if (element == file)
113
+ return fileLabel
114
+
115
+ if (element is IrValueParameter && element.index == - 1 ) {
116
+ // Don't attribute comments to the implicit `this` parameter of a function.
117
+ return null
118
+ }
119
+
120
+ val label: String
121
+ val existingLabel = if (element is IrVariable ) {
122
+ // local variables are not named globally, so we need to get them from the variable label cache
123
+ label = " variable ${element.name.asString()} "
124
+ tw.getExistingVariableLabelFor(element)
125
+ } else if (element is IrFunction && element.isLocalFunction()) {
126
+ // local functions are not named globally, so we need to get them from the local function label cache
127
+ label = " local function ${element.name.asString()} "
128
+ fileExtractor.getExistingLocallyVisibleFunctionLabel(element)
129
+ }
130
+ else {
131
+ label = getLabelForNamedElement(element) ? : return null
132
+ tw.getExistingLabelFor<DbTop >(label)
133
+ }
134
+ if (existingLabel == null ) {
135
+ logger.warn(" Couldn't get existing label for $label " )
136
+ return null
137
+ }
138
+ return existingLabel
139
+ }
140
+
141
+ private fun getLabelForNamedElement (element : IrElement ) : String? {
135
142
when (element) {
136
143
is IrClass -> return fileExtractor.getClassLabel(element, listOf ()).classLabel
137
144
is IrTypeParameter -> return fileExtractor.getTypeParameterLabel(element)
@@ -155,10 +162,10 @@ class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private v
155
162
return null
156
163
}
157
164
// Assign the comment to the class. The content of the `init` blocks might be extracted in multiple constructors.
158
- return getLabel (parentClass)
165
+ return getLabelForNamedElement (parentClass)
159
166
}
160
167
161
- // Fresh entities:
168
+ // Fresh entities, not named elements :
162
169
is IrBody -> return null
163
170
is IrExpression -> return null
164
171
0 commit comments