@@ -7,6 +7,9 @@ import com.intellij.psi.PsiComment
7
7
import com.intellij.psi.PsiElement
8
8
import org.jetbrains.kotlin.ir.IrElement
9
9
import org.jetbrains.kotlin.ir.declarations.*
10
+ import org.jetbrains.kotlin.ir.expressions.IrBody
11
+ import org.jetbrains.kotlin.ir.expressions.IrExpression
12
+ import org.jetbrains.kotlin.ir.util.parentClassOrNull
10
13
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
11
14
import org.jetbrains.kotlin.lexer.KtTokens
12
15
import org.jetbrains.kotlin.psi.KtVisitor
@@ -102,7 +105,7 @@ class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private v
102
105
label = " variable ${ownerIr.name.asString()} "
103
106
tw.getExistingVariableLabelFor(ownerIr)
104
107
} else {
105
- label = fileExtractor. getLabel(ownerIr) ? : continue
108
+ label = getLabel(ownerIr) ? : continue
106
109
tw.getExistingLabelFor<DbTop >(label)
107
110
}
108
111
if (existingLabel == null ) {
@@ -118,9 +121,42 @@ class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private v
118
121
private fun getKDocOwner (comment : KDoc ) : PsiElement ? {
119
122
val owner = comment.owner
120
123
if (owner == null ) {
121
- logger.warn(" Couldn't get owner of KDoc." )
124
+ logger.warn(" Couldn't get owner of KDoc. The comment is extracted without an owner. " )
122
125
}
123
126
return owner
124
127
}
128
+
129
+ private fun getLabel (element : IrElement ) : String? {
130
+ when (element) {
131
+ is IrClass -> return fileExtractor.getClassLabel(element, listOf ()).classLabel
132
+ is IrTypeParameter -> return fileExtractor.getTypeParameterLabel(element)
133
+ is IrFunction -> return fileExtractor.getFunctionLabel(element, null )
134
+ is IrValueParameter -> return fileExtractor.getValueParameterLabel(element, null )
135
+ is IrProperty -> return fileExtractor.getPropertyLabel(element)
136
+ is IrField -> return fileExtractor.getFieldLabel(element)
137
+ is IrEnumEntry -> return fileExtractor.getEnumEntryLabel(element)
138
+ is IrTypeAlias -> return fileExtractor.getTypeAliasLabel(element)
139
+
140
+ is IrAnonymousInitializer -> {
141
+ val parentClass = element.parentClassOrNull
142
+ if (parentClass == null ) {
143
+ logger.errorElement(" Parent of anonymous initializer is not a class" , element)
144
+ return null
145
+ }
146
+ // Assign the comment to the class. The content of the `init` blocks might be extracted in multiple constructors.
147
+ return fileExtractor.getClassLabel(parentClass, listOf ()).classLabel
148
+ }
149
+
150
+ // Fresh entities:
151
+ is IrBody -> return null
152
+ is IrExpression -> return null
153
+
154
+ // todo add others:
155
+ else -> {
156
+ logger.errorElement(" Unhandled element type: ${element::class } " , element)
157
+ return null
158
+ }
159
+ }
125
160
}
161
+ }
126
162
}
0 commit comments