Analysis API: get rid of KtTypeAndAnnotations & add annotations for every type
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.annotations
|
||||
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
public interface KtAnnotated {
|
||||
public val annotationsList: KtAnnotationsList
|
||||
}
|
||||
|
||||
public val KtAnnotated.annotations: List<KtAnnotationApplication>
|
||||
get() = annotationsList.annotations
|
||||
|
||||
public fun KtAnnotated.containsAnnotation(classId: ClassId): Boolean =
|
||||
annotationsList.containsAnnotation(classId)
|
||||
|
||||
public fun KtAnnotated.annotationsByClassId(classId: ClassId): List<KtAnnotationApplication> =
|
||||
annotationsList.annotationsByClassId(classId)
|
||||
|
||||
public val KtAnnotated.annotationClassIds: Collection<ClassId>
|
||||
get() = annotationsList.annotationClassIds
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.annotations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.ValidityTokenOwner
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
|
||||
public abstract class KtAnnotationApplication : ValidityTokenOwner {
|
||||
public abstract val classId: ClassId?
|
||||
public abstract val useSiteTarget: AnnotationUseSiteTarget?
|
||||
public abstract val psi: KtCallElement?
|
||||
public abstract val arguments: List<KtNamedConstantValue>
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.annotations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.ValidityTokenOwner
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
public abstract class KtAnnotationsList : ValidityTokenOwner {
|
||||
public abstract val annotations: List<KtAnnotationApplication>
|
||||
public abstract fun containsAnnotation(classId: ClassId): Boolean
|
||||
public abstract fun annotationsByClassId(classId: ClassId): List<KtAnnotationApplication>
|
||||
public abstract val annotationClassIds: Collection<ClassId>
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.annotations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtConstantValue
|
||||
|
||||
public data class KtNamedConstantValue(val name: String, val expression: KtConstantValue)
|
||||
+15
-9
@@ -7,6 +7,10 @@ package org.jetbrains.kotlin.analysis.api.symbols
|
||||
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationInfo
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtNamedConstantValue
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.annotations
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtSymbolInfoProviderMixIn
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.*
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtClassErrorType
|
||||
@@ -124,19 +128,17 @@ public object DebugSymbolRenderer {
|
||||
}
|
||||
|
||||
private fun Block.renderType(type: KtType) {
|
||||
if (type.annotations.isNotEmpty()) {
|
||||
renderList(type.annotations)
|
||||
append(' ')
|
||||
}
|
||||
when (type) {
|
||||
is KtClassErrorType -> append("ERROR_TYPE")
|
||||
else -> append(type.asStringForDebugging())
|
||||
}
|
||||
}
|
||||
|
||||
private fun Block.renderTypeAndAnnotations(type: KtTypeAndAnnotations) {
|
||||
renderList(type.annotations)
|
||||
append(' ')
|
||||
renderType(type.type)
|
||||
}
|
||||
|
||||
private fun Block.renderAnnotationCall(call: KtAnnotationCall) {
|
||||
private fun Block.renderAnnotationApplication(call: KtAnnotationApplication) {
|
||||
renderValue(call.classId)
|
||||
append('(')
|
||||
call.arguments.sortedBy { it.name }.forEachIndexed { index, value ->
|
||||
@@ -166,10 +168,10 @@ public object DebugSymbolRenderer {
|
||||
// Symbol-related values
|
||||
is KtSymbol -> renderSymbolTag(value)
|
||||
is KtType -> renderType(value)
|
||||
is KtTypeAndAnnotations -> renderTypeAndAnnotations(value)
|
||||
is KtConstantValue -> renderConstantValue(value)
|
||||
is KtNamedConstantValue -> renderNamedConstantValue(value)
|
||||
is KtAnnotationCall -> renderAnnotationCall(value)
|
||||
is KtAnnotationApplication -> renderAnnotationApplication(value)
|
||||
is KtAnnotationsList -> renderAnnotationsList(value)
|
||||
// Other custom values
|
||||
is Name -> append(value.asString())
|
||||
is FqName -> append(value.asString())
|
||||
@@ -188,6 +190,10 @@ public object DebugSymbolRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
private fun Block.renderAnnotationsList(value: KtAnnotationsList) {
|
||||
renderList(value.annotations)
|
||||
}
|
||||
|
||||
private fun getSymbolApiClass(symbol: KtSymbol): KClass<*> {
|
||||
var current: Class<in KtSymbol> = symbol.javaClass
|
||||
|
||||
|
||||
+4
-4
@@ -6,15 +6,15 @@
|
||||
package org.jetbrains.kotlin.analysis.api.symbols
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithKind
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtTypeAndAnnotations
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
|
||||
public abstract class KtCallableSymbol : KtSymbol, KtSymbolWithKind {
|
||||
public abstract val callableIdIfNonLocal: CallableId?
|
||||
public abstract val annotatedType: KtTypeAndAnnotations
|
||||
public abstract val type: KtType
|
||||
|
||||
public abstract val receiverType: KtTypeAndAnnotations?
|
||||
public abstract val receiverType: KtType?
|
||||
public abstract val isExtension: Boolean
|
||||
|
||||
abstract override fun createPointer(): KtSymbolPointer<KtCallableSymbol>
|
||||
@@ -25,5 +25,5 @@ public abstract class KtCallableSymbol : KtSymbol, KtSymbolWithKind {
|
||||
* `String` receiver parameter is such a symbol.
|
||||
*/
|
||||
public abstract class KtReceiverParameterSymbol : KtSymbol {
|
||||
public abstract val type: KtTypeAndAnnotations
|
||||
public abstract val type: KtType
|
||||
}
|
||||
+1
-1
@@ -52,7 +52,7 @@ public sealed class KtClassOrObjectSymbol : KtClassLikeSymbol(),
|
||||
KtSymbolWithMembers {
|
||||
|
||||
public abstract val classKind: KtClassKind
|
||||
public abstract val superTypes: List<KtTypeAndAnnotations>
|
||||
public abstract val superTypes: List<KtType>
|
||||
|
||||
abstract override fun createPointer(): KtSymbolPointer<KtClassOrObjectSymbol>
|
||||
}
|
||||
|
||||
+2
-1
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.api.symbols
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.*
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
@@ -66,7 +67,7 @@ public abstract class KtConstructorSymbol : KtFunctionLikeSymbol(),
|
||||
final override val callableIdIfNonLocal: CallableId? get() = null
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.CLASS_MEMBER
|
||||
final override val isExtension: Boolean get() = false
|
||||
final override val receiverType: KtTypeAndAnnotations? get() = null
|
||||
final override val receiverType: KtType? get() = null
|
||||
|
||||
abstract override fun createPointer(): KtSymbolPointer<KtConstructorSymbol>
|
||||
}
|
||||
|
||||
+6
-5
@@ -9,6 +9,7 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.*
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -37,7 +38,7 @@ public abstract class KtBackingFieldSymbol : KtVariableLikeSymbol() {
|
||||
final override val origin: KtSymbolOrigin get() = KtSymbolOrigin.PROPERTY_BACKING_FIELD
|
||||
final override val callableIdIfNonLocal: CallableId? get() = null
|
||||
final override val isExtension: Boolean get() = false
|
||||
final override val receiverType: KtTypeAndAnnotations? get() = null
|
||||
final override val receiverType: KtType? get() = null
|
||||
|
||||
abstract override fun createPointer(): KtSymbolPointer<KtVariableLikeSymbol>
|
||||
|
||||
@@ -50,7 +51,7 @@ public abstract class KtBackingFieldSymbol : KtVariableLikeSymbol() {
|
||||
public abstract class KtEnumEntrySymbol : KtVariableLikeSymbol(), KtSymbolWithMembers, KtSymbolWithKind {
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.CLASS_MEMBER
|
||||
final override val isExtension: Boolean get() = false
|
||||
final override val receiverType: KtTypeAndAnnotations? get() = null
|
||||
final override val receiverType: KtType? get() = null
|
||||
public abstract val containingEnumClassIdIfNonLocal: ClassId?
|
||||
|
||||
abstract override fun createPointer(): KtSymbolPointer<KtEnumEntrySymbol>
|
||||
@@ -69,7 +70,7 @@ public abstract class KtJavaFieldSymbol :
|
||||
KtSymbolWithKind {
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.CLASS_MEMBER
|
||||
final override val isExtension: Boolean get() = false
|
||||
final override val receiverType: KtTypeAndAnnotations? get() = null
|
||||
final override val receiverType: KtType? get() = null
|
||||
public abstract val isStatic: Boolean
|
||||
|
||||
abstract override fun createPointer(): KtSymbolPointer<KtJavaFieldSymbol>
|
||||
@@ -126,7 +127,7 @@ public abstract class KtSyntheticJavaPropertySymbol : KtPropertySymbol() {
|
||||
public abstract class KtLocalVariableSymbol : KtVariableSymbol(), KtSymbolWithKind {
|
||||
final override val callableIdIfNonLocal: CallableId? get() = null
|
||||
final override val isExtension: Boolean get() = false
|
||||
final override val receiverType: KtTypeAndAnnotations? get() = null
|
||||
final override val receiverType: KtType? get() = null
|
||||
|
||||
abstract override fun createPointer(): KtSymbolPointer<KtLocalVariableSymbol>
|
||||
}
|
||||
@@ -135,7 +136,7 @@ public abstract class KtValueParameterSymbol : KtVariableLikeSymbol(), KtSymbolW
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL
|
||||
final override val callableIdIfNonLocal: CallableId? get() = null
|
||||
final override val isExtension: Boolean get() = false
|
||||
final override val receiverType: KtTypeAndAnnotations? get() = null
|
||||
final override val receiverType: KtType? get() = null
|
||||
|
||||
public abstract val hasDefaultValue: Boolean
|
||||
public abstract val isVararg: Boolean
|
||||
|
||||
+3
-18
@@ -5,24 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.symbols.markers
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.analysis.api.ValidityTokenOwner
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotated
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
|
||||
public abstract class KtAnnotationCall : ValidityTokenOwner {
|
||||
public abstract val classId: ClassId?
|
||||
public abstract val useSiteTarget: AnnotationUseSiteTarget?
|
||||
public abstract val psi: KtCallElement?
|
||||
public abstract val arguments: List<KtNamedConstantValue>
|
||||
}
|
||||
|
||||
public data class KtNamedConstantValue(val name: String, val expression: KtConstantValue)
|
||||
|
||||
public interface KtAnnotatedSymbol : KtSymbol {
|
||||
public val annotations: List<KtAnnotationCall>
|
||||
|
||||
public fun containsAnnotation(classId: ClassId): Boolean
|
||||
public val annotationClassIds: Collection<ClassId>
|
||||
}
|
||||
public interface KtAnnotatedSymbol : KtSymbol, KtAnnotated
|
||||
+1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.symbols.markers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtNamedConstantValue
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.symbols.markers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.ValidityTokenOwner
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
|
||||
public abstract class KtTypeAndAnnotations : ValidityTokenOwner {
|
||||
public abstract val type: KtType
|
||||
public abstract val annotations: List<KtAnnotationCall>
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as KtTypeAndAnnotations
|
||||
|
||||
if (token != other.token) return false
|
||||
if (type != other.type) return false
|
||||
if (annotations != other.annotations) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = token.hashCode()
|
||||
result = 31 * result + type.hashCode()
|
||||
result = 31 * result + annotations.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -7,14 +7,14 @@ package org.jetbrains.kotlin.analysis.api.types
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtTypeArgument
|
||||
import org.jetbrains.kotlin.analysis.api.ValidityTokenOwner
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotated
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.ConeNullability
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
public sealed interface KtType : ValidityTokenOwner {
|
||||
public sealed interface KtType : ValidityTokenOwner, KtAnnotated {
|
||||
public val nullability: KtTypeNullability
|
||||
public fun asStringForDebugging(): String
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user