core: cleanup 'public', property access syntax
This commit is contained in:
+2
-2
@@ -20,8 +20,8 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
|
||||
public object FakePureImplementationsProvider {
|
||||
public fun getPurelyImplementedInterface(classFqName: FqName): FqName? = when(classFqName) {
|
||||
object FakePureImplementationsProvider {
|
||||
fun getPurelyImplementedInterface(classFqName: FqName): FqName? = when(classFqName) {
|
||||
in MUTABLE_LISTS_IMPLEMENTATIONS -> MUTABLE_LIST_FQ_NAME
|
||||
in MUTABLE_MAPS_IMPLEMENTATIONS -> MUTABLE_MAP_FQ_NAME
|
||||
in MUTABLE_SETS_IMPLEMENTATIONS -> MUTABLE_SET_FQ_NAME
|
||||
|
||||
+8
-8
@@ -36,7 +36,7 @@ import java.lang.annotation.Retention
|
||||
import java.lang.annotation.Target
|
||||
import java.util.EnumSet
|
||||
|
||||
public object JavaAnnotationMapper {
|
||||
object JavaAnnotationMapper {
|
||||
|
||||
private val JAVA_TARGET_FQ_NAME = FqName(Target::class.java.canonicalName)
|
||||
private val JAVA_RETENTION_FQ_NAME = FqName(Retention::class.java.canonicalName)
|
||||
@@ -45,7 +45,7 @@ public object JavaAnnotationMapper {
|
||||
// Java8-specific thing
|
||||
private val JAVA_REPEATABLE_FQ_NAME = FqName("java.lang.annotation.Repeatable")
|
||||
|
||||
public fun mapOrResolveJavaAnnotation(annotation: JavaAnnotation, c: LazyJavaResolverContext): AnnotationDescriptor? =
|
||||
fun mapOrResolveJavaAnnotation(annotation: JavaAnnotation, c: LazyJavaResolverContext): AnnotationDescriptor? =
|
||||
when (annotation.classId) {
|
||||
ClassId.topLevel(JAVA_TARGET_FQ_NAME) -> JavaTargetAnnotationDescriptor(annotation, c)
|
||||
ClassId.topLevel(JAVA_RETENTION_FQ_NAME) -> JavaRetentionAnnotationDescriptor(annotation, c)
|
||||
@@ -55,7 +55,7 @@ public object JavaAnnotationMapper {
|
||||
else -> c.resolveAnnotation(annotation)
|
||||
}
|
||||
|
||||
public fun findMappedJavaAnnotation(kotlinName: FqName,
|
||||
fun findMappedJavaAnnotation(kotlinName: FqName,
|
||||
annotationOwner: JavaAnnotationOwner,
|
||||
c: LazyJavaResolverContext
|
||||
): AnnotationDescriptor? {
|
||||
@@ -79,7 +79,7 @@ public object JavaAnnotationMapper {
|
||||
KotlinBuiltIns.FQ_NAMES.repeatable to JAVA_REPEATABLE_FQ_NAME,
|
||||
KotlinBuiltIns.FQ_NAMES.mustBeDocumented to JAVA_DOCUMENTED_FQ_NAME)
|
||||
|
||||
public val javaToKotlinNameMap: Map<FqName, FqName> =
|
||||
val javaToKotlinNameMap: Map<FqName, FqName> =
|
||||
mapOf(JAVA_TARGET_FQ_NAME to KotlinBuiltIns.FQ_NAMES.target,
|
||||
JAVA_RETENTION_FQ_NAME to KotlinBuiltIns.FQ_NAMES.retention,
|
||||
JAVA_DEPRECATED_FQ_NAME to KotlinBuiltIns.FQ_NAMES.deprecated,
|
||||
@@ -154,7 +154,7 @@ class JavaRetentionAnnotationDescriptor(
|
||||
override fun getAllValueArguments() = valueArguments()
|
||||
}
|
||||
|
||||
public object JavaAnnotationTargetMapper {
|
||||
object JavaAnnotationTargetMapper {
|
||||
private val targetNameLists = mapOf("PACKAGE" to EnumSet.noneOf(KotlinTarget::class.java),
|
||||
"TYPE" to EnumSet.of(KotlinTarget.CLASS, KotlinTarget.FILE),
|
||||
"ANNOTATION_TYPE" to EnumSet.of(KotlinTarget.ANNOTATION_CLASS),
|
||||
@@ -169,9 +169,9 @@ public object JavaAnnotationTargetMapper {
|
||||
"TYPE_USE" to EnumSet.of(KotlinTarget.TYPE)
|
||||
)
|
||||
|
||||
public fun mapJavaTargetArgumentByName(argumentName: String?): Set<KotlinTarget> = targetNameLists[argumentName] ?: emptySet()
|
||||
fun mapJavaTargetArgumentByName(argumentName: String?): Set<KotlinTarget> = targetNameLists[argumentName] ?: emptySet()
|
||||
|
||||
public fun mapJavaTargetArguments(arguments: List<JavaAnnotationArgument>, builtIns: KotlinBuiltIns): ConstantValue<*>? {
|
||||
fun mapJavaTargetArguments(arguments: List<JavaAnnotationArgument>, builtIns: KotlinBuiltIns): ConstantValue<*>? {
|
||||
// Map arguments: java.lang.annotation.Target -> kotlin.annotation.Target
|
||||
val kotlinTargets = arguments.filterIsInstance<JavaEnumValueAnnotationArgument>()
|
||||
.flatMap { mapJavaTargetArgumentByName(it.resolve()?.name?.asString()) }
|
||||
@@ -188,7 +188,7 @@ public object JavaAnnotationTargetMapper {
|
||||
"SOURCE" to KotlinRetention.SOURCE
|
||||
)
|
||||
|
||||
public fun mapJavaRetentionArgument(element: JavaAnnotationArgument, builtIns: KotlinBuiltIns): ConstantValue<*>? {
|
||||
fun mapJavaRetentionArgument(element: JavaAnnotationArgument, builtIns: KotlinBuiltIns): ConstantValue<*>? {
|
||||
// Map argument: java.lang.annotation.Retention -> kotlin.annotation.annotation
|
||||
return (element as? JavaEnumValueAnnotationArgument)?.let {
|
||||
retentionNameList[it.resolve()?.name?.asString()]?.let {
|
||||
|
||||
+5
-5
@@ -24,8 +24,8 @@ import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaMethod
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
public interface SamConversionResolver {
|
||||
public companion object EMPTY : SamConversionResolver {
|
||||
interface SamConversionResolver {
|
||||
companion object EMPTY : SamConversionResolver {
|
||||
override fun <D : FunctionDescriptor> resolveSamAdapter(original: D) = null
|
||||
override fun resolveSamConstructor(constructorOwner: DeclarationDescriptor, classifier: () -> ClassifierDescriptor?) = null
|
||||
override fun resolveFunctionTypeIfSamInterface(
|
||||
@@ -33,11 +33,11 @@ public interface SamConversionResolver {
|
||||
): KotlinType? = null
|
||||
}
|
||||
|
||||
public fun resolveSamConstructor(constructorOwner: DeclarationDescriptor, classifier: () -> ClassifierDescriptor?): SamConstructorDescriptor?
|
||||
fun resolveSamConstructor(constructorOwner: DeclarationDescriptor, classifier: () -> ClassifierDescriptor?): SamConstructorDescriptor?
|
||||
|
||||
public fun <D : FunctionDescriptor> resolveSamAdapter(original: D): D?
|
||||
fun <D : FunctionDescriptor> resolveSamAdapter(original: D): D?
|
||||
|
||||
public fun resolveFunctionTypeIfSamInterface(
|
||||
fun resolveFunctionTypeIfSamInterface(
|
||||
classDescriptor: JavaClassDescriptor,
|
||||
resolveMethod: (JavaMethod) -> FunctionDescriptor
|
||||
): KotlinType?
|
||||
|
||||
+5
-5
@@ -21,19 +21,19 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
||||
|
||||
public class SamConstructorDescriptor(
|
||||
class SamConstructorDescriptor(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
samInterface: JavaClassDescriptor
|
||||
) : SimpleFunctionDescriptorImpl(
|
||||
containingDeclaration,
|
||||
null,
|
||||
samInterface.getAnnotations(),
|
||||
samInterface.getName(),
|
||||
samInterface.annotations,
|
||||
samInterface.name,
|
||||
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
||||
samInterface.getSource()
|
||||
samInterface.source
|
||||
)
|
||||
|
||||
public object SamConstructorDescriptorKindExclude : DescriptorKindExclude() {
|
||||
object SamConstructorDescriptorKindExclude : DescriptorKindExclude() {
|
||||
override fun excludes(descriptor: DeclarationDescriptor) = descriptor is SamConstructorDescriptor
|
||||
|
||||
override val fullyExcludedDescriptorKinds: Int get() = 0
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.storage.MemoizedFunctionToNullable
|
||||
import org.jetbrains.kotlin.utils.emptyOrSingletonList
|
||||
|
||||
public class LazyJavaPackageFragmentProvider(
|
||||
class LazyJavaPackageFragmentProvider(
|
||||
components: JavaResolverComponents,
|
||||
module: ModuleDescriptor,
|
||||
reflectionTypes: ReflectionTypes
|
||||
|
||||
+4
-4
@@ -23,11 +23,11 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import kotlin.properties.Delegates
|
||||
import javax.inject.Inject
|
||||
|
||||
public interface ModuleClassResolver {
|
||||
public fun resolveClass(javaClass: JavaClass): ClassDescriptor?
|
||||
interface ModuleClassResolver {
|
||||
fun resolveClass(javaClass: JavaClass): ClassDescriptor?
|
||||
}
|
||||
|
||||
public class SingleModuleClassResolver() : ModuleClassResolver {
|
||||
class SingleModuleClassResolver() : ModuleClassResolver {
|
||||
override fun resolveClass(javaClass: JavaClass): ClassDescriptor? {
|
||||
return resolver!!.resolveClass(javaClass)
|
||||
}
|
||||
@@ -37,6 +37,6 @@ public class SingleModuleClassResolver() : ModuleClassResolver {
|
||||
@Inject set
|
||||
}
|
||||
|
||||
public class ModuleClassResolverImpl(private val descriptorResolverByJavaClass: (JavaClass) -> JavaDescriptorResolver): ModuleClassResolver {
|
||||
class ModuleClassResolverImpl(private val descriptorResolverByJavaClass: (JavaClass) -> JavaDescriptorResolver): ModuleClassResolver {
|
||||
override fun resolveClass(javaClass: JavaClass): ClassDescriptor? = descriptorResolverByJavaClass(javaClass).resolveClass(javaClass)
|
||||
}
|
||||
|
||||
+1
-1
@@ -20,5 +20,5 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
|
||||
|
||||
// Currently getter is null iff it's loaded from Java field
|
||||
public val PropertyDescriptor.isJavaField: Boolean
|
||||
val PropertyDescriptor.isJavaField: Boolean
|
||||
get() = getter == null
|
||||
+9
-9
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.utils.keysToMapExceptNulls
|
||||
|
||||
fun LazyJavaResolverContext.resolveAnnotation(annotation: JavaAnnotation): LazyJavaAnnotationDescriptor? {
|
||||
val classId = annotation.getClassId()
|
||||
val classId = annotation.classId
|
||||
if (classId == null || isSpecialAnnotation(classId, false)) return null
|
||||
return LazyJavaAnnotationDescriptor(this, annotation)
|
||||
}
|
||||
@@ -74,12 +74,12 @@ class LazyJavaAnnotationDescriptor(
|
||||
override fun getSource() = source
|
||||
|
||||
private fun computeValueArguments(): Map<ValueParameterDescriptor, ConstantValue<*>> {
|
||||
val constructors = getAnnotationClass().getConstructors()
|
||||
val constructors = getAnnotationClass().constructors
|
||||
if (constructors.isEmpty()) return mapOf()
|
||||
|
||||
val nameToArg = javaAnnotation.getArguments().toMapBy { it.name }
|
||||
val nameToArg = javaAnnotation.arguments.toMapBy { it.name }
|
||||
|
||||
return constructors.first().getValueParameters().keysToMapExceptNulls { valueParameter ->
|
||||
return constructors.first().valueParameters.keysToMapExceptNulls { valueParameter ->
|
||||
var javaAnnotationArgument = nameToArg[valueParameter.getName()]
|
||||
if (javaAnnotationArgument == null && valueParameter.getName() == DEFAULT_ANNOTATION_MEMBER_NAME) {
|
||||
javaAnnotationArgument = nameToArg[null]
|
||||
@@ -89,7 +89,7 @@ class LazyJavaAnnotationDescriptor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAnnotationClass() = getType().getConstructor().getDeclarationDescriptor() as ClassDescriptor
|
||||
private fun getAnnotationClass() = getType().getConstructor().declarationDescriptor as ClassDescriptor
|
||||
|
||||
private fun resolveAnnotationArgument(argument: JavaAnnotationArgument?): ConstantValue<*>? {
|
||||
return when (argument) {
|
||||
@@ -116,18 +116,18 @@ class LazyJavaAnnotationDescriptor(
|
||||
val values = elements.map {
|
||||
argument -> resolveAnnotationArgument(argument) ?: factory.createNullValue()
|
||||
}
|
||||
return factory.createArrayValue(values, valueParameter.getType())
|
||||
return factory.createArrayValue(values, valueParameter.type)
|
||||
}
|
||||
|
||||
private fun resolveFromEnumValue(element: JavaField?): ConstantValue<*>? {
|
||||
if (element == null || !element.isEnumEntry()) return null
|
||||
if (element == null || !element.isEnumEntry) return null
|
||||
|
||||
val containingJavaClass = element.getContainingClass()
|
||||
val containingJavaClass = element.containingClass
|
||||
|
||||
//TODO: (module refactoring) moduleClassResolver should be used here
|
||||
val enumClass = c.javaClassResolver.resolveClass(containingJavaClass) ?: return null
|
||||
|
||||
val classifier = enumClass.getUnsubstitutedInnerClassesScope().getContributedClassifier(element.getName(), NoLookupLocation.FROM_JAVA_LOADER)
|
||||
val classifier = enumClass.unsubstitutedInnerClassesScope.getContributedClassifier(element.name, NoLookupLocation.FROM_JAVA_LOADER)
|
||||
if (classifier !is ClassDescriptor) return null
|
||||
|
||||
return factory.createEnumValue(classifier)
|
||||
|
||||
+7
-7
@@ -57,18 +57,18 @@ class LazyJavaClassDescriptor(
|
||||
}
|
||||
|
||||
private val kind = when {
|
||||
jClass.isAnnotationType() -> ClassKind.ANNOTATION_CLASS
|
||||
jClass.isInterface() -> ClassKind.INTERFACE
|
||||
jClass.isEnum() -> ClassKind.ENUM_CLASS
|
||||
jClass.isAnnotationType -> ClassKind.ANNOTATION_CLASS
|
||||
jClass.isInterface -> ClassKind.INTERFACE
|
||||
jClass.isEnum -> ClassKind.ENUM_CLASS
|
||||
else -> ClassKind.CLASS
|
||||
}
|
||||
|
||||
private val modality = if (jClass.isAnnotationType())
|
||||
private val modality = if (jClass.isAnnotationType)
|
||||
Modality.FINAL
|
||||
else Modality.convertFromFlags(jClass.isAbstract() || jClass.isInterface(), !jClass.isFinal())
|
||||
else Modality.convertFromFlags(jClass.isAbstract || jClass.isInterface, !jClass.isFinal)
|
||||
|
||||
private val visibility = jClass.getVisibility()
|
||||
private val isInner = jClass.getOuterClass() != null && !jClass.isStatic()
|
||||
private val visibility = jClass.visibility
|
||||
private val isInner = jClass.outerClass != null && !jClass.isStatic
|
||||
|
||||
override fun getKind() = kind
|
||||
override fun getModality() = modality
|
||||
|
||||
+16
-16
@@ -60,14 +60,14 @@ import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||
import java.util.*
|
||||
|
||||
public class LazyJavaClassMemberScope(
|
||||
class LazyJavaClassMemberScope(
|
||||
c: LazyJavaResolverContext,
|
||||
override val ownerDescriptor: ClassDescriptor,
|
||||
private val jClass: JavaClass
|
||||
) : LazyJavaScope(c) {
|
||||
|
||||
override fun computeMemberIndex(): MemberIndex {
|
||||
return object : ClassMemberIndex(jClass, { !it.isStatic() }) {
|
||||
return object : ClassMemberIndex(jClass, { !it.isStatic }) {
|
||||
// For SAM-constructors
|
||||
override fun getMethodNames(nameFilter: (Name) -> Boolean): Collection<Name>
|
||||
= super.getMethodNames(nameFilter) + getClassNames(DescriptorKindFilter.CLASSIFIERS, nameFilter)
|
||||
@@ -341,7 +341,7 @@ public class LazyJavaClassMemberScope(
|
||||
}
|
||||
|
||||
override fun computeNonDeclaredProperties(name: Name, result: MutableCollection<PropertyDescriptor>) {
|
||||
if (jClass.isAnnotationType()) {
|
||||
if (jClass.isAnnotationType) {
|
||||
computeAnnotationProperties(name, result)
|
||||
}
|
||||
|
||||
@@ -506,13 +506,13 @@ public class LazyJavaClassMemberScope(
|
||||
classDescriptor, c.resolveAnnotations(constructor), /* isPrimary = */ false, c.components.sourceElementFactory.source(constructor)
|
||||
)
|
||||
|
||||
val valueParameters = resolveValueParameters(c, constructorDescriptor, constructor.getValueParameters())
|
||||
val valueParameters = resolveValueParameters(c, constructorDescriptor, constructor.valueParameters)
|
||||
|
||||
constructorDescriptor.initialize(valueParameters.descriptors, constructor.visibility)
|
||||
constructorDescriptor.setHasStableParameterNames(false)
|
||||
constructorDescriptor.setHasSynthesizedParameterNames(valueParameters.hasSynthesizedNames)
|
||||
|
||||
constructorDescriptor.setReturnType(classDescriptor.getDefaultType())
|
||||
constructorDescriptor.returnType = classDescriptor.defaultType
|
||||
|
||||
c.components.javaResolverCache.recordConstructor(constructor, constructorDescriptor)
|
||||
|
||||
@@ -520,8 +520,8 @@ public class LazyJavaClassMemberScope(
|
||||
}
|
||||
|
||||
private fun createDefaultConstructor(): ConstructorDescriptor? {
|
||||
val isAnnotation: Boolean = jClass.isAnnotationType()
|
||||
if (jClass.isInterface() && !isAnnotation)
|
||||
val isAnnotation: Boolean = jClass.isAnnotationType
|
||||
if (jClass.isInterface && !isAnnotation)
|
||||
return null
|
||||
|
||||
val classDescriptor = ownerDescriptor
|
||||
@@ -534,13 +534,13 @@ public class LazyJavaClassMemberScope(
|
||||
|
||||
constructorDescriptor.initialize(valueParameters, getConstructorVisibility(classDescriptor))
|
||||
constructorDescriptor.setHasStableParameterNames(true)
|
||||
constructorDescriptor.setReturnType(classDescriptor.getDefaultType())
|
||||
constructorDescriptor.returnType = classDescriptor.defaultType
|
||||
c.components.javaResolverCache.recordConstructor(jClass, constructorDescriptor);
|
||||
return constructorDescriptor
|
||||
}
|
||||
|
||||
private fun getConstructorVisibility(classDescriptor: ClassDescriptor): Visibility {
|
||||
val visibility = classDescriptor.getVisibility()
|
||||
val visibility = classDescriptor.visibility
|
||||
if (visibility == JavaVisibilities.PROTECTED_STATIC_VISIBILITY) {
|
||||
return JavaVisibilities.PROTECTED_AND_PACKAGE
|
||||
}
|
||||
@@ -548,22 +548,22 @@ public class LazyJavaClassMemberScope(
|
||||
}
|
||||
|
||||
private fun createAnnotationConstructorParameters(constructor: ConstructorDescriptorImpl): List<ValueParameterDescriptor> {
|
||||
val methods = jClass.getMethods()
|
||||
val methods = jClass.methods
|
||||
val result = ArrayList<ValueParameterDescriptor>(methods.size)
|
||||
|
||||
val attr = TypeUsage.MEMBER_SIGNATURE_INVARIANT.toAttributes(allowFlexible = false, isForAnnotationParameter = true)
|
||||
|
||||
val (methodsNamedValue, otherMethods) = methods.
|
||||
partition { it.getName() == JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME }
|
||||
partition { it.name == JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME }
|
||||
|
||||
assert(methodsNamedValue.size <= 1) { "There can't be more than one method named 'value' in annotation class: $jClass" }
|
||||
val methodNamedValue = methodsNamedValue.firstOrNull()
|
||||
if (methodNamedValue != null) {
|
||||
val parameterNamedValueJavaType = methodNamedValue.getReturnType()
|
||||
val parameterNamedValueJavaType = methodNamedValue.returnType
|
||||
val (parameterType, varargType) =
|
||||
if (parameterNamedValueJavaType is JavaArrayType)
|
||||
Pair(c.typeResolver.transformArrayType(parameterNamedValueJavaType, attr, isVararg = true),
|
||||
c.typeResolver.transformJavaType(parameterNamedValueJavaType.getComponentType(), attr))
|
||||
c.typeResolver.transformJavaType(parameterNamedValueJavaType.componentType, attr))
|
||||
else
|
||||
Pair(c.typeResolver.transformJavaType(parameterNamedValueJavaType, attr), null)
|
||||
|
||||
@@ -572,7 +572,7 @@ public class LazyJavaClassMemberScope(
|
||||
|
||||
val startIndex = if (methodNamedValue != null) 1 else 0
|
||||
for ((index, method) in otherMethods.withIndex()) {
|
||||
val parameterType = c.typeResolver.transformJavaType(method.getReturnType(), attr)
|
||||
val parameterType = c.typeResolver.transformJavaType(method.returnType, attr)
|
||||
result.addAnnotationValueParameter(constructor, index + startIndex, method, parameterType, null)
|
||||
}
|
||||
|
||||
@@ -591,7 +591,7 @@ public class LazyJavaClassMemberScope(
|
||||
null,
|
||||
index,
|
||||
Annotations.EMPTY,
|
||||
method.getName(),
|
||||
method.name,
|
||||
// Parameters of annotation constructors in Java are never nullable
|
||||
TypeUtils.makeNotNullable(returnType),
|
||||
method.hasAnnotationParameterDefaultValue(),
|
||||
@@ -654,5 +654,5 @@ public class LazyJavaClassMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString() = "Lazy java member scope for " + jClass.getFqName()
|
||||
override fun toString() = "Lazy java member scope for " + jClass.fqName
|
||||
}
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.storage.getValue
|
||||
|
||||
public class LazyJavaPackageScope(
|
||||
class LazyJavaPackageScope(
|
||||
c: LazyJavaResolverContext,
|
||||
private val jPackage: JavaPackage,
|
||||
override val ownerDescriptor: LazyJavaPackageFragment
|
||||
@@ -58,7 +58,7 @@ public class LazyJavaPackageScope(
|
||||
result
|
||||
}
|
||||
|
||||
public fun getFacadeSimpleNameForPartSimpleName(partName: String): String? =
|
||||
fun getFacadeSimpleNameForPartSimpleName(partName: String): String? =
|
||||
partToFacade()[partName]
|
||||
|
||||
private val deserializedPackageScope by c.storageManager.createLazyValue {
|
||||
|
||||
+16
-16
@@ -49,7 +49,7 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
import java.util.*
|
||||
|
||||
public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberScopeImpl() {
|
||||
abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberScopeImpl() {
|
||||
protected abstract val ownerDescriptor: DeclarationDescriptor
|
||||
|
||||
// this lazy value is not used at all in LazyPackageFragmentScopeForJavaPackage because we do not use caching there
|
||||
@@ -118,8 +118,8 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
|
||||
|
||||
val c = c.child(functionDescriptorImpl, method)
|
||||
|
||||
val methodTypeParameters = method.getTypeParameters().map { p -> c.typeParameterResolver.resolveTypeParameter(p)!! }
|
||||
val valueParameters = resolveValueParameters(c, functionDescriptorImpl, method.getValueParameters())
|
||||
val methodTypeParameters = method.typeParameters.map { p -> c.typeParameterResolver.resolveTypeParameter(p)!! }
|
||||
val valueParameters = resolveValueParameters(c, functionDescriptorImpl, method.valueParameters)
|
||||
|
||||
val returnType = computeMethodReturnType(method, annotations, c)
|
||||
|
||||
@@ -131,8 +131,8 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
|
||||
effectiveSignature.typeParameters,
|
||||
effectiveSignature.valueParameters,
|
||||
effectiveSignature.returnType,
|
||||
Modality.convertFromFlags(method.isAbstract(), !method.isFinal()),
|
||||
method.getVisibility()
|
||||
Modality.convertFromFlags(method.isAbstract, !method.isFinal),
|
||||
method.visibility
|
||||
)
|
||||
|
||||
functionDescriptorImpl.setParameterNamesStatus(effectiveSignature.hasStableParameterNames, valueParameters.hasSynthesizedNames)
|
||||
@@ -145,13 +145,13 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
|
||||
}
|
||||
|
||||
protected fun computeMethodReturnType(method: JavaMethod, annotations: Annotations, c: LazyJavaResolverContext): KotlinType {
|
||||
val annotationMethod = method.getContainingClass().isAnnotationType()
|
||||
val annotationMethod = method.containingClass.isAnnotationType
|
||||
val returnTypeAttrs = LazyJavaTypeAttributes(
|
||||
TypeUsage.MEMBER_SIGNATURE_COVARIANT, annotations,
|
||||
allowFlexible = !annotationMethod,
|
||||
isForAnnotationParameter = annotationMethod
|
||||
)
|
||||
return c.typeResolver.transformJavaType(method.getReturnType(), returnTypeAttrs).let {
|
||||
return c.typeResolver.transformJavaType(method.returnType, returnTypeAttrs).let {
|
||||
// Annotation arguments are never null in Java
|
||||
if (annotationMethod) TypeUtils.makeNotNullable(it) else it
|
||||
}
|
||||
@@ -171,17 +171,17 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
|
||||
val annotations = c.resolveAnnotations(javaParameter)
|
||||
val typeUsage = LazyJavaTypeAttributes(TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT, annotations)
|
||||
val (outType, varargElementType) =
|
||||
if (javaParameter.isVararg()) {
|
||||
val paramType = javaParameter.getType() as? JavaArrayType
|
||||
if (javaParameter.isVararg) {
|
||||
val paramType = javaParameter.type as? JavaArrayType
|
||||
?: throw AssertionError("Vararg parameter should be an array: $javaParameter")
|
||||
val outType = c.typeResolver.transformArrayType(paramType, typeUsage, true)
|
||||
outType to c.module.builtIns.getArrayElementType(outType)
|
||||
}
|
||||
else {
|
||||
c.typeResolver.transformJavaType(javaParameter.getType(), typeUsage) to null
|
||||
c.typeResolver.transformJavaType(javaParameter.type, typeUsage) to null
|
||||
}
|
||||
|
||||
val name = if (function.getName().asString() == "equals" &&
|
||||
val name = if (function.name.asString() == "equals" &&
|
||||
jValueParameters.size == 1 &&
|
||||
c.module.builtIns.getNullableAnyType() == outType) {
|
||||
// This is a hack to prevent numerous warnings on Kotlin classes that inherit Java classes: if you override "equals" in such
|
||||
@@ -192,7 +192,7 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
|
||||
}
|
||||
else {
|
||||
// TODO: parameter names may be drawn from attached sources, which is slow; it's better to make them lazy
|
||||
val javaName = javaParameter.getName()
|
||||
val javaName = javaParameter.name
|
||||
if (javaName == null) synthesizedNames = true
|
||||
javaName ?: Name.identifier("p$index")
|
||||
}
|
||||
@@ -264,10 +264,10 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
|
||||
}
|
||||
|
||||
private fun createPropertyDescriptor(field: JavaField): PropertyDescriptorImpl {
|
||||
val isVar = !field.isFinal()
|
||||
val visibility = field.getVisibility()
|
||||
val isVar = !field.isFinal
|
||||
val visibility = field.visibility
|
||||
val annotations = c.resolveAnnotations(field)
|
||||
val propertyName = field.getName()
|
||||
val propertyName = field.name
|
||||
|
||||
return JavaPropertyDescriptor(ownerDescriptor, annotations, Modality.FINAL, visibility, isVar, propertyName,
|
||||
c.components.sourceElementFactory.source(field), /* original = */ null, /*isConst= */ field.isFinalStatic)
|
||||
@@ -347,7 +347,7 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
|
||||
override fun toString() = "Lazy scope for ${ownerDescriptor}"
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println(javaClass.getSimpleName(), " {")
|
||||
p.println(javaClass.simpleName, " {")
|
||||
p.pushIndent()
|
||||
|
||||
p.println("containingDeclaration: ${ownerDescriptor}")
|
||||
|
||||
+4
-4
@@ -33,20 +33,20 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
public class LazyJavaStaticClassScope(
|
||||
class LazyJavaStaticClassScope(
|
||||
c: LazyJavaResolverContext,
|
||||
private val jClass: JavaClass,
|
||||
override val ownerDescriptor: LazyJavaClassDescriptor
|
||||
) : LazyJavaStaticScope(c) {
|
||||
|
||||
override fun computeMemberIndex(): MemberIndex {
|
||||
val delegate = ClassMemberIndex(jClass) { it.isStatic() }
|
||||
val delegate = ClassMemberIndex(jClass) { it.isStatic }
|
||||
return object : MemberIndex by delegate {
|
||||
override fun getMethodNames(nameFilter: (Name) -> Boolean): Collection<Name> {
|
||||
// Should be a super call, but KT-2860
|
||||
return delegate.getMethodNames(nameFilter) +
|
||||
// For SAM-constructors
|
||||
jClass.getInnerClasses().map { it.getName() }
|
||||
jClass.innerClasses.map { it.name }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class LazyJavaStaticClassScope(
|
||||
val functionsFromSupertypes = getStaticFunctionsFromJavaSuperClasses(name, ownerDescriptor)
|
||||
result.addAll(DescriptorResolverUtils.resolveOverrides(name, functionsFromSupertypes, result, ownerDescriptor, c.components.errorReporter))
|
||||
|
||||
if (jClass.isEnum()) {
|
||||
if (jClass.isEnum) {
|
||||
when (name) {
|
||||
DescriptorUtils.ENUM_VALUE_OF -> result.add(createEnumValueOfMethod(ownerDescriptor))
|
||||
DescriptorUtils.ENUM_VALUES -> result.add(createEnumValuesMethod(ownerDescriptor))
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
public abstract class LazyJavaStaticScope(c: LazyJavaResolverContext) : LazyJavaScope(c) {
|
||||
abstract class LazyJavaStaticScope(c: LazyJavaResolverContext) : LazyJavaScope(c) {
|
||||
|
||||
override fun getDispatchReceiverParameter() = null
|
||||
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
class LazyJavaTypeParameterDescriptor(
|
||||
private val c: LazyJavaResolverContext,
|
||||
public val javaTypeParameter: JavaTypeParameter,
|
||||
val javaTypeParameter: JavaTypeParameter,
|
||||
index: Int,
|
||||
containingDeclaration: DeclarationDescriptor
|
||||
) : AbstractLazyTypeParameterDescriptor(
|
||||
|
||||
+3
-3
@@ -81,12 +81,12 @@ private fun <M : JavaMember> JavaClass.getAllMemberNames(filter: (M) -> Boolean,
|
||||
|
||||
for (member in getMembers()) {
|
||||
if (filter(member)) {
|
||||
result.add(member.getName())
|
||||
result.add(member.name)
|
||||
}
|
||||
}
|
||||
|
||||
for (supertype in getSupertypes()) {
|
||||
val classifier = supertype.getClassifier()
|
||||
for (supertype in supertypes) {
|
||||
val classifier = supertype.classifier
|
||||
if (classifier is JavaClass) {
|
||||
result.addAll(classifier.getNonDeclaredMethodNames())
|
||||
classifier.visit()
|
||||
|
||||
@@ -45,7 +45,7 @@ class LazyJavaTypeParameterResolver(
|
||||
private val containingDeclaration: DeclarationDescriptor,
|
||||
typeParameterOwner: JavaTypeParameterListOwner
|
||||
) : TypeParameterResolver {
|
||||
private val typeParameters: Map<JavaTypeParameter, Int> = typeParameterOwner.getTypeParameters().mapToIndex()
|
||||
private val typeParameters: Map<JavaTypeParameter, Int> = typeParameterOwner.typeParameters.mapToIndex()
|
||||
|
||||
private val resolve = c.storageManager.createMemoizedFunctionWithNullableValues {
|
||||
typeParameter: JavaTypeParameter ->
|
||||
|
||||
+20
-20
@@ -45,10 +45,10 @@ class LazyJavaTypeResolver(
|
||||
private val typeParameterResolver: TypeParameterResolver
|
||||
) {
|
||||
|
||||
public fun transformJavaType(javaType: JavaType, attr: JavaTypeAttributes): KotlinType {
|
||||
fun transformJavaType(javaType: JavaType, attr: JavaTypeAttributes): KotlinType {
|
||||
return when (javaType) {
|
||||
is JavaPrimitiveType -> {
|
||||
val primitiveType = javaType.getType()
|
||||
val primitiveType = javaType.type
|
||||
if (primitiveType != null) c.module.builtIns.getPrimitiveKotlinType(primitiveType)
|
||||
else c.module.builtIns.getUnitType()
|
||||
}
|
||||
@@ -64,10 +64,10 @@ class LazyJavaTypeResolver(
|
||||
}
|
||||
}
|
||||
|
||||
public fun transformArrayType(arrayType: JavaArrayType, attr: JavaTypeAttributes, isVararg: Boolean = false): KotlinType {
|
||||
fun transformArrayType(arrayType: JavaArrayType, attr: JavaTypeAttributes, isVararg: Boolean = false): KotlinType {
|
||||
return run {
|
||||
val javaComponentType = arrayType.getComponentType()
|
||||
val primitiveType = (javaComponentType as? JavaPrimitiveType)?.getType()
|
||||
val javaComponentType = arrayType.componentType
|
||||
val primitiveType = (javaComponentType as? JavaPrimitiveType)?.type
|
||||
if (primitiveType != null) {
|
||||
val jetType = c.module.builtIns.getPrimitiveArrayKotlinType(primitiveType)
|
||||
return@run if (attr.allowFlexible)
|
||||
@@ -101,7 +101,7 @@ class LazyJavaTypeResolver(
|
||||
override fun computeTypeConstructor(): TypeConstructor {
|
||||
val classifier = classifier()
|
||||
if (classifier == null) {
|
||||
return ErrorUtils.createErrorTypeConstructor("Unresolved java classifier: " + javaType.getPresentableText())
|
||||
return ErrorUtils.createErrorTypeConstructor("Unresolved java classifier: " + javaType.presentableText)
|
||||
}
|
||||
return when (classifier) {
|
||||
is JavaClass -> {
|
||||
@@ -109,16 +109,16 @@ class LazyJavaTypeResolver(
|
||||
|
||||
val classData = mapKotlinClass(fqName) ?: c.components.moduleClassResolver.resolveClass(classifier)
|
||||
|
||||
classData?.getTypeConstructor()
|
||||
?: ErrorUtils.createErrorTypeConstructor("Unresolved java classifier: " + javaType.getPresentableText())
|
||||
classData?.typeConstructor
|
||||
?: ErrorUtils.createErrorTypeConstructor("Unresolved java classifier: " + javaType.presentableText)
|
||||
}
|
||||
is JavaTypeParameter -> {
|
||||
if (isConstructorTypeParameter()) {
|
||||
getConstructorTypeParameterSubstitute().getConstructor()
|
||||
}
|
||||
else {
|
||||
typeParameterResolver.resolveTypeParameter(classifier)?.getTypeConstructor()
|
||||
?: ErrorUtils.createErrorTypeConstructor("Unresolved Java type parameter: " + javaType.getPresentableText())
|
||||
typeParameterResolver.resolveTypeParameter(classifier)?.typeConstructor
|
||||
?: ErrorUtils.createErrorTypeConstructor("Unresolved Java type parameter: " + javaType.presentableText)
|
||||
}
|
||||
}
|
||||
else -> throw IllegalStateException("Unknown classifier kind: $classifier")
|
||||
@@ -174,18 +174,18 @@ class LazyJavaTypeResolver(
|
||||
}
|
||||
|
||||
private fun isRaw(): Boolean {
|
||||
if (javaType.isRaw()) return true
|
||||
if (javaType.isRaw) return true
|
||||
|
||||
// This option is needed because sometimes we get weird versions of JDK classes in the class path,
|
||||
// such as collections with no generics, so the Java types are not raw, formally, but they don't match with
|
||||
// their Kotlin analogs, so we treat them as raw to avoid exceptions
|
||||
// No type arguments, but some are expected => raw
|
||||
return javaType.getTypeArguments().isEmpty() && !getConstructor().getParameters().isEmpty()
|
||||
return javaType.typeArguments.isEmpty() && !getConstructor().parameters.isEmpty()
|
||||
}
|
||||
|
||||
override fun computeArguments(): List<TypeProjection> {
|
||||
val typeConstructor = getConstructor()
|
||||
val typeParameters = typeConstructor.getParameters()
|
||||
val typeParameters = typeConstructor.parameters
|
||||
if (isRaw()) {
|
||||
return typeParameters.map {
|
||||
parameter ->
|
||||
@@ -213,12 +213,12 @@ class LazyJavaTypeResolver(
|
||||
return getConstructorTypeParameterSubstitute().getArguments()
|
||||
}
|
||||
|
||||
if (typeParameters.size != javaType.getTypeArguments().size) {
|
||||
if (typeParameters.size != javaType.typeArguments.size) {
|
||||
// Most of the time this means there is an error in the Java code
|
||||
return typeParameters.map { p -> TypeProjectionImpl(ErrorUtils.createErrorType(p.getName().asString())) }
|
||||
return typeParameters.map { p -> TypeProjectionImpl(ErrorUtils.createErrorType(p.name.asString())) }
|
||||
}
|
||||
var howTheProjectionIsUsed = if (attr.howThisTypeIsUsed == SUPERTYPE) SUPERTYPE_ARGUMENT else TYPE_ARGUMENT
|
||||
return javaType.getTypeArguments().withIndex().map {
|
||||
return javaType.typeArguments.withIndex().map {
|
||||
javaTypeParameter ->
|
||||
val (i, t) = javaTypeParameter
|
||||
val parameter = if (i >= typeParameters.size)
|
||||
@@ -235,7 +235,7 @@ class LazyJavaTypeResolver(
|
||||
): TypeProjection {
|
||||
return when (javaType) {
|
||||
is JavaWildcardType -> {
|
||||
val bound = javaType.getBound()
|
||||
val bound = javaType.bound
|
||||
if (bound == null)
|
||||
makeStarProjection(typeParameter, attr)
|
||||
else {
|
||||
@@ -278,7 +278,7 @@ class LazyJavaTypeResolver(
|
||||
override fun getAnnotations() = annotations
|
||||
}
|
||||
|
||||
public object FlexibleJavaClassifierTypeCapabilities : FlexibleTypeCapabilities {
|
||||
object FlexibleJavaClassifierTypeCapabilities : FlexibleTypeCapabilities {
|
||||
@JvmStatic
|
||||
fun create(lowerBound: KotlinType, upperBound: KotlinType) = DelegatingFlexibleType.create(lowerBound, upperBound, this)
|
||||
|
||||
@@ -380,8 +380,8 @@ class LazyJavaTypeAttributes(
|
||||
private fun hasAnnotation(fqName: FqName) = typeAnnotations.findAnnotation(fqName) != null
|
||||
}
|
||||
|
||||
public fun Annotations.isMarkedNotNull() = findAnnotation(JETBRAINS_NOT_NULL_ANNOTATION) != null
|
||||
public fun Annotations.isMarkedNullable() = findAnnotation(JETBRAINS_NULLABLE_ANNOTATION) != null
|
||||
fun Annotations.isMarkedNotNull() = findAnnotation(JETBRAINS_NOT_NULL_ANNOTATION) != null
|
||||
fun Annotations.isMarkedNullable() = findAnnotation(JETBRAINS_NULLABLE_ANNOTATION) != null
|
||||
|
||||
fun TypeUsage.toAttributes(
|
||||
allowFlexible: Boolean = true,
|
||||
|
||||
+3
-3
@@ -24,9 +24,9 @@ import org.jetbrains.kotlin.renderer.CustomFlexibleRendering
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.types.*
|
||||
|
||||
public object RawTypeTag : TypeCapability
|
||||
object RawTypeTag : TypeCapability
|
||||
|
||||
public object RawTypeCapabilities : TypeCapabilities {
|
||||
object RawTypeCapabilities : TypeCapabilities {
|
||||
private object RawSubstitutionCapability : CustomSubstitutionCapability {
|
||||
override val substitution: TypeSubstitution?
|
||||
get() = RawSubstitution
|
||||
@@ -89,7 +89,7 @@ internal object RawSubstitution : TypeSubstitution() {
|
||||
private val lowerTypeAttr = TypeUsage.MEMBER_SIGNATURE_INVARIANT.toAttributes().toFlexible(JavaTypeFlexibility.FLEXIBLE_LOWER_BOUND)
|
||||
private val upperTypeAttr = TypeUsage.MEMBER_SIGNATURE_INVARIANT.toAttributes().toFlexible(JavaTypeFlexibility.FLEXIBLE_UPPER_BOUND)
|
||||
|
||||
public fun eraseType(type: KotlinType): KotlinType {
|
||||
fun eraseType(type: KotlinType): KotlinType {
|
||||
val declaration = type.constructor.declarationDescriptor
|
||||
return when (declaration) {
|
||||
is TypeParameterDescriptor -> eraseType(declaration.getErasedUpperBound())
|
||||
|
||||
+2
-2
@@ -32,8 +32,8 @@ fun propertyNamesBySetMethodName(methodName: Name)
|
||||
= listOf(propertyNameBySetMethodName(methodName, false), propertyNameBySetMethodName(methodName, true)).filterNotNull()
|
||||
|
||||
private fun propertyNameFromAccessorMethodName(methodName: Name, prefix: String, removePrefix: Boolean = true, addPrefix: String? = null): Name? {
|
||||
if (methodName.isSpecial()) return null
|
||||
val identifier = methodName.getIdentifier()
|
||||
if (methodName.isSpecial) return null
|
||||
val identifier = methodName.identifier
|
||||
if (!identifier.startsWith(prefix)) return null
|
||||
if (identifier.length == prefix.length) return null
|
||||
if (identifier[prefix.length] in 'a'..'z') return null
|
||||
|
||||
+4
-4
@@ -19,10 +19,10 @@ package org.jetbrains.kotlin.load.java.sources
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaElement
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
|
||||
public interface JavaSourceElementFactory {
|
||||
public fun source(javaElement: JavaElement): JavaSourceElement
|
||||
interface JavaSourceElementFactory {
|
||||
fun source(javaElement: JavaElement): JavaSourceElement
|
||||
}
|
||||
|
||||
public interface JavaSourceElement: SourceElement {
|
||||
public val javaElement: JavaElement
|
||||
interface JavaSourceElement: SourceElement {
|
||||
val javaElement: JavaElement
|
||||
}
|
||||
|
||||
+5
-5
@@ -79,7 +79,7 @@ object BuiltinMethodsWithSpecialGenericSignature {
|
||||
FqName("kotlin.MutableCollection.retainAll")
|
||||
)
|
||||
|
||||
public enum class DefaultValue(val value: Any?) {
|
||||
enum class DefaultValue(val value: Any?) {
|
||||
NULL(null), INDEX(-1), FALSE(false)
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ private fun getOverriddenBuiltinThatAffectsJvmName(
|
||||
return null
|
||||
}
|
||||
|
||||
public fun ClassDescriptor.hasRealKotlinSuperClassWithOverrideOf(
|
||||
fun ClassDescriptor.hasRealKotlinSuperClassWithOverrideOf(
|
||||
specialCallableDescriptor: CallableDescriptor
|
||||
): Boolean {
|
||||
val builtinContainerDefaultType = (specialCallableDescriptor.containingDeclaration as ClassDescriptor).defaultType
|
||||
@@ -286,16 +286,16 @@ public fun ClassDescriptor.hasRealKotlinSuperClassWithOverrideOf(
|
||||
}
|
||||
|
||||
// Util methods
|
||||
public val CallableMemberDescriptor.isFromJava: Boolean
|
||||
val CallableMemberDescriptor.isFromJava: Boolean
|
||||
get() = propertyIfAccessor is JavaCallableMemberDescriptor && propertyIfAccessor.containingDeclaration is JavaClassDescriptor
|
||||
|
||||
public fun CallableMemberDescriptor.isFromBuiltins(): Boolean {
|
||||
fun CallableMemberDescriptor.isFromBuiltins(): Boolean {
|
||||
val fqName = propertyIfAccessor.fqNameOrNull() ?: return false
|
||||
return fqName.toUnsafe().startsWith(KotlinBuiltIns.BUILT_INS_PACKAGE_NAME) &&
|
||||
this.module == this.builtIns.builtInsModule
|
||||
}
|
||||
|
||||
public fun CallableMemberDescriptor.isFromJavaOrBuiltins() = isFromJava || isFromBuiltins()
|
||||
fun CallableMemberDescriptor.isFromJavaOrBuiltins() = isFromJava || isFromBuiltins()
|
||||
|
||||
private fun Map<FqName, Name>.getInversedShortNamesMap(): Map<Name, List<Name>> =
|
||||
entries.groupBy { it.value }.mapValues { entry -> entry.value.map { it.key.shortName() } }
|
||||
+4
-4
@@ -19,10 +19,10 @@ package org.jetbrains.kotlin.load.java.structure
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
public interface JavaPackage : JavaElement {
|
||||
public fun getClasses(nameFilter: (Name) -> Boolean): Collection<JavaClass>
|
||||
interface JavaPackage : JavaElement {
|
||||
fun getClasses(nameFilter: (Name) -> Boolean): Collection<JavaClass>
|
||||
|
||||
public fun getSubPackages(): Collection<JavaPackage>
|
||||
fun getSubPackages(): Collection<JavaPackage>
|
||||
|
||||
public fun getFqName(): FqName
|
||||
fun getFqName(): FqName
|
||||
}
|
||||
|
||||
+4
-4
@@ -19,12 +19,12 @@ package org.jetbrains.kotlin.load.java.structure
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
|
||||
public interface JavaPropertyInitializerEvaluator {
|
||||
public fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor): ConstantValue<*>?
|
||||
interface JavaPropertyInitializerEvaluator {
|
||||
fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor): ConstantValue<*>?
|
||||
|
||||
public fun isNotNullCompileTimeConstant(field: JavaField): Boolean
|
||||
fun isNotNullCompileTimeConstant(field: JavaField): Boolean
|
||||
|
||||
public object DoNothing : JavaPropertyInitializerEvaluator {
|
||||
object DoNothing : JavaPropertyInitializerEvaluator {
|
||||
override fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor) = null
|
||||
|
||||
override fun isNotNullCompileTimeConstant(field: JavaField) = false
|
||||
|
||||
+12
-12
@@ -18,26 +18,26 @@ package org.jetbrains.kotlin.load.java.structure
|
||||
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
public interface JavaAnnotationArgument {
|
||||
public val name: Name?
|
||||
interface JavaAnnotationArgument {
|
||||
val name: Name?
|
||||
}
|
||||
|
||||
public interface JavaLiteralAnnotationArgument : JavaAnnotationArgument {
|
||||
public val value: Any?
|
||||
interface JavaLiteralAnnotationArgument : JavaAnnotationArgument {
|
||||
val value: Any?
|
||||
}
|
||||
|
||||
public interface JavaArrayAnnotationArgument : JavaAnnotationArgument {
|
||||
public fun getElements(): List<JavaAnnotationArgument>
|
||||
interface JavaArrayAnnotationArgument : JavaAnnotationArgument {
|
||||
fun getElements(): List<JavaAnnotationArgument>
|
||||
}
|
||||
|
||||
public interface JavaEnumValueAnnotationArgument : JavaAnnotationArgument {
|
||||
public fun resolve(): JavaField?
|
||||
interface JavaEnumValueAnnotationArgument : JavaAnnotationArgument {
|
||||
fun resolve(): JavaField?
|
||||
}
|
||||
|
||||
public interface JavaClassObjectAnnotationArgument : JavaAnnotationArgument {
|
||||
public fun getReferencedType(): JavaType
|
||||
interface JavaClassObjectAnnotationArgument : JavaAnnotationArgument {
|
||||
fun getReferencedType(): JavaType
|
||||
}
|
||||
|
||||
public interface JavaAnnotationAsAnnotationArgument : JavaAnnotationArgument {
|
||||
public fun getAnnotation(): JavaAnnotation
|
||||
interface JavaAnnotationAsAnnotationArgument : JavaAnnotationArgument {
|
||||
fun getAnnotation(): JavaAnnotation
|
||||
}
|
||||
|
||||
+8
-8
@@ -20,27 +20,27 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
public fun <D : CallableMemberDescriptor> enhanceSignatures(platformSignatures: Collection<D>): Collection<D> {
|
||||
fun <D : CallableMemberDescriptor> enhanceSignatures(platformSignatures: Collection<D>): Collection<D> {
|
||||
return platformSignatures.map {
|
||||
it.enhanceSignature()
|
||||
}
|
||||
}
|
||||
|
||||
public fun <D : CallableMemberDescriptor> D.enhanceSignature(): D {
|
||||
fun <D : CallableMemberDescriptor> D.enhanceSignature(): D {
|
||||
// TODO type parameters
|
||||
// TODO use new type parameters while enhancing other types
|
||||
// TODO Propagation into generic type arguments
|
||||
|
||||
val enhancedReceiverType =
|
||||
if (getExtensionReceiverParameter() != null)
|
||||
parts(isCovariant = false) { it.getExtensionReceiverParameter()!!.getType() }.enhance()
|
||||
if (extensionReceiverParameter != null)
|
||||
parts(isCovariant = false) { it.extensionReceiverParameter!!.type }.enhance()
|
||||
else null
|
||||
|
||||
val enhancedValueParametersTypes = getValueParameters().map {
|
||||
p -> parts(isCovariant = false) { it.getValueParameters()[p.index].getType() }.enhance()
|
||||
val enhancedValueParametersTypes = valueParameters.map {
|
||||
p -> parts(isCovariant = false) { it.valueParameters[p.index].type }.enhance()
|
||||
}
|
||||
|
||||
val enhancedReturnType = parts(isCovariant = true) { it.getReturnType()!! }.enhance()
|
||||
val enhancedReturnType = parts(isCovariant = true) { it.returnType!! }.enhance()
|
||||
|
||||
if (this is JavaCallableMemberDescriptor) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@@ -64,7 +64,7 @@ private class SignatureParts(
|
||||
private fun <D : CallableMemberDescriptor> D.parts(isCovariant: Boolean, collector: (D) -> KotlinType): SignatureParts {
|
||||
return SignatureParts(
|
||||
collector(this),
|
||||
this.getOverriddenDescriptors().map {
|
||||
this.overriddenDescriptors.map {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
collector(it as D)
|
||||
},
|
||||
|
||||
+4
-4
@@ -71,7 +71,7 @@ private fun KotlinType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers
|
||||
val shouldEnhance = position.shouldEnhance()
|
||||
if (!shouldEnhance && getArguments().isEmpty()) return Result(this, 1)
|
||||
|
||||
val originalClass = getConstructor().getDeclarationDescriptor()
|
||||
val originalClass = getConstructor().declarationDescriptor
|
||||
?: return Result(this, 1)
|
||||
|
||||
val effectiveQualifiers = qualifiers(index)
|
||||
@@ -82,12 +82,12 @@ private fun KotlinType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers
|
||||
var globalArgIndex = index + 1
|
||||
val enhancedArguments = getArguments().mapIndexed {
|
||||
localArgIndex, arg ->
|
||||
if (arg.isStarProjection()) {
|
||||
if (arg.isStarProjection) {
|
||||
globalArgIndex++
|
||||
TypeUtils.makeStarProjection(enhancedClassifier.getTypeConstructor().getParameters()[localArgIndex])
|
||||
TypeUtils.makeStarProjection(enhancedClassifier.typeConstructor.parameters[localArgIndex])
|
||||
}
|
||||
else {
|
||||
val (enhancedType, subtreeSize) = arg.getType().enhancePossiblyFlexible(qualifiers, globalArgIndex)
|
||||
val (enhancedType, subtreeSize) = arg.type.enhancePossiblyFlexible(qualifiers, globalArgIndex)
|
||||
globalArgIndex += subtreeSize
|
||||
createProjection(enhancedType, arg.projectionKind, typeParameterDescriptor = typeConstructor.parameters[localArgIndex])
|
||||
}
|
||||
|
||||
+3
-3
@@ -95,11 +95,11 @@ fun KotlinType.computeIndexedQualifiersForOverride(fromSupertypes: Collection<Ko
|
||||
fun add(type: KotlinType) {
|
||||
list.add(type)
|
||||
for (arg in type.getArguments()) {
|
||||
if (arg.isStarProjection()) {
|
||||
list.add(arg.getType())
|
||||
if (arg.isStarProjection) {
|
||||
list.add(arg.type)
|
||||
}
|
||||
else {
|
||||
add(arg.getType())
|
||||
add(arg.type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import java.util.*
|
||||
|
||||
public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any, T : Any>(
|
||||
abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any, T : Any>(
|
||||
storageManager: StorageManager,
|
||||
private val kotlinClassFinder: KotlinClassFinder,
|
||||
private val errorReporter: ErrorReporter
|
||||
@@ -322,7 +322,7 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
|
||||
}
|
||||
|
||||
private class Storage<A, C>(
|
||||
public val memberAnnotations: Map<MemberSignature, List<A>>,
|
||||
public val propertyConstants: Map<MemberSignature, C>
|
||||
val memberAnnotations: Map<MemberSignature, List<A>>,
|
||||
val propertyConstants: Map<MemberSignature, C>
|
||||
)
|
||||
}
|
||||
|
||||
+5
-5
@@ -39,7 +39,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import java.util.*
|
||||
|
||||
public class BinaryClassAnnotationAndConstantLoaderImpl(
|
||||
class BinaryClassAnnotationAndConstantLoaderImpl(
|
||||
private val module: ModuleDescriptor,
|
||||
storageManager: StorageManager,
|
||||
kotlinClassFinder: KotlinClassFinder,
|
||||
@@ -131,7 +131,7 @@ public class BinaryClassAnnotationAndConstantLoaderImpl(
|
||||
val parameter = DescriptorResolverUtils.getAnnotationParameterByName(name, annotationClass)
|
||||
if (parameter != null) {
|
||||
elements.trimToSize()
|
||||
arguments[parameter] = factory.createArrayValue(elements, parameter.getType())
|
||||
arguments[parameter] = factory.createArrayValue(elements, parameter.type)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,8 +151,8 @@ public class BinaryClassAnnotationAndConstantLoaderImpl(
|
||||
// NOTE: see analogous code in AnnotationDeserializer
|
||||
private fun enumEntryValue(enumClassId: ClassId, name: Name): ConstantValue<*> {
|
||||
val enumClass = resolveClass(enumClassId)
|
||||
if (enumClass.getKind() == ClassKind.ENUM_CLASS) {
|
||||
val classifier = enumClass.getUnsubstitutedInnerClassesScope().getContributedClassifier(name, NoLookupLocation.FROM_JAVA_LOADER)
|
||||
if (enumClass.kind == ClassKind.ENUM_CLASS) {
|
||||
val classifier = enumClass.unsubstitutedInnerClassesScope.getContributedClassifier(name, NoLookupLocation.FROM_JAVA_LOADER)
|
||||
if (classifier is ClassDescriptor) {
|
||||
return factory.createEnumValue(classifier)
|
||||
}
|
||||
@@ -161,7 +161,7 @@ public class BinaryClassAnnotationAndConstantLoaderImpl(
|
||||
}
|
||||
|
||||
override fun visitEnd() {
|
||||
result.add(AnnotationDescriptorImpl(annotationClass.getDefaultType(), arguments, source))
|
||||
result.add(AnnotationDescriptorImpl(annotationClass.defaultType, arguments, source))
|
||||
}
|
||||
|
||||
private fun createConstant(name: Name?, value: Any?): ConstantValue<*> {
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
// This class is needed only for easier injection: exact types of needed components are specified in the constructor here.
|
||||
// Otherwise injector generator is not smart enough to deduce, for example, which package fragment provider DeserializationComponents needs
|
||||
public class DeserializationComponentsForJava(
|
||||
class DeserializationComponentsForJava(
|
||||
storageManager: StorageManager,
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
classDataFinder: JavaClassDataFinder,
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.serialization.ClassDataWithSource
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ClassDataFinder
|
||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil
|
||||
|
||||
public class JavaClassDataFinder(
|
||||
class JavaClassDataFinder(
|
||||
private val kotlinClassFinder: KotlinClassFinder,
|
||||
private val deserializedDescriptorResolver: DeserializedDescriptorResolver
|
||||
) : ClassDataFinder {
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.serialization.deserialization.TypeCapabilitiesLoader
|
||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
|
||||
import org.jetbrains.kotlin.types.TypeCapabilities
|
||||
|
||||
public object JavaTypeCapabilitiesLoader : TypeCapabilitiesLoader() {
|
||||
object JavaTypeCapabilitiesLoader : TypeCapabilitiesLoader() {
|
||||
override fun loadCapabilities(type: ProtoBuf.Type): TypeCapabilities =
|
||||
if (type.hasExtension(JvmProtoBuf.isRaw)) RawTypeCapabilities else TypeCapabilities.NONE
|
||||
}
|
||||
|
||||
+3
-3
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.load.kotlin
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
public interface KotlinClassFinder {
|
||||
public fun findKotlinClass(classId: ClassId): KotlinJvmBinaryClass?
|
||||
interface KotlinClassFinder {
|
||||
fun findKotlinClass(classId: ClassId): KotlinJvmBinaryClass?
|
||||
|
||||
public fun findKotlinClass(javaClass: JavaClass): KotlinJvmBinaryClass?
|
||||
fun findKotlinClass(javaClass: JavaClass): KotlinJvmBinaryClass?
|
||||
}
|
||||
|
||||
+2
-2
@@ -37,11 +37,11 @@ class KotlinJvmBinaryPackageSourceElement(
|
||||
override fun toString(): String = "Binary package ${jPackage.getFqName()}: ${implClassNameToBinaryClass.keys}"
|
||||
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
|
||||
|
||||
public fun getRepresentativeBinaryClass(): KotlinJvmBinaryClass {
|
||||
fun getRepresentativeBinaryClass(): KotlinJvmBinaryClass {
|
||||
return implClassNameToBinaryClass.values.first()
|
||||
}
|
||||
|
||||
public fun getContainingBinaryClass(descriptor: DeserializedCallableMemberDescriptor): KotlinJvmBinaryClass? {
|
||||
fun getContainingBinaryClass(descriptor: DeserializedCallableMemberDescriptor): KotlinJvmBinaryClass? {
|
||||
val name = descriptor.getImplClassNameForDeserialized() ?: return null
|
||||
return implClassNameToBinaryClass[name.asString()]
|
||||
}
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.load.kotlin
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.descriptors.SourceFile
|
||||
|
||||
public class KotlinJvmBinarySourceElement(public val binaryClass: KotlinJvmBinaryClass) : SourceElement {
|
||||
class KotlinJvmBinarySourceElement(val binaryClass: KotlinJvmBinaryClass) : SourceElement {
|
||||
override fun toString() = javaClass.name + ": " + binaryClass.toString()
|
||||
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
|
||||
}
|
||||
|
||||
@@ -22,18 +22,16 @@ import org.jetbrains.kotlin.serialization.jvm.JvmPackageTable
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.DataInputStream
|
||||
|
||||
public class ModuleMapping private constructor(val packageFqName2Parts: Map<String, PackageParts>) {
|
||||
class ModuleMapping private constructor(val packageFqName2Parts: Map<String, PackageParts>) {
|
||||
|
||||
fun findPackageParts(packageFqName: String): PackageParts? {
|
||||
return packageFqName2Parts[packageFqName]
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
public val MAPPING_FILE_EXT: String = "kotlin_module"
|
||||
@JvmField val MAPPING_FILE_EXT: String = "kotlin_module"
|
||||
|
||||
@JvmField
|
||||
public val EMPTY: ModuleMapping = ModuleMapping(emptyMap())
|
||||
@JvmField val EMPTY: ModuleMapping = ModuleMapping(emptyMap())
|
||||
|
||||
fun create(proto: ByteArray? = null): ModuleMapping {
|
||||
if (proto == null) {
|
||||
@@ -68,7 +66,7 @@ public class ModuleMapping private constructor(val packageFqName2Parts: Map<Stri
|
||||
}
|
||||
}
|
||||
|
||||
public class PackageParts(val packageFqName: String) {
|
||||
class PackageParts(val packageFqName: String) {
|
||||
|
||||
val parts = linkedSetOf<String>()
|
||||
|
||||
@@ -79,8 +77,7 @@ public class PackageParts(val packageFqName: String) {
|
||||
packageFqName.hashCode() * 31 + parts.hashCode()
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
public fun PackageParts.serialize(builder: JvmPackageTable.PackageTable.Builder) {
|
||||
@JvmStatic fun PackageParts.serialize(builder: JvmPackageTable.PackageTable.Builder) {
|
||||
if (this.parts.isNotEmpty()) {
|
||||
val packageParts = JvmPackageTable.PackageParts.newBuilder()
|
||||
packageParts.setPackageFqName(this.packageFqName)
|
||||
|
||||
+6
-10
@@ -25,31 +25,27 @@ import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||
import java.io.ByteArrayInputStream
|
||||
|
||||
public object JvmProtoBufUtil {
|
||||
public val EXTENSION_REGISTRY: ExtensionRegistryLite = run {
|
||||
object JvmProtoBufUtil {
|
||||
val EXTENSION_REGISTRY: ExtensionRegistryLite = run {
|
||||
val registry = ExtensionRegistryLite.newInstance()
|
||||
JvmProtoBuf.registerAllExtensions(registry)
|
||||
registry
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
public fun readClassDataFrom(data: Array<String>, strings: Array<String>): ClassData =
|
||||
@JvmStatic fun readClassDataFrom(data: Array<String>, strings: Array<String>): ClassData =
|
||||
readClassDataFrom(BitEncoding.decodeBytes(data), strings)
|
||||
|
||||
@JvmStatic
|
||||
public fun readClassDataFrom(bytes: ByteArray, strings: Array<String>): ClassData {
|
||||
@JvmStatic fun readClassDataFrom(bytes: ByteArray, strings: Array<String>): ClassData {
|
||||
val input = ByteArrayInputStream(bytes)
|
||||
val nameResolver = JvmNameResolver(JvmProtoBuf.StringTableTypes.parseDelimitedFrom(input, EXTENSION_REGISTRY), strings)
|
||||
val classProto = ProtoBuf.Class.parseFrom(input, EXTENSION_REGISTRY)
|
||||
return ClassData(nameResolver, classProto)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
public fun readPackageDataFrom(data: Array<String>, strings: Array<String>): PackageData =
|
||||
@JvmStatic fun readPackageDataFrom(data: Array<String>, strings: Array<String>): PackageData =
|
||||
readPackageDataFrom(BitEncoding.decodeBytes(data), strings)
|
||||
|
||||
@JvmStatic
|
||||
public fun readPackageDataFrom(bytes: ByteArray, strings: Array<String>): PackageData {
|
||||
@JvmStatic fun readPackageDataFrom(bytes: ByteArray, strings: Array<String>): PackageData {
|
||||
val input = ByteArrayInputStream(bytes)
|
||||
val nameResolver = JvmNameResolver(JvmProtoBuf.StringTableTypes.parseDelimitedFrom(input, EXTENSION_REGISTRY), strings)
|
||||
val packageProto = ProtoBuf.Package.parseFrom(input, EXTENSION_REGISTRY)
|
||||
|
||||
+3
-3
@@ -23,10 +23,10 @@ import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ErrorReporter
|
||||
|
||||
public object RuntimeErrorReporter : ErrorReporter {
|
||||
object RuntimeErrorReporter : ErrorReporter {
|
||||
// TODO: specialized exceptions
|
||||
override fun reportIncompleteHierarchy(descriptor: ClassDescriptor, unresolvedSuperClasses: MutableList<String>) {
|
||||
throw IllegalStateException("Incomplete hierarchy for class ${descriptor.getName()}, unresolved classes $unresolvedSuperClasses")
|
||||
throw IllegalStateException("Incomplete hierarchy for class ${descriptor.name}, unresolved classes $unresolvedSuperClasses")
|
||||
}
|
||||
|
||||
override fun reportIncompatibleAbiVersion(classId: ClassId, filePath: String, actualVersion: BinaryVersion) {
|
||||
@@ -36,7 +36,7 @@ public object RuntimeErrorReporter : ErrorReporter {
|
||||
|
||||
override fun reportCannotInferVisibility(descriptor: CallableMemberDescriptor) {
|
||||
// TODO: use DescriptorRenderer
|
||||
throw IllegalStateException("Cannot infer visibility for class ${descriptor.getName()}")
|
||||
throw IllegalStateException("Cannot infer visibility for class ${descriptor.name}")
|
||||
}
|
||||
|
||||
override fun reportLoadingError(message: String, exception: Exception?) {
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.load.java.sources.JavaSourceElementFactory
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaElement
|
||||
import org.jetbrains.kotlin.load.java.structure.reflect.ReflectJavaElement
|
||||
|
||||
public object RuntimeSourceElementFactory : JavaSourceElementFactory {
|
||||
object RuntimeSourceElementFactory : JavaSourceElementFactory {
|
||||
private class RuntimeSourceElement(override val javaElement: ReflectJavaElement) : JavaSourceElement {
|
||||
override fun toString() = javaClass.name + ": " + javaElement.toString()
|
||||
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
|
||||
|
||||
+4
-4
@@ -24,12 +24,12 @@ import org.jetbrains.kotlin.load.java.structure.reflect.ReflectJavaClass
|
||||
import org.jetbrains.kotlin.load.java.structure.reflect.ReflectJavaPackage
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
public class ReflectJavaClassFinder(private val classLoader: ClassLoader) : JavaClassFinder {
|
||||
class ReflectJavaClassFinder(private val classLoader: ClassLoader) : JavaClassFinder {
|
||||
override fun findClass(classId: ClassId): JavaClass? {
|
||||
val packageFqName = classId.getPackageFqName()
|
||||
val relativeClassName = classId.getRelativeClassName().asString().replace('.', '$')
|
||||
val packageFqName = classId.packageFqName
|
||||
val relativeClassName = classId.relativeClassName.asString().replace('.', '$')
|
||||
val name =
|
||||
if (packageFqName.isRoot()) relativeClassName
|
||||
if (packageFqName.isRoot) relativeClassName
|
||||
else packageFqName.asString() + "." + relativeClassName
|
||||
|
||||
val klass = classLoader.tryLoadClass(name)
|
||||
|
||||
+4
-4
@@ -21,17 +21,17 @@ import org.jetbrains.kotlin.load.java.structure.JavaAnnotationArgument
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import java.lang.reflect.Method
|
||||
|
||||
public class ReflectJavaAnnotation(private val annotation: Annotation) : ReflectJavaElement(), JavaAnnotation {
|
||||
class ReflectJavaAnnotation(private val annotation: Annotation) : ReflectJavaElement(), JavaAnnotation {
|
||||
override fun findArgument(name: Name): JavaAnnotationArgument? {
|
||||
return getArgumentValue(annotation.annotationClass.java.getDeclaredMethod(name.asString()))
|
||||
}
|
||||
|
||||
override fun getArguments(): Collection<JavaAnnotationArgument> {
|
||||
return annotation.annotationClass.java.getDeclaredMethods().map { getArgumentValue(it) }
|
||||
return annotation.annotationClass.java.declaredMethods.map { getArgumentValue(it) }
|
||||
}
|
||||
|
||||
private fun getArgumentValue(argument: Method): ReflectJavaAnnotationArgument {
|
||||
return argument.invoke(annotation).let { ReflectJavaAnnotationArgument.create(it, Name.identifier(argument.getName())) }
|
||||
return argument.invoke(annotation).let { ReflectJavaAnnotationArgument.create(it, Name.identifier(argument.name)) }
|
||||
}
|
||||
|
||||
override fun resolve() = ReflectJavaClass(annotation.annotationClass.java)
|
||||
@@ -42,5 +42,5 @@ public class ReflectJavaAnnotation(private val annotation: Annotation) : Reflect
|
||||
|
||||
override fun hashCode() = annotation.hashCode()
|
||||
|
||||
override fun toString() = javaClass.getName() + ": " + annotation
|
||||
override fun toString() = javaClass.name + ": " + annotation
|
||||
}
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ class ReflectJavaEnumValueAnnotationArgument(
|
||||
) : ReflectJavaAnnotationArgument(name), JavaEnumValueAnnotationArgument {
|
||||
override fun resolve(): ReflectJavaField {
|
||||
val clazz = value.javaClass
|
||||
val enumClass = if (clazz.isEnum()) clazz else clazz.getEnclosingClass()
|
||||
val enumClass = if (clazz.isEnum) clazz else clazz.enclosingClass
|
||||
return ReflectJavaField(enumClass.getDeclaredField(value.name))
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -20,12 +20,12 @@ import org.jetbrains.kotlin.load.java.structure.JavaAnnotationOwner
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import java.lang.reflect.AnnotatedElement
|
||||
|
||||
public interface ReflectJavaAnnotationOwner : JavaAnnotationOwner {
|
||||
interface ReflectJavaAnnotationOwner : JavaAnnotationOwner {
|
||||
val element: AnnotatedElement
|
||||
|
||||
override fun getAnnotations() = getAnnotations(element.getDeclaredAnnotations())
|
||||
override fun getAnnotations() = getAnnotations(element.declaredAnnotations)
|
||||
|
||||
override fun findAnnotation(fqName: FqName) = findAnnotation(element.getDeclaredAnnotations(), fqName)
|
||||
override fun findAnnotation(fqName: FqName) = findAnnotation(element.declaredAnnotations, fqName)
|
||||
|
||||
override fun isDeprecatedInJavaDoc() = false
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,10 +20,10 @@ import org.jetbrains.kotlin.load.java.structure.JavaArrayType
|
||||
import java.lang.reflect.GenericArrayType
|
||||
import java.lang.reflect.Type
|
||||
|
||||
public class ReflectJavaArrayType(override val type: Type) : ReflectJavaType(), JavaArrayType {
|
||||
class ReflectJavaArrayType(override val type: Type) : ReflectJavaType(), JavaArrayType {
|
||||
private val componentType: ReflectJavaType = with (type) {
|
||||
when {
|
||||
this is GenericArrayType -> ReflectJavaType.create(getGenericComponentType())
|
||||
this is GenericArrayType -> ReflectJavaType.create(genericComponentType)
|
||||
this is Class<*> && isArray() -> ReflectJavaType.create(getComponentType())
|
||||
else -> throw IllegalArgumentException("Not an array type (${type.javaClass}): $type")
|
||||
}
|
||||
|
||||
+21
-21
@@ -24,39 +24,39 @@ import org.jetbrains.kotlin.name.Name
|
||||
import java.lang.reflect.Method
|
||||
import java.util.Arrays
|
||||
|
||||
public class ReflectJavaClass(
|
||||
class ReflectJavaClass(
|
||||
private val klass: Class<*>
|
||||
) : ReflectJavaElement(), ReflectJavaAnnotationOwner, ReflectJavaModifierListOwner, JavaClass {
|
||||
override val element: Class<*> get() = klass
|
||||
|
||||
override val modifiers: Int get() = klass.getModifiers()
|
||||
override val modifiers: Int get() = klass.modifiers
|
||||
|
||||
override fun getInnerClasses() = klass.getDeclaredClasses()
|
||||
override fun getInnerClasses() = klass.declaredClasses
|
||||
.asSequence()
|
||||
.filterNot {
|
||||
// getDeclaredClasses() returns anonymous classes sometimes, for example enums with specialized entries (which are in fact
|
||||
// anonymous classes) or in case of a special anonymous class created for the synthetic accessor to a private nested class
|
||||
// constructor accessed from the outer class
|
||||
it.getSimpleName().isEmpty()
|
||||
it.simpleName.isEmpty()
|
||||
}
|
||||
.map(::ReflectJavaClass)
|
||||
.toList()
|
||||
|
||||
override fun getFqName() = klass.classId.asSingleFqName()
|
||||
|
||||
override fun getOuterClass() = klass.getDeclaringClass()?.let(::ReflectJavaClass)
|
||||
override fun getOuterClass() = klass.declaringClass?.let(::ReflectJavaClass)
|
||||
|
||||
override fun getSupertypes(): Collection<JavaClassifierType> {
|
||||
if (klass == Any::class.java) return emptyList()
|
||||
return listOf(klass.genericSuperclass ?: Any::class.java, *klass.genericInterfaces).map(::ReflectJavaClassifierType)
|
||||
}
|
||||
|
||||
override fun getMethods() = klass.getDeclaredMethods()
|
||||
override fun getMethods() = klass.declaredMethods
|
||||
.asSequence()
|
||||
.filter { method ->
|
||||
when {
|
||||
method.isSynthetic() -> false
|
||||
isEnum() -> !isEnumValuesOrValueOf(method)
|
||||
method.isSynthetic -> false
|
||||
isEnum -> !isEnumValuesOrValueOf(method)
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
@@ -64,22 +64,22 @@ public class ReflectJavaClass(
|
||||
.toList()
|
||||
|
||||
private fun isEnumValuesOrValueOf(method: Method): Boolean {
|
||||
return when (method.getName()) {
|
||||
"values" -> method.getParameterTypes().isEmpty()
|
||||
"valueOf" -> Arrays.equals(method.getParameterTypes(), arrayOf(String::class.java))
|
||||
return when (method.name) {
|
||||
"values" -> method.parameterTypes.isEmpty()
|
||||
"valueOf" -> Arrays.equals(method.parameterTypes, arrayOf(String::class.java))
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
override fun getFields() = klass.getDeclaredFields()
|
||||
override fun getFields() = klass.declaredFields
|
||||
.asSequence()
|
||||
.filter { field -> !field.isSynthetic() }
|
||||
.filter { field -> !field.isSynthetic }
|
||||
.map(::ReflectJavaField)
|
||||
.toList()
|
||||
|
||||
override fun getConstructors() = klass.getDeclaredConstructors()
|
||||
override fun getConstructors() = klass.declaredConstructors
|
||||
.asSequence()
|
||||
.filter { constructor -> !constructor.isSynthetic() }
|
||||
.filter { constructor -> !constructor.isSynthetic }
|
||||
.map(::ReflectJavaConstructor)
|
||||
.toList()
|
||||
|
||||
@@ -90,17 +90,17 @@ public class ReflectJavaClass(
|
||||
|
||||
override fun createImmediateType(substitutor: JavaTypeSubstitutor): JavaType = throw UnsupportedOperationException()
|
||||
|
||||
override fun getName(): Name = Name.identifier(klass.getSimpleName())
|
||||
override fun getName(): Name = Name.identifier(klass.simpleName)
|
||||
|
||||
override fun getTypeParameters() = klass.getTypeParameters().map { ReflectJavaTypeParameter(it) }
|
||||
override fun getTypeParameters() = klass.typeParameters.map { ReflectJavaTypeParameter(it) }
|
||||
|
||||
override fun isInterface() = klass.isInterface()
|
||||
override fun isAnnotationType() = klass.isAnnotation()
|
||||
override fun isEnum() = klass.isEnum()
|
||||
override fun isInterface() = klass.isInterface
|
||||
override fun isAnnotationType() = klass.isAnnotation
|
||||
override fun isEnum() = klass.isEnum
|
||||
|
||||
override fun equals(other: Any?) = other is ReflectJavaClass && klass == other.klass
|
||||
|
||||
override fun hashCode() = klass.hashCode()
|
||||
|
||||
override fun toString() = javaClass.getName() + ": " + klass
|
||||
override fun toString() = javaClass.name + ": " + klass
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,13 +22,13 @@ import java.lang.reflect.ParameterizedType
|
||||
import java.lang.reflect.Type
|
||||
import java.lang.reflect.TypeVariable
|
||||
|
||||
public class ReflectJavaClassifierType(public override val type: Type) : ReflectJavaType(), JavaClassifierType {
|
||||
class ReflectJavaClassifierType(public override val type: Type) : ReflectJavaType(), JavaClassifierType {
|
||||
private val classifier: JavaClassifier = run {
|
||||
val type = type
|
||||
val classifier: JavaClassifier = when (type) {
|
||||
is Class<*> -> ReflectJavaClass(type)
|
||||
is TypeVariable<*> -> ReflectJavaTypeParameter(type)
|
||||
is ParameterizedType -> ReflectJavaClass(type.getRawType() as Class<*>)
|
||||
is ParameterizedType -> ReflectJavaClass(type.rawType as Class<*>)
|
||||
else -> throw IllegalStateException("Not a classifier type (${type.javaClass}): $type")
|
||||
}
|
||||
classifier
|
||||
|
||||
+6
-6
@@ -22,27 +22,27 @@ import org.jetbrains.kotlin.load.java.structure.JavaValueParameter
|
||||
import java.lang.reflect.Constructor
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
public class ReflectJavaConstructor(override val member: Constructor<*>) : ReflectJavaMember(), JavaConstructor {
|
||||
class ReflectJavaConstructor(override val member: Constructor<*>) : ReflectJavaMember(), JavaConstructor {
|
||||
// TODO: test local/anonymous classes
|
||||
override fun getValueParameters(): List<JavaValueParameter> {
|
||||
val types = member.getGenericParameterTypes()
|
||||
val types = member.genericParameterTypes
|
||||
if (types.isEmpty()) return emptyList()
|
||||
|
||||
val klass = member.getDeclaringClass()
|
||||
val klass = member.declaringClass
|
||||
|
||||
val realTypes = when {
|
||||
klass.getDeclaringClass() != null && !Modifier.isStatic(klass.getModifiers()) -> types.copyOfRange(1, types.size)
|
||||
klass.declaringClass != null && !Modifier.isStatic(klass.modifiers) -> types.copyOfRange(1, types.size)
|
||||
else -> types
|
||||
}
|
||||
|
||||
val annotations = member.getParameterAnnotations()
|
||||
val annotations = member.parameterAnnotations
|
||||
val realAnnotations = when {
|
||||
annotations.size < realTypes.size -> throw IllegalStateException("Illegal generic signature: $member")
|
||||
annotations.size > realTypes.size -> annotations.copyOfRange(annotations.size - realTypes.size, annotations.size)
|
||||
else -> annotations
|
||||
}
|
||||
|
||||
return getValueParameters(realTypes, realAnnotations, member.isVarArgs())
|
||||
return getValueParameters(realTypes, realAnnotations, member.isVarArgs)
|
||||
}
|
||||
|
||||
override fun getTypeParameters(): List<JavaTypeParameter> {
|
||||
|
||||
+1
-1
@@ -18,4 +18,4 @@ package org.jetbrains.kotlin.load.java.structure.reflect
|
||||
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaElement
|
||||
|
||||
public abstract class ReflectJavaElement : JavaElement
|
||||
abstract class ReflectJavaElement : JavaElement
|
||||
|
||||
+3
-3
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.load.java.structure.reflect
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaField
|
||||
import java.lang.reflect.Field
|
||||
|
||||
public class ReflectJavaField(override val member: Field) : ReflectJavaMember(), JavaField {
|
||||
override fun isEnumEntry() = member.isEnumConstant()
|
||||
class ReflectJavaField(override val member: Field) : ReflectJavaMember(), JavaField {
|
||||
override fun isEnumEntry() = member.isEnumConstant
|
||||
|
||||
override fun getType() = ReflectJavaType.create(member.getGenericType())
|
||||
override fun getType() = ReflectJavaType.create(member.genericType)
|
||||
}
|
||||
|
||||
+6
-6
@@ -26,16 +26,16 @@ import java.lang.reflect.Method
|
||||
import java.lang.reflect.Type
|
||||
import java.util.*
|
||||
|
||||
public abstract class ReflectJavaMember : ReflectJavaElement(), ReflectJavaAnnotationOwner, ReflectJavaModifierListOwner, JavaMember {
|
||||
public abstract val member: Member
|
||||
abstract class ReflectJavaMember : ReflectJavaElement(), ReflectJavaAnnotationOwner, ReflectJavaModifierListOwner, JavaMember {
|
||||
abstract val member: Member
|
||||
|
||||
override val element: AnnotatedElement get() = member as AnnotatedElement
|
||||
|
||||
override val modifiers: Int get() = member.getModifiers()
|
||||
override val modifiers: Int get() = member.modifiers
|
||||
|
||||
override fun getName() = member.getName()?.let { Name.identifier(it) } ?: SpecialNames.NO_NAME_PROVIDED
|
||||
override fun getName() = member.name?.let { Name.identifier(it) } ?: SpecialNames.NO_NAME_PROVIDED
|
||||
|
||||
override fun getContainingClass() = ReflectJavaClass(member.getDeclaringClass())
|
||||
override fun getContainingClass() = ReflectJavaClass(member.declaringClass)
|
||||
|
||||
protected fun getValueParameters(
|
||||
parameterTypes: Array<Type>,
|
||||
@@ -57,7 +57,7 @@ public abstract class ReflectJavaMember : ReflectJavaElement(), ReflectJavaAnnot
|
||||
|
||||
override fun hashCode() = member.hashCode()
|
||||
|
||||
override fun toString() = javaClass.getName() + ": " + member
|
||||
override fun toString() = javaClass.name + ": " + member
|
||||
}
|
||||
|
||||
private object Java8ParameterNamesLoader {
|
||||
|
||||
+5
-5
@@ -20,13 +20,13 @@ import org.jetbrains.kotlin.load.java.structure.JavaMethod
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaValueParameter
|
||||
import java.lang.reflect.Method
|
||||
|
||||
public class ReflectJavaMethod(override val member: Method) : ReflectJavaMember(), JavaMethod {
|
||||
class ReflectJavaMethod(override val member: Method) : ReflectJavaMember(), JavaMethod {
|
||||
override fun getValueParameters(): List<JavaValueParameter> =
|
||||
getValueParameters(member.getGenericParameterTypes(), member.getParameterAnnotations(), member.isVarArgs())
|
||||
getValueParameters(member.genericParameterTypes, member.parameterAnnotations, member.isVarArgs)
|
||||
|
||||
override fun getReturnType() = ReflectJavaType.create(member.getGenericReturnType())
|
||||
override fun getReturnType() = ReflectJavaType.create(member.genericReturnType)
|
||||
|
||||
override fun hasAnnotationParameterDefaultValue() = member.getDefaultValue() != null
|
||||
override fun hasAnnotationParameterDefaultValue() = member.defaultValue != null
|
||||
|
||||
override fun getTypeParameters() = member.getTypeParameters().map { ReflectJavaTypeParameter(it) }
|
||||
override fun getTypeParameters() = member.typeParameters.map { ReflectJavaTypeParameter(it) }
|
||||
}
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.load.java.JavaVisibilities
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaModifierListOwner
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
public interface ReflectJavaModifierListOwner : JavaModifierListOwner {
|
||||
interface ReflectJavaModifierListOwner : JavaModifierListOwner {
|
||||
/* protected // KT-3029 */ val modifiers: Int
|
||||
|
||||
override fun isAbstract() = Modifier.isAbstract(modifiers)
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.load.java.structure.JavaPackage
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
public class ReflectJavaPackage(private val fqName: FqName) : ReflectJavaElement(), JavaPackage {
|
||||
class ReflectJavaPackage(private val fqName: FqName) : ReflectJavaElement(), JavaPackage {
|
||||
override fun getFqName() = fqName
|
||||
|
||||
override fun getClasses(nameFilter: (Name) -> Boolean): Collection<JavaClass> {
|
||||
@@ -38,5 +38,5 @@ public class ReflectJavaPackage(private val fqName: FqName) : ReflectJavaElement
|
||||
|
||||
override fun hashCode() = fqName.hashCode()
|
||||
|
||||
override fun toString() = javaClass.getName() + ": " + fqName
|
||||
override fun toString() = javaClass.name + ": " + fqName
|
||||
}
|
||||
|
||||
+2
-2
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.load.java.structure.reflect
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaPrimitiveType
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
||||
|
||||
public class ReflectJavaPrimitiveType(override val type: Class<*>) : ReflectJavaType(), JavaPrimitiveType {
|
||||
class ReflectJavaPrimitiveType(override val type: Class<*>) : ReflectJavaType(), JavaPrimitiveType {
|
||||
override fun getType() =
|
||||
if (type == Void.TYPE) null
|
||||
else JvmPrimitiveType.get(type.getName()).getPrimitiveType()
|
||||
else JvmPrimitiveType.get(type.name).primitiveType
|
||||
}
|
||||
|
||||
+4
-4
@@ -22,7 +22,7 @@ import java.lang.reflect.GenericArrayType
|
||||
import java.lang.reflect.Type
|
||||
import java.lang.reflect.WildcardType
|
||||
|
||||
public abstract class ReflectJavaType : JavaType {
|
||||
abstract class ReflectJavaType : JavaType {
|
||||
protected abstract val type: Type
|
||||
|
||||
override fun createArrayType(): JavaArrayType = throw UnsupportedOperationException()
|
||||
@@ -30,8 +30,8 @@ public abstract class ReflectJavaType : JavaType {
|
||||
companion object Factory {
|
||||
fun create(type: Type): ReflectJavaType {
|
||||
return when {
|
||||
type is Class<*> && type.isPrimitive() -> ReflectJavaPrimitiveType(type)
|
||||
type is GenericArrayType || type is Class<*> && type.isArray() -> ReflectJavaArrayType(type)
|
||||
type is Class<*> && type.isPrimitive -> ReflectJavaPrimitiveType(type)
|
||||
type is GenericArrayType || type is Class<*> && type.isArray -> ReflectJavaArrayType(type)
|
||||
type is WildcardType -> ReflectJavaWildcardType(type)
|
||||
else -> ReflectJavaClassifierType(type)
|
||||
}
|
||||
@@ -42,5 +42,5 @@ public abstract class ReflectJavaType : JavaType {
|
||||
|
||||
override fun hashCode() = type.hashCode()
|
||||
|
||||
override fun toString() = javaClass.getName() + ": " + type
|
||||
override fun toString() = javaClass.name + ": " + type
|
||||
}
|
||||
|
||||
+6
-6
@@ -25,17 +25,17 @@ import java.lang.reflect.Constructor
|
||||
import java.lang.reflect.Method
|
||||
import java.lang.reflect.TypeVariable
|
||||
|
||||
public class ReflectJavaTypeParameter(
|
||||
public val typeVariable: TypeVariable<*>
|
||||
class ReflectJavaTypeParameter(
|
||||
val typeVariable: TypeVariable<*>
|
||||
) : ReflectJavaElement(), JavaTypeParameter {
|
||||
override fun getUpperBounds(): List<ReflectJavaClassifierType> {
|
||||
val bounds = typeVariable.getBounds().map { bound -> ReflectJavaClassifierType(bound) }
|
||||
val bounds = typeVariable.bounds.map { bound -> ReflectJavaClassifierType(bound) }
|
||||
if (bounds.singleOrNull()?.type == Any::class.java) return emptyList()
|
||||
return bounds
|
||||
}
|
||||
|
||||
override fun getOwner(): JavaTypeParameterListOwner? {
|
||||
val owner = typeVariable.getGenericDeclaration()
|
||||
val owner = typeVariable.genericDeclaration
|
||||
return when (owner) {
|
||||
is Class<*> -> ReflectJavaClass(owner)
|
||||
is Method -> ReflectJavaMethod(owner)
|
||||
@@ -48,11 +48,11 @@ public class ReflectJavaTypeParameter(
|
||||
|
||||
override fun getTypeProvider(): JavaTypeProvider = throw UnsupportedOperationException()
|
||||
|
||||
override fun getName() = Name.identifier(typeVariable.getName())
|
||||
override fun getName() = Name.identifier(typeVariable.name)
|
||||
|
||||
override fun equals(other: Any?) = other is ReflectJavaTypeParameter && typeVariable == other.typeVariable
|
||||
|
||||
override fun hashCode() = typeVariable.hashCode()
|
||||
|
||||
override fun toString() = javaClass.getName() + ": " + typeVariable
|
||||
override fun toString() = javaClass.name + ": " + typeVariable
|
||||
}
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.Name.guess
|
||||
|
||||
public class ReflectJavaValueParameter(
|
||||
class ReflectJavaValueParameter(
|
||||
private val returnType: ReflectJavaType,
|
||||
private val annotations: Array<Annotation>,
|
||||
private val name: String?,
|
||||
@@ -37,5 +37,5 @@ public class ReflectJavaValueParameter(
|
||||
override fun getType() = returnType
|
||||
override fun isVararg() = isVararg
|
||||
|
||||
override fun toString() = javaClass.getName() + ": " + (if (isVararg) "vararg " else "") + getName() + ": " + returnType
|
||||
override fun toString() = javaClass.name + ": " + (if (isVararg) "vararg " else "") + getName() + ": " + returnType
|
||||
}
|
||||
|
||||
+4
-4
@@ -20,10 +20,10 @@ import org.jetbrains.kotlin.load.java.structure.JavaTypeProvider
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaWildcardType
|
||||
import java.lang.reflect.WildcardType
|
||||
|
||||
public class ReflectJavaWildcardType(override val type: WildcardType): ReflectJavaType(), JavaWildcardType {
|
||||
class ReflectJavaWildcardType(override val type: WildcardType): ReflectJavaType(), JavaWildcardType {
|
||||
override fun getBound(): ReflectJavaType? {
|
||||
val upperBounds = type.getUpperBounds()
|
||||
val lowerBounds = type.getLowerBounds()
|
||||
val upperBounds = type.upperBounds
|
||||
val lowerBounds = type.lowerBounds
|
||||
if (upperBounds.size > 1 || lowerBounds.size > 1) {
|
||||
throw UnsupportedOperationException("Wildcard types with many bounds are not yet supported: $type")
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class ReflectJavaWildcardType(override val type: WildcardType): ReflectJa
|
||||
}
|
||||
}
|
||||
|
||||
override fun isExtends() = type.getUpperBounds().firstOrNull() != Any::class.java
|
||||
override fun isExtends() = type.upperBounds.firstOrNull() != Any::class.java
|
||||
|
||||
override fun getTypeProvider(): JavaTypeProvider = throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
+11
-11
@@ -21,33 +21,33 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import java.lang.reflect.Array
|
||||
|
||||
public val Class<*>.safeClassLoader: ClassLoader
|
||||
val Class<*>.safeClassLoader: ClassLoader
|
||||
get() = classLoader ?: ClassLoader.getSystemClassLoader()
|
||||
|
||||
public fun Class<*>.isEnumClassOrSpecializedEnumEntryClass(): Boolean =
|
||||
fun Class<*>.isEnumClassOrSpecializedEnumEntryClass(): Boolean =
|
||||
Enum::class.java.isAssignableFrom(this)
|
||||
|
||||
/**
|
||||
* NOTE: does not perform a Java -> Kotlin mapping. If this is not expected, consider using KClassImpl#classId instead
|
||||
*/
|
||||
public val Class<*>.classId: ClassId
|
||||
val Class<*>.classId: ClassId
|
||||
get() = when {
|
||||
isPrimitive() -> throw IllegalArgumentException("Can't compute ClassId for primitive type: $this")
|
||||
isArray() -> throw IllegalArgumentException("Can't compute ClassId for array type: $this")
|
||||
getEnclosingMethod() != null || getEnclosingConstructor() != null || getSimpleName().isEmpty() -> {
|
||||
val fqName = FqName(getName())
|
||||
isPrimitive -> throw IllegalArgumentException("Can't compute ClassId for primitive type: $this")
|
||||
isArray -> throw IllegalArgumentException("Can't compute ClassId for array type: $this")
|
||||
enclosingMethod != null || enclosingConstructor != null || simpleName.isEmpty() -> {
|
||||
val fqName = FqName(name)
|
||||
ClassId(fqName.parent(), FqName.topLevel(fqName.shortName()), /* local = */ true)
|
||||
}
|
||||
else -> getDeclaringClass()?.classId?.createNestedClassId(Name.identifier(getSimpleName())) ?: ClassId.topLevel(FqName(getName()))
|
||||
else -> declaringClass?.classId?.createNestedClassId(Name.identifier(simpleName)) ?: ClassId.topLevel(FqName(name))
|
||||
}
|
||||
|
||||
public val Class<*>.desc: String
|
||||
val Class<*>.desc: String
|
||||
get() {
|
||||
if (this == Void.TYPE) return "V"
|
||||
// This is a clever exploitation of a format returned by Class.getName(): for arrays, it's almost an internal name,
|
||||
// but with '.' instead of '/'
|
||||
return createArrayType().getName().substring(1).replace('.', '/')
|
||||
return createArrayType().name.substring(1).replace('.', '/')
|
||||
}
|
||||
|
||||
public fun Class<*>.createArrayType(): Class<*> =
|
||||
fun Class<*>.createArrayType(): Class<*> =
|
||||
Array.newInstance(this, 0).javaClass
|
||||
|
||||
+1
-1
@@ -19,6 +19,6 @@ package org.jetbrains.kotlin.load.kotlin.reflect
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.descriptors.SourceFile
|
||||
|
||||
public class ReflectAnnotationSource(public val annotation: Annotation) : SourceElement {
|
||||
class ReflectAnnotationSource(val annotation: Annotation) : SourceElement {
|
||||
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
|
||||
}
|
||||
|
||||
+28
-28
@@ -39,21 +39,21 @@ private val TYPES_ELIGIBLE_FOR_SIMPLE_VISIT = setOf<Class<*>>(
|
||||
Class::class.java, String::class.java
|
||||
)
|
||||
|
||||
public class ReflectKotlinClass private constructor(
|
||||
public val klass: Class<*>,
|
||||
class ReflectKotlinClass private constructor(
|
||||
val klass: Class<*>,
|
||||
private val classHeader: KotlinClassHeader
|
||||
) : KotlinJvmBinaryClass {
|
||||
|
||||
companion object Factory {
|
||||
|
||||
public fun create(klass: Class<*>): ReflectKotlinClass? {
|
||||
fun create(klass: Class<*>): ReflectKotlinClass? {
|
||||
val headerReader = ReadKotlinClassHeaderAnnotationVisitor()
|
||||
ReflectClassStructure.loadClassAnnotations(klass, headerReader)
|
||||
return ReflectKotlinClass(klass, headerReader.createHeader() ?: return null)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getLocation() = klass.getName().replace('.', '/') + ".class"
|
||||
override fun getLocation() = klass.name.replace('.', '/') + ".class"
|
||||
|
||||
override fun getClassId() = klass.classId
|
||||
|
||||
@@ -71,12 +71,12 @@ public class ReflectKotlinClass private constructor(
|
||||
|
||||
override fun hashCode() = klass.hashCode()
|
||||
|
||||
override fun toString() = javaClass.getName() + ": " + klass
|
||||
override fun toString() = javaClass.name + ": " + klass
|
||||
}
|
||||
|
||||
private object ReflectClassStructure {
|
||||
fun loadClassAnnotations(klass: Class<*>, visitor: KotlinJvmBinaryClass.AnnotationVisitor) {
|
||||
for (annotation in klass.getDeclaredAnnotations()) {
|
||||
for (annotation in klass.declaredAnnotations) {
|
||||
processAnnotation(visitor, annotation)
|
||||
}
|
||||
visitor.visitEnd()
|
||||
@@ -89,14 +89,14 @@ private object ReflectClassStructure {
|
||||
}
|
||||
|
||||
private fun loadMethodAnnotations(klass: Class<*>, memberVisitor: KotlinJvmBinaryClass.MemberVisitor) {
|
||||
for (method in klass.getDeclaredMethods()) {
|
||||
val visitor = memberVisitor.visitMethod(Name.identifier(method.getName()), SignatureSerializer.methodDesc(method)) ?: continue
|
||||
for (method in klass.declaredMethods) {
|
||||
val visitor = memberVisitor.visitMethod(Name.identifier(method.name), SignatureSerializer.methodDesc(method)) ?: continue
|
||||
|
||||
for (annotation in method.getDeclaredAnnotations()) {
|
||||
for (annotation in method.declaredAnnotations) {
|
||||
processAnnotation(visitor, annotation)
|
||||
}
|
||||
|
||||
for ((parameterIndex, annotations) in method.getParameterAnnotations().withIndex()) {
|
||||
for ((parameterIndex, annotations) in method.parameterAnnotations.withIndex()) {
|
||||
for (annotation in annotations) {
|
||||
val annotationType = annotation.annotationClass.java
|
||||
visitor.visitParameterAnnotation(parameterIndex, annotationType.classId, ReflectAnnotationSource(annotation))?.let {
|
||||
@@ -110,14 +110,14 @@ private object ReflectClassStructure {
|
||||
}
|
||||
|
||||
private fun loadConstructorAnnotations(klass: Class<*>, memberVisitor: KotlinJvmBinaryClass.MemberVisitor) {
|
||||
for (constructor in klass.getDeclaredConstructors()) {
|
||||
for (constructor in klass.declaredConstructors) {
|
||||
val visitor = memberVisitor.visitMethod(Name.special("<init>"), SignatureSerializer.constructorDesc(constructor)) ?: continue
|
||||
|
||||
for (annotation in constructor.getDeclaredAnnotations()) {
|
||||
for (annotation in constructor.declaredAnnotations) {
|
||||
processAnnotation(visitor, annotation)
|
||||
}
|
||||
|
||||
val parameterAnnotations = constructor.getParameterAnnotations()
|
||||
val parameterAnnotations = constructor.parameterAnnotations
|
||||
if (parameterAnnotations.isNotEmpty()) {
|
||||
// Constructors of some classes have additional synthetic parameters:
|
||||
// - inner classes have one parameter, instance of the outer class
|
||||
@@ -125,7 +125,7 @@ private object ReflectClassStructure {
|
||||
// - local/anonymous classes may have many parameters for captured values
|
||||
// At the moment this seems like a working heuristic for computing number of synthetic parameters for Kotlin classes,
|
||||
// although this is wrong and likely to change, see KT-6886
|
||||
val shift = constructor.getParameterTypes().size - parameterAnnotations.size
|
||||
val shift = constructor.parameterTypes.size - parameterAnnotations.size
|
||||
|
||||
for ((parameterIndex, annotations) in parameterAnnotations.withIndex()) {
|
||||
for (annotation in annotations) {
|
||||
@@ -144,10 +144,10 @@ private object ReflectClassStructure {
|
||||
}
|
||||
|
||||
private fun loadFieldAnnotations(klass: Class<*>, memberVisitor: KotlinJvmBinaryClass.MemberVisitor) {
|
||||
for (field in klass.getDeclaredFields()) {
|
||||
val visitor = memberVisitor.visitField(Name.identifier(field.getName()), SignatureSerializer.fieldDesc(field), null) ?: continue
|
||||
for (field in klass.declaredFields) {
|
||||
val visitor = memberVisitor.visitField(Name.identifier(field.name), SignatureSerializer.fieldDesc(field), null) ?: continue
|
||||
|
||||
for (annotation in field.getDeclaredAnnotations()) {
|
||||
for (annotation in field.declaredAnnotations) {
|
||||
processAnnotation(visitor, annotation)
|
||||
}
|
||||
|
||||
@@ -167,8 +167,8 @@ private object ReflectClassStructure {
|
||||
annotation: Annotation,
|
||||
annotationType: Class<*>
|
||||
) {
|
||||
for (method in annotationType.getDeclaredMethods()) {
|
||||
processAnnotationArgumentValue(visitor, Name.identifier(method.getName()), method(annotation)!!)
|
||||
for (method in annotationType.declaredMethods) {
|
||||
processAnnotationArgumentValue(visitor, Name.identifier(method.name), method(annotation)!!)
|
||||
}
|
||||
visitor.visitEnd()
|
||||
}
|
||||
@@ -181,18 +181,18 @@ private object ReflectClassStructure {
|
||||
}
|
||||
clazz.isEnumClassOrSpecializedEnumEntryClass() -> {
|
||||
// isEnum returns false for specialized enum constants (enum entries which are anonymous enum subclasses)
|
||||
val classId = (if (clazz.isEnum()) clazz else clazz.getEnclosingClass()).classId
|
||||
val classId = (if (clazz.isEnum) clazz else clazz.enclosingClass).classId
|
||||
visitor.visitEnum(name, classId, Name.identifier((value as Enum<*>).name))
|
||||
}
|
||||
Annotation::class.java.isAssignableFrom(clazz) -> {
|
||||
val annotationClass = clazz.getInterfaces().single()
|
||||
val annotationClass = clazz.interfaces.single()
|
||||
val v = visitor.visitAnnotation(name, annotationClass.classId) ?: return
|
||||
processAnnotationArguments(v, value as Annotation, annotationClass)
|
||||
}
|
||||
clazz.isArray() -> {
|
||||
clazz.isArray -> {
|
||||
val v = visitor.visitArray(name) ?: return
|
||||
val componentType = clazz.getComponentType()
|
||||
if (componentType.isEnum()) {
|
||||
val componentType = clazz.componentType
|
||||
if (componentType.isEnum) {
|
||||
val enumClassId = componentType.classId
|
||||
for (element in value as Array<*>) {
|
||||
v.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name))
|
||||
@@ -216,18 +216,18 @@ private object SignatureSerializer {
|
||||
fun methodDesc(method: Method): String {
|
||||
val sb = StringBuilder()
|
||||
sb.append("(")
|
||||
for (parameterType in method.getParameterTypes()) {
|
||||
for (parameterType in method.parameterTypes) {
|
||||
sb.append(parameterType.desc)
|
||||
}
|
||||
sb.append(")")
|
||||
sb.append(method.getReturnType().desc)
|
||||
sb.append(method.returnType.desc)
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
fun constructorDesc(constructor: Constructor<*>): String {
|
||||
val sb = StringBuilder()
|
||||
sb.append("(")
|
||||
for (parameterType in constructor.getParameterTypes()) {
|
||||
for (parameterType in constructor.parameterTypes) {
|
||||
sb.append(parameterType.desc)
|
||||
}
|
||||
sb.append(")V")
|
||||
@@ -235,6 +235,6 @@ private object SignatureSerializer {
|
||||
}
|
||||
|
||||
fun fieldDesc(field: Field): String {
|
||||
return field.getType().desc
|
||||
return field.type.desc
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.load.kotlin.KotlinClassFinder
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
public class ReflectKotlinClassFinder(private val classLoader: ClassLoader) : KotlinClassFinder {
|
||||
class ReflectKotlinClassFinder(private val classLoader: ClassLoader) : KotlinClassFinder {
|
||||
private fun findKotlinClass(fqName: String): KotlinJvmBinaryClass? {
|
||||
return classLoader.tryLoadClass(fqName)?.let { ReflectKotlinClass.create(it) }
|
||||
}
|
||||
@@ -31,11 +31,11 @@ public class ReflectKotlinClassFinder(private val classLoader: ClassLoader) : Ko
|
||||
|
||||
override fun findKotlinClass(javaClass: JavaClass): KotlinJvmBinaryClass? {
|
||||
// TODO: go through javaClass's class loader
|
||||
return findKotlinClass(javaClass.getFqName()?.asString() ?: return null)
|
||||
return findKotlinClass(javaClass.fqName?.asString() ?: return null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun ClassId.toRuntimeFqName(): String {
|
||||
val className = getRelativeClassName().asString().replace('.', '$')
|
||||
return if (getPackageFqName().isRoot()) className else "${getPackageFqName()}.$className"
|
||||
val className = relativeClassName.asString().replace('.', '$')
|
||||
return if (packageFqName.isRoot) className else "${packageFqName}.$className"
|
||||
}
|
||||
|
||||
+4
-4
@@ -40,12 +40,12 @@ import org.jetbrains.kotlin.serialization.deserialization.DeserializationCompone
|
||||
import org.jetbrains.kotlin.serialization.deserialization.LocalClassResolver
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
|
||||
public class RuntimeModuleData private constructor(public val deserialization: DeserializationComponents, val packageFacadeProvider: RuntimePackagePartProvider) {
|
||||
public val module: ModuleDescriptor get() = deserialization.moduleDescriptor
|
||||
public val localClassResolver: LocalClassResolver get() = deserialization.localClassResolver
|
||||
class RuntimeModuleData private constructor(val deserialization: DeserializationComponents, val packageFacadeProvider: RuntimePackagePartProvider) {
|
||||
val module: ModuleDescriptor get() = deserialization.moduleDescriptor
|
||||
val localClassResolver: LocalClassResolver get() = deserialization.localClassResolver
|
||||
|
||||
companion object {
|
||||
public fun create(classLoader: ClassLoader): RuntimeModuleData {
|
||||
fun create(classLoader: ClassLoader): RuntimeModuleData {
|
||||
val builtIns = JvmBuiltIns.Instance
|
||||
val storageManager = LockBasedStorageManager()
|
||||
val module = ModuleDescriptorImpl(Name.special("<runtime module for $classLoader>"), storageManager,
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.builtins
|
||||
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
|
||||
public class BuiltInsInitializer<T : KotlinBuiltIns>(
|
||||
class BuiltInsInitializer<T : KotlinBuiltIns>(
|
||||
private val constructor: () -> T
|
||||
) {
|
||||
@Volatile private var instance: T? = null
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
||||
import java.io.DataInputStream
|
||||
import java.io.InputStream
|
||||
|
||||
public class BuiltinsPackageFragment(
|
||||
class BuiltinsPackageFragment(
|
||||
fqName: FqName,
|
||||
storageManager: StorageManager,
|
||||
module: ModuleDescriptor,
|
||||
@@ -68,7 +68,7 @@ public class BuiltinsPackageFragment(
|
||||
)
|
||||
} ?: super.computeMemberScope()
|
||||
|
||||
protected override fun loadClassNames(packageProto: ProtoBuf.Package): Collection<Name> {
|
||||
override fun loadClassNames(packageProto: ProtoBuf.Package): Collection<Name> {
|
||||
return packageProto.getExtension(BuiltInsProtoBuf.className)?.map { id -> nameResolver.getName(id) } ?: listOf()
|
||||
}
|
||||
|
||||
|
||||
@@ -20,22 +20,22 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import java.util.*
|
||||
|
||||
public class CompanionObjectMapping(private val builtIns: KotlinBuiltIns) {
|
||||
class CompanionObjectMapping(private val builtIns: KotlinBuiltIns) {
|
||||
private val classes = linkedSetOf<ClassDescriptor>()
|
||||
|
||||
init {
|
||||
for (type in PrimitiveType.NUMBER_TYPES) {
|
||||
classes.add(builtIns.getPrimitiveClassDescriptor(type))
|
||||
}
|
||||
classes.add(builtIns.getString())
|
||||
classes.add(builtIns.getEnum())
|
||||
classes.add(builtIns.string)
|
||||
classes.add(builtIns.enum)
|
||||
}
|
||||
|
||||
public fun allClassesWithIntrinsicCompanions(): Set<ClassDescriptor> =
|
||||
fun allClassesWithIntrinsicCompanions(): Set<ClassDescriptor> =
|
||||
Collections.unmodifiableSet(classes)
|
||||
|
||||
public fun hasMappingToObject(classDescriptor: ClassDescriptor): Boolean {
|
||||
fun hasMappingToObject(classDescriptor: ClassDescriptor): Boolean {
|
||||
return DescriptorUtils.isCompanionObject(classDescriptor) &&
|
||||
classDescriptor.getContainingDeclaration() in classes
|
||||
classDescriptor.containingDeclaration in classes
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import kotlin.reflect.KProperty
|
||||
|
||||
val KOTLIN_REFLECT_FQ_NAME = FqName("kotlin.reflect")
|
||||
|
||||
public class ReflectionTypes(private val module: ModuleDescriptor) {
|
||||
class ReflectionTypes(private val module: ModuleDescriptor) {
|
||||
private val kotlinReflectScope: MemberScope by lazy {
|
||||
module.getPackage(KOTLIN_REFLECT_FQ_NAME).memberScope
|
||||
}
|
||||
@@ -49,16 +49,16 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
|
||||
}
|
||||
}
|
||||
|
||||
public fun getKFunction(n: Int): ClassDescriptor = find("KFunction$n")
|
||||
fun getKFunction(n: Int): ClassDescriptor = find("KFunction$n")
|
||||
|
||||
public val kClass: ClassDescriptor by ClassLookup
|
||||
public val kProperty0: ClassDescriptor by ClassLookup
|
||||
public val kProperty1: ClassDescriptor by ClassLookup
|
||||
public val kProperty2: ClassDescriptor by ClassLookup
|
||||
public val kMutableProperty0: ClassDescriptor by ClassLookup
|
||||
public val kMutableProperty1: ClassDescriptor by ClassLookup
|
||||
val kClass: ClassDescriptor by ClassLookup
|
||||
val kProperty0: ClassDescriptor by ClassLookup
|
||||
val kProperty1: ClassDescriptor by ClassLookup
|
||||
val kProperty2: ClassDescriptor by ClassLookup
|
||||
val kMutableProperty0: ClassDescriptor by ClassLookup
|
||||
val kMutableProperty1: ClassDescriptor by ClassLookup
|
||||
|
||||
public fun getKClassType(annotations: Annotations, type: KotlinType): KotlinType {
|
||||
fun getKClassType(annotations: Annotations, type: KotlinType): KotlinType {
|
||||
val descriptor = kClass
|
||||
if (ErrorUtils.isError(descriptor)) {
|
||||
return descriptor.defaultType
|
||||
@@ -68,7 +68,7 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
|
||||
return KotlinTypeImpl.create(annotations, descriptor, false, arguments)
|
||||
}
|
||||
|
||||
public fun getKFunctionType(
|
||||
fun getKFunctionType(
|
||||
annotations: Annotations,
|
||||
receiverType: KotlinType?,
|
||||
parameterTypes: List<KotlinType>,
|
||||
@@ -85,7 +85,7 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
|
||||
return KotlinTypeImpl.create(annotations, classDescriptor, false, arguments)
|
||||
}
|
||||
|
||||
public fun getKPropertyType(annotations: Annotations, receiverType: KotlinType?, returnType: KotlinType, mutable: Boolean): KotlinType {
|
||||
fun getKPropertyType(annotations: Annotations, receiverType: KotlinType?, returnType: KotlinType, mutable: Boolean): KotlinType {
|
||||
val classDescriptor =
|
||||
when {
|
||||
receiverType != null -> when {
|
||||
@@ -111,12 +111,12 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
public fun isReflectionClass(descriptor: ClassDescriptor): Boolean {
|
||||
fun isReflectionClass(descriptor: ClassDescriptor): Boolean {
|
||||
val containingPackage = DescriptorUtils.getParentOfType(descriptor, PackageFragmentDescriptor::class.java)
|
||||
return containingPackage != null && containingPackage.fqName == KOTLIN_REFLECT_FQ_NAME
|
||||
}
|
||||
|
||||
public fun isCallableType(type: KotlinType): Boolean =
|
||||
fun isCallableType(type: KotlinType): Boolean =
|
||||
KotlinBuiltIns.isFunctionOrExtensionFunctionType(type) || isKCallableType(type)
|
||||
|
||||
private fun isKCallableType(type: KotlinType): Boolean =
|
||||
@@ -128,7 +128,7 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
|
||||
return descriptor is ClassDescriptor && DescriptorUtils.getFqName(descriptor) == KotlinBuiltIns.FQ_NAMES.kCallable
|
||||
}
|
||||
|
||||
public fun createKPropertyStarType(module: ModuleDescriptor): KotlinType? {
|
||||
fun createKPropertyStarType(module: ModuleDescriptor): KotlinType? {
|
||||
val kPropertyClass = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.kProperty) ?: return null
|
||||
return KotlinTypeImpl.create(
|
||||
Annotations.EMPTY, kPropertyClass, false,
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import java.io.InputStream
|
||||
|
||||
public fun createBuiltInPackageFragmentProvider(
|
||||
fun createBuiltInPackageFragmentProvider(
|
||||
storageManager: StorageManager,
|
||||
module: ModuleDescriptor,
|
||||
packageFqNames: Set<FqName>,
|
||||
|
||||
+2
-3
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
||||
/**
|
||||
* Produces descriptors representing the fictitious classes for function types, such as kotlin.Function1 or kotlin.reflect.KFunction2.
|
||||
*/
|
||||
public class BuiltInFictitiousFunctionClassFactory(
|
||||
class BuiltInFictitiousFunctionClassFactory(
|
||||
private val storageManager: StorageManager,
|
||||
private val module: ModuleDescriptor
|
||||
) : ClassDescriptorFactory {
|
||||
@@ -35,8 +35,7 @@ public class BuiltInFictitiousFunctionClassFactory(
|
||||
private data class KindWithArity(val kind: Kind, val arity: Int)
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
public fun parseClassName(className: String, packageFqName: FqName): KindWithArity? {
|
||||
@JvmStatic fun parseClassName(className: String, packageFqName: FqName): KindWithArity? {
|
||||
val kind = FunctionClassDescriptor.Kind.byPackage(packageFqName) ?: return null
|
||||
|
||||
val prefix = kind.classNamePrefix
|
||||
|
||||
+8
-8
@@ -40,14 +40,14 @@ import java.util.*
|
||||
* If the class represents kotlin.reflect.KFunction1, it has two supertypes: kotlin.Function1 and kotlin.reflect.KFunction.
|
||||
* This allows to use both 'invoke' and reflection API on function references obtained by '::'.
|
||||
*/
|
||||
public class FunctionClassDescriptor(
|
||||
class FunctionClassDescriptor(
|
||||
private val storageManager: StorageManager,
|
||||
private val containingDeclaration: PackageFragmentDescriptor,
|
||||
val functionKind: Kind,
|
||||
val arity: Int
|
||||
) : AbstractClassDescriptor(storageManager, functionKind.numberedClassName(arity)) {
|
||||
|
||||
public enum class Kind(val packageFqName: FqName, val classNamePrefix: String) {
|
||||
enum class Kind(val packageFqName: FqName, val classNamePrefix: String) {
|
||||
Function(BUILT_INS_PACKAGE_FQ_NAME, "Function"),
|
||||
KFunction(KOTLIN_REFLECT_FQ_NAME, "KFunction");
|
||||
|
||||
@@ -117,11 +117,11 @@ public class FunctionClassDescriptor(
|
||||
val descriptor = packageFragment.getMemberScope().getContributedClassifier(name, NoLookupLocation.FROM_BUILTINS) as? ClassDescriptor
|
||||
?: error("Class $name not found in $packageFragment")
|
||||
|
||||
val typeConstructor = descriptor.getTypeConstructor()
|
||||
val typeConstructor = descriptor.typeConstructor
|
||||
|
||||
// Substitute all type parameters of the super class with our last type parameters
|
||||
val arguments = getParameters().takeLast(typeConstructor.getParameters().size).map {
|
||||
TypeProjectionImpl(it.getDefaultType())
|
||||
val arguments = getParameters().takeLast(typeConstructor.parameters.size).map {
|
||||
TypeProjectionImpl(it.defaultType)
|
||||
}
|
||||
|
||||
result.add(KotlinTypeImpl.create(Annotations.EMPTY, descriptor, false, arguments))
|
||||
@@ -132,7 +132,7 @@ public class FunctionClassDescriptor(
|
||||
|
||||
// For KFunction{n}, add corresponding numbered Function{n} class, e.g. Function2 for KFunction2
|
||||
if (functionKind == Kind.KFunction) {
|
||||
val module = containingDeclaration.getContainingDeclaration()
|
||||
val module = containingDeclaration.containingDeclaration
|
||||
val kotlinPackageFragment = module.getPackage(BUILT_INS_PACKAGE_FQ_NAME).fragments.single()
|
||||
|
||||
add(kotlinPackageFragment, Kind.Function.numberedClassName(arity))
|
||||
@@ -150,8 +150,8 @@ public class FunctionClassDescriptor(
|
||||
override fun isFinal() = false
|
||||
override fun getAnnotations() = Annotations.EMPTY
|
||||
|
||||
override fun toString() = getDeclarationDescriptor().toString()
|
||||
override fun toString() = declarationDescriptor.toString()
|
||||
}
|
||||
|
||||
override fun toString() = getName().asString()
|
||||
override fun toString() = name.asString()
|
||||
}
|
||||
|
||||
@@ -47,24 +47,24 @@ class FunctionClassScope(
|
||||
}
|
||||
|
||||
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
||||
return allDescriptors().filterIsInstance<FunctionDescriptor>().filter { it.getName() == name }
|
||||
return allDescriptors().filterIsInstance<FunctionDescriptor>().filter { it.name == name }
|
||||
}
|
||||
|
||||
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
|
||||
return allDescriptors().filterIsInstance<PropertyDescriptor>().filter { it.getName() == name }
|
||||
return allDescriptors().filterIsInstance<PropertyDescriptor>().filter { it.name == name }
|
||||
}
|
||||
|
||||
private fun createFakeOverrides(invoke: FunctionDescriptor?): List<DeclarationDescriptor> {
|
||||
val result = ArrayList<DeclarationDescriptor>(3)
|
||||
val allSuperDescriptors = functionClass.getTypeConstructor().getSupertypes()
|
||||
.flatMap { it.getMemberScope().getContributedDescriptors() }
|
||||
val allSuperDescriptors = functionClass.typeConstructor.supertypes
|
||||
.flatMap { it.memberScope.getContributedDescriptors() }
|
||||
.filterIsInstance<CallableMemberDescriptor>()
|
||||
for ((name, group) in allSuperDescriptors.groupBy { it.getName() }) {
|
||||
for ((name, group) in allSuperDescriptors.groupBy { it.name }) {
|
||||
for ((isFunction, descriptors) in group.groupBy { it is FunctionDescriptor }) {
|
||||
OverridingUtil.generateOverridesInFunctionGroup(
|
||||
name,
|
||||
/* membersFromSupertypes = */ descriptors,
|
||||
/* membersFromCurrent = */ if (isFunction && name == invoke?.getName()) listOf(invoke) else listOf(),
|
||||
/* membersFromCurrent = */ if (isFunction && name == invoke?.name) listOf(invoke) else listOf(),
|
||||
functionClass,
|
||||
object : OverridingUtil.DescriptorSink {
|
||||
override fun addFakeOverride(fakeOverride: CallableMemberDescriptor) {
|
||||
|
||||
+6
-6
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
public class FunctionInvokeDescriptor private constructor(
|
||||
class FunctionInvokeDescriptor private constructor(
|
||||
private val container: DeclarationDescriptor,
|
||||
private val original: FunctionInvokeDescriptor?,
|
||||
private val callableKind: CallableMemberDescriptor.Kind
|
||||
@@ -63,12 +63,12 @@ public class FunctionInvokeDescriptor private constructor(
|
||||
val result = FunctionInvokeDescriptor(functionClass, null, CallableMemberDescriptor.Kind.DECLARATION)
|
||||
result.initialize(
|
||||
null,
|
||||
functionClass.getThisAsReceiverParameter(),
|
||||
functionClass.thisAsReceiverParameter,
|
||||
listOf(),
|
||||
typeParameters.takeWhile { it.getVariance() == Variance.IN_VARIANCE }
|
||||
typeParameters.takeWhile { it.variance == Variance.IN_VARIANCE }
|
||||
.withIndex()
|
||||
.map { createValueParameter(result, it.index, it.value) },
|
||||
typeParameters.last().getDefaultType(),
|
||||
typeParameters.last().defaultType,
|
||||
Modality.ABSTRACT,
|
||||
Visibilities.PUBLIC
|
||||
)
|
||||
@@ -81,7 +81,7 @@ public class FunctionInvokeDescriptor private constructor(
|
||||
index: Int,
|
||||
typeParameter: TypeParameterDescriptor
|
||||
): ValueParameterDescriptor {
|
||||
val typeParameterName = typeParameter.getName().asString()
|
||||
val typeParameterName = typeParameter.name.asString()
|
||||
val name = when (typeParameterName) {
|
||||
"T" -> "instance"
|
||||
"E" -> "receiver"
|
||||
@@ -95,7 +95,7 @@ public class FunctionInvokeDescriptor private constructor(
|
||||
containingDeclaration, null, index,
|
||||
Annotations.EMPTY,
|
||||
Name.identifier(name),
|
||||
typeParameter.getDefaultType(),
|
||||
typeParameter.defaultType,
|
||||
/* declaresDefaultValue = */ false,
|
||||
/* isCrossinline = */ false,
|
||||
/* isNoinline = */ false,
|
||||
|
||||
@@ -22,8 +22,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
object ConstUtil {
|
||||
@JvmStatic
|
||||
public fun canBeUsedForConstVal(type: KotlinType) = type.canBeUsedForConstVal()
|
||||
@JvmStatic fun canBeUsedForConstVal(type: KotlinType) = type.canBeUsedForConstVal()
|
||||
}
|
||||
|
||||
public fun KotlinType.canBeUsedForConstVal() = KotlinBuiltIns.isPrimitiveType(this) || KotlinBuiltIns.isString(this)
|
||||
fun KotlinType.canBeUsedForConstVal() = KotlinBuiltIns.isPrimitiveType(this) || KotlinBuiltIns.isString(this)
|
||||
|
||||
@@ -23,12 +23,12 @@ import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap
|
||||
import org.jetbrains.kotlin.resolve.ImportPath
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
|
||||
public interface ModuleDescriptor : DeclarationDescriptor, ModuleParameters {
|
||||
interface ModuleDescriptor : DeclarationDescriptor, ModuleParameters {
|
||||
override fun getContainingDeclaration(): DeclarationDescriptor? = null
|
||||
|
||||
public val builtIns: KotlinBuiltIns
|
||||
val builtIns: KotlinBuiltIns
|
||||
|
||||
public fun isFriend(other: ModuleDescriptor): Boolean
|
||||
fun isFriend(other: ModuleDescriptor): Boolean
|
||||
|
||||
override fun substitute(substitutor: TypeSubstitutor): ModuleDescriptor {
|
||||
return this
|
||||
@@ -38,9 +38,9 @@ public interface ModuleDescriptor : DeclarationDescriptor, ModuleParameters {
|
||||
return visitor.visitModuleDeclaration(this, data)
|
||||
}
|
||||
|
||||
public fun getPackage(fqName: FqName): PackageViewDescriptor
|
||||
fun getPackage(fqName: FqName): PackageViewDescriptor
|
||||
|
||||
public fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName>
|
||||
fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName>
|
||||
|
||||
fun <T> getCapability(capability: Capability<T>): T?
|
||||
|
||||
@@ -48,8 +48,8 @@ public interface ModuleDescriptor : DeclarationDescriptor, ModuleParameters {
|
||||
}
|
||||
|
||||
interface ModuleParameters {
|
||||
public val defaultImports: List<ImportPath>
|
||||
public val platformToKotlinClassMap: PlatformToKotlinClassMap
|
||||
val defaultImports: List<ImportPath>
|
||||
val platformToKotlinClassMap: PlatformToKotlinClassMap
|
||||
|
||||
object Empty: ModuleParameters {
|
||||
override val defaultImports: List<ImportPath> = emptyList()
|
||||
@@ -57,7 +57,7 @@ interface ModuleParameters {
|
||||
}
|
||||
}
|
||||
|
||||
public fun ModuleParameters(defaultImports: List<ImportPath>, platformToKotlinClassMap: PlatformToKotlinClassMap): ModuleParameters =
|
||||
fun ModuleParameters(defaultImports: List<ImportPath>, platformToKotlinClassMap: PlatformToKotlinClassMap): ModuleParameters =
|
||||
object : ModuleParameters {
|
||||
override val defaultImports: List<ImportPath> = defaultImports
|
||||
override val platformToKotlinClassMap: PlatformToKotlinClassMap = platformToKotlinClassMap
|
||||
|
||||
@@ -19,11 +19,11 @@ package org.jetbrains.kotlin.descriptors
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
|
||||
public interface PackageFragmentDescriptor : ClassOrPackageFragmentDescriptor {
|
||||
interface PackageFragmentDescriptor : ClassOrPackageFragmentDescriptor {
|
||||
|
||||
override fun getContainingDeclaration(): ModuleDescriptor
|
||||
|
||||
public val fqName: FqName
|
||||
val fqName: FqName
|
||||
|
||||
public fun getMemberScope(): MemberScope
|
||||
fun getMemberScope(): MemberScope
|
||||
}
|
||||
|
||||
@@ -19,13 +19,13 @@ package org.jetbrains.kotlin.descriptors
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
public interface PackageFragmentProvider {
|
||||
public fun getPackageFragments(fqName: FqName): List<PackageFragmentDescriptor>
|
||||
interface PackageFragmentProvider {
|
||||
fun getPackageFragments(fqName: FqName): List<PackageFragmentDescriptor>
|
||||
|
||||
public fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName>
|
||||
fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName>
|
||||
|
||||
|
||||
public object Empty : PackageFragmentProvider {
|
||||
object Empty : PackageFragmentProvider {
|
||||
override fun getPackageFragments(fqName: FqName) = emptyList<PackageFragmentDescriptor>()
|
||||
|
||||
override fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean) = emptySet<FqName>()
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.descriptors
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
public class PackageFragmentProviderImpl(
|
||||
class PackageFragmentProviderImpl(
|
||||
private val packageFragments: Collection<PackageFragmentDescriptor>
|
||||
) : PackageFragmentProvider {
|
||||
override fun getPackageFragments(fqName: FqName): List<PackageFragmentDescriptor> =
|
||||
@@ -28,6 +28,6 @@ public class PackageFragmentProviderImpl(
|
||||
override fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName> =
|
||||
packageFragments.asSequence()
|
||||
.map { it.fqName }
|
||||
.filter { !it.isRoot() && it.parent() == fqName }
|
||||
.filter { !it.isRoot && it.parent() == fqName }
|
||||
.toList()
|
||||
}
|
||||
|
||||
@@ -19,16 +19,16 @@ package org.jetbrains.kotlin.descriptors
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
|
||||
public interface PackageViewDescriptor : DeclarationDescriptor {
|
||||
interface PackageViewDescriptor : DeclarationDescriptor {
|
||||
override fun getContainingDeclaration(): PackageViewDescriptor?
|
||||
|
||||
public val fqName: FqName
|
||||
val fqName: FqName
|
||||
|
||||
public val memberScope: MemberScope
|
||||
val memberScope: MemberScope
|
||||
|
||||
public val module: ModuleDescriptor
|
||||
val module: ModuleDescriptor
|
||||
|
||||
public val fragments: List<PackageFragmentDescriptor>
|
||||
val fragments: List<PackageFragmentDescriptor>
|
||||
|
||||
public fun isEmpty(): Boolean = fragments.isEmpty()
|
||||
fun isEmpty(): Boolean = fragments.isEmpty()
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ package org.jetbrains.kotlin.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
|
||||
public abstract class Visibility protected constructor(
|
||||
public val name: String,
|
||||
public val isPublicAPI: Boolean
|
||||
abstract class Visibility protected constructor(
|
||||
val name: String,
|
||||
val isPublicAPI: Boolean
|
||||
) {
|
||||
public abstract fun isVisible(receiver: ReceiverValue?, what: DeclarationDescriptorWithVisibility, from: DeclarationDescriptor): Boolean
|
||||
abstract fun isVisible(receiver: ReceiverValue?, what: DeclarationDescriptorWithVisibility, from: DeclarationDescriptor): Boolean
|
||||
|
||||
/**
|
||||
* True, if it makes sense to check this visibility in imports and not import inaccessible declarations with such visibility.
|
||||
@@ -34,7 +34,7 @@ public abstract class Visibility protected constructor(
|
||||
* it returns true for PRIVATE, because there's no point in importing privates: they are inaccessible unless their short name is
|
||||
* already available without an import
|
||||
*/
|
||||
public abstract fun mustCheckInImports(): Boolean
|
||||
abstract fun mustCheckInImports(): Boolean
|
||||
|
||||
/**
|
||||
* @return null if the answer is unknown
|
||||
@@ -43,13 +43,13 @@ public abstract class Visibility protected constructor(
|
||||
return Visibilities.compareLocal(this, visibility)
|
||||
}
|
||||
|
||||
public open val displayName: String
|
||||
open val displayName: String
|
||||
get() = name
|
||||
|
||||
override final fun toString() = displayName
|
||||
|
||||
public open fun normalize(): Visibility = this
|
||||
open fun normalize(): Visibility = this
|
||||
|
||||
// Should be overloaded in Java visibilities
|
||||
public open fun effectiveVisibility(descriptor: ClassDescriptor?) = effectiveVisibility(normalize(), descriptor)
|
||||
open fun effectiveVisibility(descriptor: ClassDescriptor?) = effectiveVisibility(normalize(), descriptor)
|
||||
}
|
||||
|
||||
+4
-4
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.descriptors.annotations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
|
||||
public enum class AnnotationUseSiteTarget(renderName: String? = null) {
|
||||
enum class AnnotationUseSiteTarget(renderName: String? = null) {
|
||||
FIELD(),
|
||||
FILE(),
|
||||
PROPERTY(),
|
||||
@@ -28,10 +28,10 @@ public enum class AnnotationUseSiteTarget(renderName: String? = null) {
|
||||
CONSTRUCTOR_PARAMETER("param"),
|
||||
SETTER_PARAMETER("setparam");
|
||||
|
||||
public val renderName: String = renderName ?: name.toLowerCase()
|
||||
val renderName: String = renderName ?: name.toLowerCase()
|
||||
|
||||
public companion object {
|
||||
public fun getAssociatedUseSiteTarget(descriptor: DeclarationDescriptor): AnnotationUseSiteTarget? = when (descriptor) {
|
||||
companion object {
|
||||
fun getAssociatedUseSiteTarget(descriptor: DeclarationDescriptor): AnnotationUseSiteTarget? = when (descriptor) {
|
||||
is PropertyDescriptor -> PROPERTY
|
||||
is ValueParameterDescriptor -> CONSTRUCTOR_PARAMETER
|
||||
is PropertyGetterDescriptor -> PROPERTY_GETTER
|
||||
|
||||
+1
-1
@@ -16,4 +16,4 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.annotations
|
||||
|
||||
public data class AnnotationWithTarget(val annotation: AnnotationDescriptor, val target: AnnotationUseSiteTarget?)
|
||||
data class AnnotationWithTarget(val annotation: AnnotationDescriptor, val target: AnnotationUseSiteTarget?)
|
||||
@@ -20,23 +20,23 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
|
||||
public interface Annotations : Iterable<AnnotationDescriptor> {
|
||||
interface Annotations : Iterable<AnnotationDescriptor> {
|
||||
|
||||
public fun isEmpty(): Boolean
|
||||
fun isEmpty(): Boolean
|
||||
|
||||
public fun findAnnotation(fqName: FqName): AnnotationDescriptor?
|
||||
fun findAnnotation(fqName: FqName): AnnotationDescriptor?
|
||||
|
||||
public fun hasAnnotation(fqName: FqName) = findAnnotation(fqName) != null
|
||||
fun hasAnnotation(fqName: FqName) = findAnnotation(fqName) != null
|
||||
|
||||
public fun findExternalAnnotation(fqName: FqName): AnnotationDescriptor?
|
||||
fun findExternalAnnotation(fqName: FqName): AnnotationDescriptor?
|
||||
|
||||
public fun getUseSiteTargetedAnnotations(): List<AnnotationWithTarget>
|
||||
fun getUseSiteTargetedAnnotations(): List<AnnotationWithTarget>
|
||||
|
||||
// Returns both targeted and annotations without target. Annotation order is preserved.
|
||||
public fun getAllAnnotations(): List<AnnotationWithTarget>
|
||||
fun getAllAnnotations(): List<AnnotationWithTarget>
|
||||
|
||||
companion object {
|
||||
public val EMPTY: Annotations = object : Annotations {
|
||||
val EMPTY: Annotations = object : Annotations {
|
||||
override fun isEmpty() = true
|
||||
|
||||
override fun findAnnotation(fqName: FqName) = null
|
||||
@@ -52,11 +52,11 @@ public interface Annotations : Iterable<AnnotationDescriptor> {
|
||||
override fun toString() = "EMPTY"
|
||||
}
|
||||
|
||||
public fun findAnyAnnotation(annotations: Annotations, fqName: FqName): AnnotationWithTarget? {
|
||||
fun findAnyAnnotation(annotations: Annotations, fqName: FqName): AnnotationWithTarget? {
|
||||
return annotations.getAllAnnotations().firstOrNull { checkAnnotationName(it.annotation, fqName) }
|
||||
}
|
||||
|
||||
public fun findUseSiteTargetedAnnotation(annotations: Annotations, target: AnnotationUseSiteTarget, fqName: FqName): AnnotationDescriptor? {
|
||||
fun findUseSiteTargetedAnnotation(annotations: Annotations, target: AnnotationUseSiteTarget, fqName: FqName): AnnotationDescriptor? {
|
||||
return getUseSiteTargetedAnnotations(annotations, target).firstOrNull { checkAnnotationName(it, fqName) }
|
||||
}
|
||||
|
||||
@@ -104,9 +104,9 @@ class FilteredAnnotations(
|
||||
override fun iterator() = delegate.filter { shouldBeReturned(it) }.iterator()
|
||||
|
||||
private fun shouldBeReturned(annotation: AnnotationDescriptor): Boolean {
|
||||
val descriptor = annotation.getType().getConstructor().getDeclarationDescriptor()
|
||||
val descriptor = annotation.type.constructor.declarationDescriptor
|
||||
return descriptor != null && DescriptorUtils.getFqName(descriptor).let { fqName ->
|
||||
fqName.isSafe() && fqNameFilter(fqName.toSafe())
|
||||
fqName.isSafe && fqNameFilter(fqName.toSafe())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-6
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
|
||||
public class AnnotationsImpl : Annotations {
|
||||
class AnnotationsImpl : Annotations {
|
||||
private val annotations: List<AnnotationDescriptor>
|
||||
private val targetedAnnotations: List<AnnotationWithTarget>
|
||||
|
||||
@@ -41,7 +41,7 @@ public class AnnotationsImpl : Annotations {
|
||||
override fun isEmpty() = annotations.isEmpty()
|
||||
|
||||
override fun findAnnotation(fqName: FqName) = annotations.firstOrNull {
|
||||
val descriptor = it.getType().getConstructor().getDeclarationDescriptor()
|
||||
val descriptor = it.type.constructor.declarationDescriptor
|
||||
descriptor is ClassDescriptor && fqName.toUnsafe() == DescriptorUtils.getFqName(descriptor)
|
||||
}
|
||||
|
||||
@@ -60,13 +60,11 @@ public class AnnotationsImpl : Annotations {
|
||||
override fun toString() = annotations.toString()
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
public fun create(annotationsWithTargets: List<AnnotationWithTarget>): AnnotationsImpl {
|
||||
@JvmStatic fun create(annotationsWithTargets: List<AnnotationWithTarget>): AnnotationsImpl {
|
||||
return AnnotationsImpl(annotationsWithTargets, 0)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
public fun createWithNoTarget(vararg annotations: AnnotationDescriptor): AnnotationsImpl {
|
||||
@JvmStatic fun createWithNoTarget(vararg annotations: AnnotationDescriptor): AnnotationsImpl {
|
||||
return create(annotations.map { AnnotationWithTarget(it, null) })
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.annotations
|
||||
|
||||
public enum class KotlinRetention {
|
||||
enum class KotlinRetention {
|
||||
RUNTIME,
|
||||
BINARY,
|
||||
SOURCE
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.*
|
||||
|
||||
// NOTE: this enum must have the same entries with kotlin.annotation.AnnotationTarget,
|
||||
// and may also have some additional entries
|
||||
public enum class KotlinTarget(val description: String, val isDefault: Boolean = true) {
|
||||
enum class KotlinTarget(val description: String, val isDefault: Boolean = true) {
|
||||
CLASS("class"), // includes CLASS_ONLY, OBJECT, COMPANION_OBJECT, OBJECT_LITERAL, INTERFACE, *_CLASS but not ENUM_ENTRY
|
||||
ANNOTATION_CLASS("annotation class"),
|
||||
TYPE_PARAMETER("type parameter", false),
|
||||
@@ -81,13 +81,13 @@ public enum class KotlinTarget(val description: String, val isDefault: Boolean =
|
||||
}
|
||||
}
|
||||
|
||||
public fun valueOrNull(name: String): KotlinTarget? = map[name]
|
||||
fun valueOrNull(name: String): KotlinTarget? = map[name]
|
||||
|
||||
public val DEFAULT_TARGET_SET: Set<KotlinTarget> = values().filter { it.isDefault }.toSet()
|
||||
val DEFAULT_TARGET_SET: Set<KotlinTarget> = values().filter { it.isDefault }.toSet()
|
||||
|
||||
public val ALL_TARGET_SET: Set<KotlinTarget> = values().toSet()
|
||||
val ALL_TARGET_SET: Set<KotlinTarget> = values().toSet()
|
||||
|
||||
public fun classActualTargets(descriptor: ClassDescriptor): List<KotlinTarget> = when (descriptor.kind) {
|
||||
fun classActualTargets(descriptor: ClassDescriptor): List<KotlinTarget> = when (descriptor.kind) {
|
||||
ClassKind.ANNOTATION_CLASS -> listOf(ANNOTATION_CLASS, CLASS)
|
||||
ClassKind.CLASS ->
|
||||
if (descriptor.isInner) {
|
||||
@@ -117,7 +117,7 @@ public enum class KotlinTarget(val description: String, val isDefault: Boolean =
|
||||
ClassKind.ENUM_ENTRY -> listOf(ENUM_ENTRY, PROPERTY, FIELD)
|
||||
}
|
||||
|
||||
public val USE_SITE_MAPPING: Map<AnnotationUseSiteTarget, KotlinTarget> = mapOf(
|
||||
val USE_SITE_MAPPING: Map<AnnotationUseSiteTarget, KotlinTarget> = mapOf(
|
||||
AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER to VALUE_PARAMETER,
|
||||
AnnotationUseSiteTarget.FIELD to FIELD,
|
||||
AnnotationUseSiteTarget.PROPERTY to PROPERTY,
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.resolve.constants.EnumValue
|
||||
import org.jetbrains.kotlin.resolve.constants.StringValue
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
public fun KotlinBuiltIns.createDeprecatedAnnotation(
|
||||
fun KotlinBuiltIns.createDeprecatedAnnotation(
|
||||
message: String,
|
||||
replaceWith: String,
|
||||
level: String = "WARNING"
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ import java.util.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
|
||||
public class CompositePackageFragmentProvider(// can be modified from outside
|
||||
class CompositePackageFragmentProvider(// can be modified from outside
|
||||
private val providers: List<PackageFragmentProvider>) : PackageFragmentProvider {
|
||||
|
||||
override fun getPackageFragments(fqName: FqName): List<PackageFragmentDescriptor> {
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.storage.getValue
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
|
||||
public class LazyPackageViewDescriptorImpl(
|
||||
class LazyPackageViewDescriptorImpl(
|
||||
override val module: ModuleDescriptorImpl,
|
||||
override val fqName: FqName,
|
||||
storageManager: StorageManager
|
||||
@@ -51,7 +51,7 @@ public class LazyPackageViewDescriptorImpl(
|
||||
})
|
||||
|
||||
override fun getContainingDeclaration(): PackageViewDescriptor? {
|
||||
return if (fqName.isRoot()) null else module.getPackage(fqName.parent())
|
||||
return if (fqName.isRoot) null else module.getPackage(fqName.parent())
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
|
||||
+12
-12
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
import java.util.*
|
||||
|
||||
public class ModuleDescriptorImpl @JvmOverloads constructor(
|
||||
class ModuleDescriptorImpl @JvmOverloads constructor(
|
||||
moduleName: Name,
|
||||
private val storageManager: StorageManager,
|
||||
private val moduleParameters: ModuleParameters,
|
||||
@@ -36,7 +36,7 @@ public class ModuleDescriptorImpl @JvmOverloads constructor(
|
||||
private val capabilities: Map<ModuleDescriptor.Capability<*>, Any?> = emptyMap()
|
||||
) : DeclarationDescriptorImpl(Annotations.EMPTY, moduleName), ModuleDescriptor, ModuleParameters by moduleParameters {
|
||||
init {
|
||||
if (!moduleName.isSpecial()) {
|
||||
if (!moduleName.isSpecial) {
|
||||
throw IllegalArgumentException("Module name must be special: $moduleName")
|
||||
}
|
||||
}
|
||||
@@ -68,26 +68,26 @@ public class ModuleDescriptorImpl @JvmOverloads constructor(
|
||||
private val isInitialized: Boolean
|
||||
get() = packageFragmentProviderForModuleContent != null
|
||||
|
||||
public fun setDependencies(dependencies: ModuleDependencies) {
|
||||
fun setDependencies(dependencies: ModuleDependencies) {
|
||||
assert(this.dependencies == null) { "Dependencies of $id were already set" }
|
||||
this.dependencies = dependencies
|
||||
}
|
||||
|
||||
public fun setDependencies(vararg descriptors: ModuleDescriptorImpl) {
|
||||
fun setDependencies(vararg descriptors: ModuleDescriptorImpl) {
|
||||
setDependencies(descriptors.toList())
|
||||
}
|
||||
|
||||
public fun setDependencies(descriptors: List<ModuleDescriptorImpl>) {
|
||||
fun setDependencies(descriptors: List<ModuleDescriptorImpl>) {
|
||||
setDependencies(ModuleDependenciesImpl(descriptors))
|
||||
}
|
||||
|
||||
private val id: String
|
||||
get() = getName().toString()
|
||||
get() = name.toString()
|
||||
|
||||
/*
|
||||
* Call initialize() to set module contents. Uninitialized module cannot be queried for its contents.
|
||||
*/
|
||||
public fun initialize(providerForModuleContent: PackageFragmentProvider) {
|
||||
fun initialize(providerForModuleContent: PackageFragmentProvider) {
|
||||
assert(!isInitialized) { "Attempt to initialize module $id twice" }
|
||||
this.packageFragmentProviderForModuleContent = providerForModuleContent
|
||||
}
|
||||
@@ -99,7 +99,7 @@ public class ModuleDescriptorImpl @JvmOverloads constructor(
|
||||
|
||||
override fun isFriend(other: ModuleDescriptor) = other == this || other in friendModules
|
||||
|
||||
public fun addFriend(friend: ModuleDescriptorImpl): Unit {
|
||||
fun addFriend(friend: ModuleDescriptorImpl): Unit {
|
||||
assert(friend != this) { "Attempt to make module $id a friend to itself" }
|
||||
friendModules.add(friend)
|
||||
}
|
||||
@@ -108,13 +108,13 @@ public class ModuleDescriptorImpl @JvmOverloads constructor(
|
||||
override fun <T> getCapability(capability: ModuleDescriptor.Capability<T>) = capabilities[capability] as? T
|
||||
}
|
||||
|
||||
public interface ModuleDependencies {
|
||||
public val descriptors: List<ModuleDescriptorImpl>
|
||||
interface ModuleDependencies {
|
||||
val descriptors: List<ModuleDescriptorImpl>
|
||||
}
|
||||
|
||||
public class ModuleDependenciesImpl(override val descriptors: List<ModuleDescriptorImpl>) : ModuleDependencies
|
||||
class ModuleDependenciesImpl(override val descriptors: List<ModuleDescriptorImpl>) : ModuleDependencies
|
||||
|
||||
public class LazyModuleDependencies(
|
||||
class LazyModuleDependencies(
|
||||
storageManager: StorageManager,
|
||||
computeDependencies: () -> List<ModuleDescriptorImpl>
|
||||
) : ModuleDependencies {
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
|
||||
public abstract class PackageFragmentDescriptorImpl(
|
||||
abstract class PackageFragmentDescriptorImpl(
|
||||
module: ModuleDescriptor,
|
||||
override val fqName: FqName
|
||||
) : DeclarationDescriptorNonRootImpl(module, Annotations.EMPTY, fqName.shortNameOrSpecial(), SourceElement.NO_SOURCE),
|
||||
|
||||
@@ -28,10 +28,10 @@ import org.jetbrains.kotlin.utils.Printer
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import java.util.*
|
||||
|
||||
public open class SubpackagesScope(private val moduleDescriptor: ModuleDescriptor, private val fqName: FqName) : MemberScopeImpl() {
|
||||
open class SubpackagesScope(private val moduleDescriptor: ModuleDescriptor, private val fqName: FqName) : MemberScopeImpl() {
|
||||
|
||||
protected fun getPackage(name: Name): PackageViewDescriptor? {
|
||||
if (name.isSpecial()) {
|
||||
if (name.isSpecial) {
|
||||
return null
|
||||
}
|
||||
val packageViewDescriptor = moduleDescriptor.getPackage(fqName.child(name))
|
||||
@@ -44,7 +44,7 @@ public open class SubpackagesScope(private val moduleDescriptor: ModuleDescripto
|
||||
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
if (!kindFilter.acceptsKinds(DescriptorKindFilter.PACKAGES_MASK)) return listOf()
|
||||
if (fqName.isRoot() && kindFilter.excludes.contains(DescriptorKindExclude.TopLevelPackages)) return listOf()
|
||||
if (fqName.isRoot && kindFilter.excludes.contains(DescriptorKindExclude.TopLevelPackages)) return listOf()
|
||||
|
||||
val subFqNames = moduleDescriptor.getSubPackagesOf(fqName, nameFilter)
|
||||
val result = ArrayList<DeclarationDescriptor>(subFqNames.size)
|
||||
@@ -58,7 +58,7 @@ public open class SubpackagesScope(private val moduleDescriptor: ModuleDescripto
|
||||
}
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println(javaClass.getSimpleName(), " {")
|
||||
p.println(javaClass.simpleName, " {")
|
||||
p.pushIndent()
|
||||
|
||||
p.popIndent()
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.incremental.components
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
public interface LookupLocation {
|
||||
interface LookupLocation {
|
||||
val location: LocationInfo?
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ data class Position(val line: Int, val column: Int) : Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public enum class NoLookupLocation : LookupLocation {
|
||||
enum class NoLookupLocation : LookupLocation {
|
||||
FROM_IDE,
|
||||
FROM_BACKEND,
|
||||
FROM_TEST,
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.incremental.components
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
public interface LookupTracker {
|
||||
interface LookupTracker {
|
||||
// used in tests for more accurate checks
|
||||
val requiresPosition: Boolean
|
||||
|
||||
@@ -41,7 +41,7 @@ public interface LookupTracker {
|
||||
}
|
||||
}
|
||||
|
||||
public enum class ScopeKind {
|
||||
enum class ScopeKind {
|
||||
PACKAGE,
|
||||
CLASSIFIER
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.incremental.components.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
|
||||
public fun LookupTracker.record(from: LookupLocation, scopeOwner: DeclarationDescriptor, name: Name) {
|
||||
fun LookupTracker.record(from: LookupLocation, scopeOwner: DeclarationDescriptor, name: Name) {
|
||||
if (this == LookupTracker.DO_NOTHING || from is NoLookupLocation) return
|
||||
|
||||
val location = from.location ?: return
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.name
|
||||
|
||||
public fun FqName.isSubpackageOf(packageName: FqName): Boolean {
|
||||
fun FqName.isSubpackageOf(packageName: FqName): Boolean {
|
||||
return when {
|
||||
this == packageName -> true
|
||||
packageName.isRoot() -> true
|
||||
packageName.isRoot -> true
|
||||
else -> isSubpackageOf(this.asString(), packageName.asString())
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ private fun isSubpackageOf(subpackageNameStr: String, packageNameStr: String): B
|
||||
return subpackageNameStr.startsWith(packageNameStr) && subpackageNameStr[packageNameStr.length] == '.'
|
||||
}
|
||||
|
||||
public fun FqName.isOneSegmentFQN(): Boolean = !isRoot() && parent().isRoot()
|
||||
fun FqName.isOneSegmentFQN(): Boolean = !isRoot && parent().isRoot
|
||||
|
||||
/**
|
||||
* Get the tail part of the FQ name by stripping a prefix. If FQ name does not begin with the given prefix, it will be returned as is.
|
||||
@@ -39,15 +39,15 @@ public fun FqName.isOneSegmentFQN(): Boolean = !isRoot() && parent().isRoot()
|
||||
* "org.jetbrains.kotlin".tail("org.jetbrains.kotlin") = ""
|
||||
* "org.jetbrains.kotlin".tail("org.jetbrains.gogland") = "org.jetbrains.kotlin"
|
||||
*/
|
||||
public fun FqName.tail(prefix: FqName): FqName {
|
||||
fun FqName.tail(prefix: FqName): FqName {
|
||||
return when {
|
||||
!isSubpackageOf(prefix) || prefix.isRoot() -> this
|
||||
!isSubpackageOf(prefix) || prefix.isRoot -> this
|
||||
this == prefix -> FqName.ROOT
|
||||
else -> FqName(asString().substring(prefix.asString().length + 1))
|
||||
}
|
||||
}
|
||||
|
||||
public fun FqName.parentOrNull(): FqName? = if (this.isRoot) null else parent()
|
||||
fun FqName.parentOrNull(): FqName? = if (this.isRoot) null else parent()
|
||||
|
||||
private enum class State {
|
||||
BEGINNING,
|
||||
@@ -56,7 +56,7 @@ private enum class State {
|
||||
}
|
||||
|
||||
// Check that it is javaName(\.javaName)* or an empty string
|
||||
public fun isValidJavaFqName(qualifiedName: String?): Boolean {
|
||||
fun isValidJavaFqName(qualifiedName: String?): Boolean {
|
||||
if (qualifiedName == null) return false
|
||||
|
||||
var state = State.BEGINNING
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.types.Flexibility
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeCapability
|
||||
|
||||
public interface CustomFlexibleRendering : TypeCapability {
|
||||
public fun renderInflexible(type: KotlinType, renderer: DescriptorRenderer): String?
|
||||
public fun renderBounds(flexibility: Flexibility, renderer: DescriptorRenderer): Pair<String, String>?
|
||||
interface CustomFlexibleRendering : TypeCapability {
|
||||
fun renderInflexible(type: KotlinType, renderer: DescriptorRenderer): String?
|
||||
fun renderBounds(flexibility: Flexibility, renderer: DescriptorRenderer): Pair<String, String>?
|
||||
}
|
||||
|
||||
@@ -26,45 +26,45 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.TypeProjection
|
||||
|
||||
public abstract class DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
||||
public fun withOptions(changeOptions: DescriptorRendererOptions.() -> Unit): DescriptorRenderer {
|
||||
abstract class DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
||||
fun withOptions(changeOptions: DescriptorRendererOptions.() -> Unit): DescriptorRenderer {
|
||||
val options = (this as DescriptorRendererImpl).options.copy()
|
||||
options.changeOptions()
|
||||
options.lock()
|
||||
return DescriptorRendererImpl(options)
|
||||
}
|
||||
|
||||
public abstract fun renderType(type: KotlinType): String
|
||||
abstract fun renderType(type: KotlinType): String
|
||||
|
||||
public abstract fun renderTypeArguments(typeArguments: List<TypeProjection>): String
|
||||
abstract fun renderTypeArguments(typeArguments: List<TypeProjection>): String
|
||||
|
||||
public abstract fun renderTypeProjection(typeProjection: TypeProjection): String
|
||||
abstract fun renderTypeProjection(typeProjection: TypeProjection): String
|
||||
|
||||
public abstract fun renderTypeConstructor(typeConstructor: TypeConstructor): String
|
||||
abstract fun renderTypeConstructor(typeConstructor: TypeConstructor): String
|
||||
|
||||
public abstract fun renderClassifierName(klass: ClassifierDescriptor): String
|
||||
abstract fun renderClassifierName(klass: ClassifierDescriptor): String
|
||||
|
||||
public abstract fun renderAnnotation(annotation: AnnotationDescriptor, target: AnnotationUseSiteTarget? = null): String
|
||||
abstract fun renderAnnotation(annotation: AnnotationDescriptor, target: AnnotationUseSiteTarget? = null): String
|
||||
|
||||
override abstract fun render(declarationDescriptor: DeclarationDescriptor): String
|
||||
|
||||
public abstract fun renderValueParameters(parameters: Collection<ValueParameterDescriptor>, synthesizedParameterNames: Boolean): String
|
||||
abstract fun renderValueParameters(parameters: Collection<ValueParameterDescriptor>, synthesizedParameterNames: Boolean): String
|
||||
|
||||
public fun renderFunctionParameters(functionDescriptor: FunctionDescriptor): String
|
||||
fun renderFunctionParameters(functionDescriptor: FunctionDescriptor): String
|
||||
= renderValueParameters(functionDescriptor.valueParameters, functionDescriptor.hasSynthesizedParameterNames())
|
||||
|
||||
public abstract fun renderName(name: Name): String
|
||||
abstract fun renderName(name: Name): String
|
||||
|
||||
public abstract fun renderFqName(fqName: FqNameUnsafe): String
|
||||
abstract fun renderFqName(fqName: FqNameUnsafe): String
|
||||
|
||||
public interface ValueParametersHandler {
|
||||
public fun appendBeforeValueParameters(parameterCount: Int, builder: StringBuilder)
|
||||
public fun appendAfterValueParameters(parameterCount: Int, builder: StringBuilder)
|
||||
interface ValueParametersHandler {
|
||||
fun appendBeforeValueParameters(parameterCount: Int, builder: StringBuilder)
|
||||
fun appendAfterValueParameters(parameterCount: Int, builder: StringBuilder)
|
||||
|
||||
public fun appendBeforeValueParameter(parameter: ValueParameterDescriptor, parameterIndex: Int, parameterCount: Int, builder: StringBuilder)
|
||||
public fun appendAfterValueParameter(parameter: ValueParameterDescriptor, parameterIndex: Int, parameterCount: Int, builder: StringBuilder)
|
||||
fun appendBeforeValueParameter(parameter: ValueParameterDescriptor, parameterIndex: Int, parameterCount: Int, builder: StringBuilder)
|
||||
fun appendAfterValueParameter(parameter: ValueParameterDescriptor, parameterIndex: Int, parameterCount: Int, builder: StringBuilder)
|
||||
|
||||
public object DEFAULT : ValueParametersHandler {
|
||||
object DEFAULT : ValueParametersHandler {
|
||||
override fun appendBeforeValueParameters(parameterCount: Int, builder: StringBuilder) {
|
||||
builder.append("(")
|
||||
}
|
||||
@@ -85,33 +85,29 @@ public abstract class DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
||||
}
|
||||
|
||||
companion object {
|
||||
public fun withOptions(changeOptions: DescriptorRendererOptions.() -> Unit): DescriptorRenderer {
|
||||
fun withOptions(changeOptions: DescriptorRendererOptions.() -> Unit): DescriptorRenderer {
|
||||
val options = DescriptorRendererOptionsImpl()
|
||||
options.changeOptions()
|
||||
options.lock()
|
||||
return DescriptorRendererImpl(options)
|
||||
}
|
||||
|
||||
@JvmField
|
||||
public val COMPACT_WITH_MODIFIERS: DescriptorRenderer = withOptions {
|
||||
@JvmField val COMPACT_WITH_MODIFIERS: DescriptorRenderer = withOptions {
|
||||
withDefinedIn = false
|
||||
}
|
||||
|
||||
@JvmField
|
||||
public val COMPACT: DescriptorRenderer = withOptions {
|
||||
@JvmField val COMPACT: DescriptorRenderer = withOptions {
|
||||
withDefinedIn = false
|
||||
modifiers = emptySet()
|
||||
}
|
||||
|
||||
@JvmField
|
||||
public val COMPACT_WITH_SHORT_TYPES: DescriptorRenderer = withOptions {
|
||||
@JvmField val COMPACT_WITH_SHORT_TYPES: DescriptorRenderer = withOptions {
|
||||
modifiers = emptySet()
|
||||
nameShortness = NameShortness.SHORT
|
||||
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.ONLY_NON_SYNTHESIZED
|
||||
}
|
||||
|
||||
@JvmField
|
||||
public val ONLY_NAMES_WITH_SHORT_TYPES: DescriptorRenderer = withOptions {
|
||||
@JvmField val ONLY_NAMES_WITH_SHORT_TYPES: DescriptorRenderer = withOptions {
|
||||
withDefinedIn = false
|
||||
modifiers = emptySet()
|
||||
nameShortness = NameShortness.SHORT
|
||||
@@ -123,40 +119,35 @@ public abstract class DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
||||
startFromName = true
|
||||
}
|
||||
|
||||
@JvmField
|
||||
public val FQ_NAMES_IN_TYPES: DescriptorRenderer = withOptions {
|
||||
@JvmField val FQ_NAMES_IN_TYPES: DescriptorRenderer = withOptions {
|
||||
modifiers = DescriptorRendererModifier.ALL
|
||||
}
|
||||
|
||||
@JvmField
|
||||
public val SHORT_NAMES_IN_TYPES: DescriptorRenderer = withOptions {
|
||||
@JvmField val SHORT_NAMES_IN_TYPES: DescriptorRenderer = withOptions {
|
||||
nameShortness = NameShortness.SHORT
|
||||
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.ONLY_NON_SYNTHESIZED
|
||||
}
|
||||
|
||||
@JvmField
|
||||
public val DEBUG_TEXT: DescriptorRenderer = withOptions {
|
||||
@JvmField val DEBUG_TEXT: DescriptorRenderer = withOptions {
|
||||
debugMode = true
|
||||
nameShortness = NameShortness.FULLY_QUALIFIED
|
||||
modifiers = DescriptorRendererModifier.ALL
|
||||
}
|
||||
|
||||
@JvmField
|
||||
public val FLEXIBLE_TYPES_FOR_CODE: DescriptorRenderer = withOptions {
|
||||
@JvmField val FLEXIBLE_TYPES_FOR_CODE: DescriptorRenderer = withOptions {
|
||||
flexibleTypesForCode = true
|
||||
}
|
||||
|
||||
@JvmField
|
||||
public val HTML: DescriptorRenderer = withOptions {
|
||||
@JvmField val HTML: DescriptorRenderer = withOptions {
|
||||
textFormat = RenderingFormat.HTML
|
||||
modifiers = DescriptorRendererModifier.ALL
|
||||
}
|
||||
|
||||
public fun getClassKindPrefix(klass: ClassDescriptor): String {
|
||||
if (klass.isCompanionObject()) {
|
||||
fun getClassKindPrefix(klass: ClassDescriptor): String {
|
||||
if (klass.isCompanionObject) {
|
||||
return "companion object"
|
||||
}
|
||||
return when (klass.getKind()) {
|
||||
return when (klass.kind) {
|
||||
ClassKind.CLASS -> "class"
|
||||
ClassKind.INTERFACE -> "interface"
|
||||
ClassKind.ENUM_CLASS -> "enum class"
|
||||
@@ -168,38 +159,38 @@ public abstract class DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
||||
}
|
||||
}
|
||||
|
||||
public interface DescriptorRendererOptions {
|
||||
public var nameShortness: NameShortness
|
||||
public var withDefinedIn: Boolean
|
||||
public var modifiers: Set<DescriptorRendererModifier>
|
||||
public var startFromName: Boolean
|
||||
public var debugMode: Boolean
|
||||
public var classWithPrimaryConstructor: Boolean
|
||||
public var verbose: Boolean
|
||||
public var unitReturnType: Boolean
|
||||
public var withoutReturnType: Boolean
|
||||
public var normalizedVisibilities: Boolean
|
||||
public var showInternalKeyword: Boolean
|
||||
public var prettyFunctionTypes: Boolean
|
||||
public var uninferredTypeParameterAsName: Boolean
|
||||
public var overrideRenderingPolicy: OverrideRenderingPolicy
|
||||
public var valueParametersHandler: DescriptorRenderer.ValueParametersHandler
|
||||
public var textFormat: RenderingFormat
|
||||
public var excludedAnnotationClasses: Set<FqName>
|
||||
public var excludedTypeAnnotationClasses: Set<FqName>
|
||||
public var includePropertyConstant: Boolean
|
||||
public var parameterNameRenderingPolicy: ParameterNameRenderingPolicy
|
||||
public var withoutTypeParameters: Boolean
|
||||
public var receiverAfterName: Boolean
|
||||
public var renderCompanionObjectName: Boolean
|
||||
public var withoutSuperTypes: Boolean
|
||||
public var typeNormalizer: (KotlinType) -> KotlinType
|
||||
public var renderDefaultValues: Boolean
|
||||
public var flexibleTypesForCode: Boolean
|
||||
public var secondaryConstructorsAsPrimary: Boolean
|
||||
public var renderAccessors: Boolean
|
||||
public var renderDefaultAnnotationArguments: Boolean
|
||||
public var alwaysRenderModifiers: Boolean
|
||||
interface DescriptorRendererOptions {
|
||||
var nameShortness: NameShortness
|
||||
var withDefinedIn: Boolean
|
||||
var modifiers: Set<DescriptorRendererModifier>
|
||||
var startFromName: Boolean
|
||||
var debugMode: Boolean
|
||||
var classWithPrimaryConstructor: Boolean
|
||||
var verbose: Boolean
|
||||
var unitReturnType: Boolean
|
||||
var withoutReturnType: Boolean
|
||||
var normalizedVisibilities: Boolean
|
||||
var showInternalKeyword: Boolean
|
||||
var prettyFunctionTypes: Boolean
|
||||
var uninferredTypeParameterAsName: Boolean
|
||||
var overrideRenderingPolicy: OverrideRenderingPolicy
|
||||
var valueParametersHandler: DescriptorRenderer.ValueParametersHandler
|
||||
var textFormat: RenderingFormat
|
||||
var excludedAnnotationClasses: Set<FqName>
|
||||
var excludedTypeAnnotationClasses: Set<FqName>
|
||||
var includePropertyConstant: Boolean
|
||||
var parameterNameRenderingPolicy: ParameterNameRenderingPolicy
|
||||
var withoutTypeParameters: Boolean
|
||||
var receiverAfterName: Boolean
|
||||
var renderCompanionObjectName: Boolean
|
||||
var withoutSuperTypes: Boolean
|
||||
var typeNormalizer: (KotlinType) -> KotlinType
|
||||
var renderDefaultValues: Boolean
|
||||
var flexibleTypesForCode: Boolean
|
||||
var secondaryConstructorsAsPrimary: Boolean
|
||||
var renderAccessors: Boolean
|
||||
var renderDefaultAnnotationArguments: Boolean
|
||||
var alwaysRenderModifiers: Boolean
|
||||
}
|
||||
|
||||
object ExcludedTypeAnnotations {
|
||||
@@ -214,30 +205,30 @@ object ExcludedTypeAnnotations {
|
||||
FqName("kotlin.internal.Exact"))
|
||||
}
|
||||
|
||||
public enum class RenderingFormat {
|
||||
enum class RenderingFormat {
|
||||
PLAIN,
|
||||
HTML
|
||||
}
|
||||
|
||||
public enum class NameShortness {
|
||||
enum class NameShortness {
|
||||
SHORT,
|
||||
FULLY_QUALIFIED,
|
||||
SOURCE_CODE_QUALIFIED // for local declarations qualified up to function scope
|
||||
}
|
||||
|
||||
public enum class OverrideRenderingPolicy {
|
||||
enum class OverrideRenderingPolicy {
|
||||
RENDER_OVERRIDE,
|
||||
RENDER_OPEN,
|
||||
RENDER_OPEN_OVERRIDE
|
||||
}
|
||||
|
||||
public enum class ParameterNameRenderingPolicy {
|
||||
enum class ParameterNameRenderingPolicy {
|
||||
ALL,
|
||||
ONLY_NON_SYNTHESIZED,
|
||||
NONE
|
||||
}
|
||||
|
||||
public enum class DescriptorRendererModifier(val includeByDefault: Boolean) {
|
||||
enum class DescriptorRendererModifier(val includeByDefault: Boolean) {
|
||||
VISIBILITY(true),
|
||||
MODALITY(true),
|
||||
OVERRIDE(true),
|
||||
|
||||
@@ -90,7 +90,7 @@ internal class DescriptorRendererImpl(
|
||||
}
|
||||
|
||||
private fun renderName(descriptor: DeclarationDescriptor, builder: StringBuilder) {
|
||||
builder.append(renderName(descriptor.getName()))
|
||||
builder.append(renderName(descriptor.name))
|
||||
}
|
||||
|
||||
private fun renderCompanionObjectName(descriptor: DeclarationDescriptor, builder: StringBuilder) {
|
||||
@@ -99,15 +99,15 @@ internal class DescriptorRendererImpl(
|
||||
builder.append("companion object")
|
||||
}
|
||||
renderSpaceIfNeeded(builder)
|
||||
val containingDeclaration = descriptor.getContainingDeclaration()
|
||||
val containingDeclaration = descriptor.containingDeclaration
|
||||
if (containingDeclaration != null) {
|
||||
builder.append("of ")
|
||||
builder.append(renderName(containingDeclaration.getName()))
|
||||
builder.append(renderName(containingDeclaration.name))
|
||||
}
|
||||
}
|
||||
if (verbose || descriptor.name != SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT) {
|
||||
if (!startFromName) renderSpaceIfNeeded(builder)
|
||||
builder.append(renderName(descriptor.getName()))
|
||||
builder.append(renderName(descriptor.name))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ internal class DescriptorRendererImpl(
|
||||
return klass.fullFqName.asString()
|
||||
}
|
||||
if (ErrorUtils.isError(klass)) {
|
||||
return klass.getTypeConstructor().toString()
|
||||
return klass.typeConstructor.toString()
|
||||
}
|
||||
when (nameShortness) {
|
||||
NameShortness.SHORT -> {
|
||||
@@ -129,8 +129,8 @@ internal class DescriptorRendererImpl(
|
||||
// for nested classes qualified name should be used
|
||||
var current: DeclarationDescriptor? = klass
|
||||
do {
|
||||
qualifiedNameElements.add(current!!.getName())
|
||||
current = current.getContainingDeclaration()
|
||||
qualifiedNameElements.add(current!!.name)
|
||||
current = current.containingDeclaration
|
||||
}
|
||||
while (current is ClassDescriptor)
|
||||
|
||||
@@ -162,8 +162,8 @@ internal class DescriptorRendererImpl(
|
||||
return renderFlexibleTypeWithBothBounds(type.flexibility().lowerBound, type.flexibility().upperBound)
|
||||
}
|
||||
else if (flexibleTypesForCode) {
|
||||
val prefix = if (nameShortness == NameShortness.SHORT) "" else Flexibility.FLEXIBLE_TYPE_CLASSIFIER.getPackageFqName().asString() + "."
|
||||
return prefix + Flexibility.FLEXIBLE_TYPE_CLASSIFIER.getRelativeClassName() + lt() + renderNormalizedType(type.flexibility().lowerBound) + ", " + renderNormalizedType(type.flexibility().upperBound) + gt()
|
||||
val prefix = if (nameShortness == NameShortness.SHORT) "" else Flexibility.FLEXIBLE_TYPE_CLASSIFIER.packageFqName.asString() + "."
|
||||
return prefix + Flexibility.FLEXIBLE_TYPE_CLASSIFIER.relativeClassName + lt() + renderNormalizedType(type.flexibility().lowerBound) + ", " + renderNormalizedType(type.flexibility().upperBound) + gt()
|
||||
}
|
||||
else {
|
||||
return renderFlexibleType(type)
|
||||
@@ -189,11 +189,11 @@ internal class DescriptorRendererImpl(
|
||||
}
|
||||
if (ErrorUtils.isUninferredParameter(type)) {
|
||||
if (uninferredTypeParameterAsName) {
|
||||
return renderError((type.getConstructor() as UninferredParameterTypeConstructor).getTypeParameterDescriptor().getName().toString())
|
||||
return renderError((type.constructor as UninferredParameterTypeConstructor).typeParameterDescriptor.name.toString())
|
||||
}
|
||||
return "???"
|
||||
}
|
||||
if (type.isError()) {
|
||||
if (type.isError) {
|
||||
return renderDefaultType(type)
|
||||
}
|
||||
if (shouldRenderAsPrettyFunctionType(type)) {
|
||||
@@ -204,7 +204,7 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
private fun shouldRenderAsPrettyFunctionType(type: KotlinType): Boolean {
|
||||
return prettyFunctionTypes && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type)
|
||||
&& type.getArguments().none { it.isStarProjection() }
|
||||
&& type.arguments.none { it.isStarProjection }
|
||||
}
|
||||
|
||||
private fun renderFlexibleType(type: KotlinType): String {
|
||||
@@ -251,15 +251,15 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
renderAnnotations(type, sb, /* needBrackets = */ true)
|
||||
|
||||
if (type.isError()) {
|
||||
sb.append(type.getConstructor().toString()) // Debug name of an error type is more informative
|
||||
sb.append(renderTypeArguments(type.getArguments()))
|
||||
if (type.isError) {
|
||||
sb.append(type.constructor.toString()) // Debug name of an error type is more informative
|
||||
sb.append(renderTypeArguments(type.arguments))
|
||||
}
|
||||
else {
|
||||
sb.append(renderTypeConstructorAndArguments(type))
|
||||
}
|
||||
|
||||
if (type.isMarkedNullable()) {
|
||||
if (type.isMarkedNullable) {
|
||||
sb.append("?")
|
||||
}
|
||||
return sb.toString()
|
||||
@@ -295,7 +295,7 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
|
||||
override fun renderTypeConstructor(typeConstructor: TypeConstructor): String {
|
||||
val cd = typeConstructor.getDeclarationDescriptor()
|
||||
val cd = typeConstructor.declarationDescriptor
|
||||
return when (cd) {
|
||||
is TypeParameterDescriptor -> renderName(cd.getName())
|
||||
is ClassDescriptor -> renderClassifierName(cd)
|
||||
@@ -310,24 +310,24 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
private fun appendTypeProjections(typeProjections: List<TypeProjection>, builder: StringBuilder) {
|
||||
typeProjections.map {
|
||||
if (it.isStarProjection()) {
|
||||
if (it.isStarProjection) {
|
||||
"*"
|
||||
}
|
||||
else {
|
||||
val type = renderType(it.getType())
|
||||
if (it.getProjectionKind() == Variance.INVARIANT) type else "${it.getProjectionKind()} $type"
|
||||
val type = renderType(it.type)
|
||||
if (it.projectionKind == Variance.INVARIANT) type else "${it.projectionKind} $type"
|
||||
}
|
||||
}.joinTo(builder, ", ")
|
||||
}
|
||||
|
||||
private fun renderFunctionType(type: KotlinType): String {
|
||||
return buildString {
|
||||
val isNullable = type.isMarkedNullable()
|
||||
val isNullable = type.isMarkedNullable
|
||||
if (isNullable) append("(")
|
||||
|
||||
val receiverType = KotlinBuiltIns.getReceiverType(type)
|
||||
if (receiverType != null) {
|
||||
val surroundReceiver = shouldRenderAsPrettyFunctionType(receiverType) && !receiverType.isMarkedNullable()
|
||||
val surroundReceiver = shouldRenderAsPrettyFunctionType(receiverType) && !receiverType.isMarkedNullable
|
||||
if (surroundReceiver) {
|
||||
append("(")
|
||||
}
|
||||
@@ -375,9 +375,9 @@ internal class DescriptorRendererImpl(
|
||||
// See AnnotationResolver.resolveAndAppendAnnotationsFromModifiers for clarification
|
||||
// This hack can be removed when modifiers will be resolved without annotations
|
||||
|
||||
val sortedAnnotations = annotated.getAnnotations().getAllAnnotations()
|
||||
val sortedAnnotations = annotated.annotations.getAllAnnotations()
|
||||
for ((annotation, target) in sortedAnnotations) {
|
||||
val annotationClass = annotation.getType().getConstructor().getDeclarationDescriptor() as ClassDescriptor
|
||||
val annotationClass = annotation.type.constructor.declarationDescriptor as ClassDescriptor
|
||||
|
||||
if (!excluded.contains(DescriptorUtils.getFqNameSafe(annotationClass))) {
|
||||
append(renderAnnotation(annotation, target)).append(" ")
|
||||
@@ -394,7 +394,7 @@ internal class DescriptorRendererImpl(
|
||||
if (target != null) {
|
||||
append(target.renderName + ":")
|
||||
}
|
||||
append(renderType(annotation.getType()))
|
||||
append(renderType(annotation.type))
|
||||
if (verbose) {
|
||||
renderAndSortAnnotationArguments(annotation).joinTo(this, ", ", "(", ")")
|
||||
}
|
||||
@@ -402,17 +402,17 @@ internal class DescriptorRendererImpl(
|
||||
}
|
||||
|
||||
private fun renderAndSortAnnotationArguments(descriptor: AnnotationDescriptor): List<String> {
|
||||
val allValueArguments = descriptor.getAllValueArguments()
|
||||
val classDescriptor = if (renderDefaultAnnotationArguments) TypeUtils.getClassDescriptor(descriptor.getType()) else null
|
||||
val parameterDescriptorsWithDefaultValue = classDescriptor?.getUnsubstitutedPrimaryConstructor()?.getValueParameters()?.filter {
|
||||
val allValueArguments = descriptor.allValueArguments
|
||||
val classDescriptor = if (renderDefaultAnnotationArguments) TypeUtils.getClassDescriptor(descriptor.type) else null
|
||||
val parameterDescriptorsWithDefaultValue = classDescriptor?.unsubstitutedPrimaryConstructor?.valueParameters?.filter {
|
||||
it.declaresDefaultValue()
|
||||
} ?: emptyList()
|
||||
val defaultList = parameterDescriptorsWithDefaultValue.filter { !allValueArguments.containsKey(it) }.map {
|
||||
"${it.getName().asString()} = ..."
|
||||
"${it.name.asString()} = ..."
|
||||
}
|
||||
val argumentList = allValueArguments.entries
|
||||
.map { entry ->
|
||||
val name = entry.key.getName().asString()
|
||||
val name = entry.key.name.asString()
|
||||
val value = if (!parameterDescriptorsWithDefaultValue.contains(entry.key)) renderConstant(entry.value) else "..."
|
||||
"$name = $value"
|
||||
}
|
||||
@@ -457,11 +457,11 @@ internal class DescriptorRendererImpl(
|
||||
}
|
||||
|
||||
private fun renderModalityForCallable(callable: CallableMemberDescriptor, builder: StringBuilder) {
|
||||
if (!DescriptorUtils.isTopLevelDeclaration(callable) || callable.getModality() != Modality.FINAL) {
|
||||
if (overridesSomething(callable) && overrideRenderingPolicy == OverrideRenderingPolicy.RENDER_OVERRIDE && callable.getModality() == Modality.OPEN) {
|
||||
if (!DescriptorUtils.isTopLevelDeclaration(callable) || callable.modality != Modality.FINAL) {
|
||||
if (overridesSomething(callable) && overrideRenderingPolicy == OverrideRenderingPolicy.RENDER_OVERRIDE && callable.modality == Modality.OPEN) {
|
||||
return
|
||||
}
|
||||
renderModality(callable.getModality(), builder)
|
||||
renderModality(callable.modality, builder)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,7 +471,7 @@ internal class DescriptorRendererImpl(
|
||||
if (overrideRenderingPolicy != OverrideRenderingPolicy.RENDER_OPEN) {
|
||||
builder.append("override ")
|
||||
if (verbose) {
|
||||
builder.append("/*").append(callableMember.getOverriddenDescriptors().size).append("*/ ")
|
||||
builder.append("/*").append(callableMember.overriddenDescriptors.size).append("*/ ")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -479,8 +479,8 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
private fun renderMemberKind(callableMember: CallableMemberDescriptor, builder: StringBuilder) {
|
||||
if (DescriptorRendererModifier.MEMBER_KIND !in modifiers) return
|
||||
if (verbose && callableMember.getKind() != CallableMemberDescriptor.Kind.DECLARATION) {
|
||||
builder.append("/*").append(callableMember.getKind().name.toLowerCase()).append("*/ ")
|
||||
if (verbose && callableMember.kind != CallableMemberDescriptor.Kind.DECLARATION) {
|
||||
builder.append("/*").append(callableMember.kind.name.toLowerCase()).append("*/ ")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -526,27 +526,27 @@ internal class DescriptorRendererImpl(
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
builder.append("/*").append(typeParameter.getIndex()).append("*/ ")
|
||||
builder.append("/*").append(typeParameter.index).append("*/ ")
|
||||
}
|
||||
|
||||
if (typeParameter.isReified()) {
|
||||
if (typeParameter.isReified) {
|
||||
builder.append(renderKeyword("reified")).append(" ")
|
||||
}
|
||||
val variance = typeParameter.getVariance().label
|
||||
val variance = typeParameter.variance.label
|
||||
if (!variance.isEmpty()) {
|
||||
builder.append(renderKeyword(variance)).append(" ")
|
||||
}
|
||||
renderName(typeParameter, builder)
|
||||
val upperBoundsCount = typeParameter.getUpperBounds().size
|
||||
val upperBoundsCount = typeParameter.upperBounds.size
|
||||
if ((upperBoundsCount > 1 && !topLevel) || upperBoundsCount == 1) {
|
||||
val upperBound = typeParameter.getUpperBounds().iterator().next()
|
||||
val upperBound = typeParameter.upperBounds.iterator().next()
|
||||
if (!KotlinBuiltIns.isDefaultBound(upperBound)) {
|
||||
builder.append(" : ").append(renderType(upperBound))
|
||||
}
|
||||
}
|
||||
else if (topLevel) {
|
||||
var first = true
|
||||
for (upperBound in typeParameter.getUpperBounds()) {
|
||||
for (upperBound in typeParameter.upperBounds) {
|
||||
if (KotlinBuiltIns.isDefaultBound(upperBound)) {
|
||||
continue
|
||||
}
|
||||
@@ -597,7 +597,7 @@ internal class DescriptorRendererImpl(
|
||||
private fun renderFunction(function: FunctionDescriptor, builder: StringBuilder) {
|
||||
if (!startFromName) {
|
||||
renderAnnotations(function, builder)
|
||||
renderVisibility(function.getVisibility(), builder)
|
||||
renderVisibility(function.visibility, builder)
|
||||
renderModalityForCallable(function, builder)
|
||||
renderAdditionalModifiers(function, builder)
|
||||
renderOverride(function, builder)
|
||||
@@ -608,7 +608,7 @@ internal class DescriptorRendererImpl(
|
||||
}
|
||||
|
||||
builder.append(renderKeyword("fun")).append(" ")
|
||||
renderTypeParameters(function.getTypeParameters(), builder, true)
|
||||
renderTypeParameters(function.typeParameters, builder, true)
|
||||
renderReceiver(function, builder)
|
||||
}
|
||||
|
||||
@@ -618,27 +618,27 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
renderReceiverAfterName(function, builder)
|
||||
|
||||
val returnType = function.getReturnType()
|
||||
val returnType = function.returnType
|
||||
if (!withoutReturnType && (unitReturnType || (returnType == null || !KotlinBuiltIns.isUnit(returnType)))) {
|
||||
builder.append(": ").append(if (returnType == null) "[NULL]" else escape(renderType(returnType)))
|
||||
}
|
||||
|
||||
renderWhereSuffix(function.getTypeParameters(), builder)
|
||||
renderWhereSuffix(function.typeParameters, builder)
|
||||
}
|
||||
|
||||
private fun renderReceiverAfterName(callableDescriptor: CallableDescriptor, builder: StringBuilder) {
|
||||
if (!receiverAfterName) return
|
||||
|
||||
val receiver = callableDescriptor.getExtensionReceiverParameter()
|
||||
val receiver = callableDescriptor.extensionReceiverParameter
|
||||
if (receiver != null) {
|
||||
builder.append(" on ").append(escape(renderType(receiver.getType())))
|
||||
builder.append(" on ").append(escape(renderType(receiver.type)))
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderReceiver(callableDescriptor: CallableDescriptor, builder: StringBuilder) {
|
||||
val receiver = callableDescriptor.getExtensionReceiverParameter()
|
||||
val receiver = callableDescriptor.extensionReceiverParameter
|
||||
if (receiver != null) {
|
||||
val type = receiver.getType()
|
||||
val type = receiver.type
|
||||
var result = escape(renderType(type))
|
||||
if (shouldRenderAsPrettyFunctionType(type) && !TypeUtils.isNullableType(type)) {
|
||||
result = "($result)"
|
||||
@@ -649,12 +649,12 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
private fun renderConstructor(constructor: ConstructorDescriptor, builder: StringBuilder) {
|
||||
renderAnnotations(constructor, builder)
|
||||
renderVisibility(constructor.getVisibility(), builder)
|
||||
renderVisibility(constructor.visibility, builder)
|
||||
renderMemberKind(constructor, builder)
|
||||
|
||||
builder.append(renderKeyword("constructor"))
|
||||
if (secondaryConstructorsAsPrimary) {
|
||||
val classDescriptor = constructor.getContainingDeclaration()
|
||||
val classDescriptor = constructor.containingDeclaration
|
||||
builder.append(" ")
|
||||
renderName(classDescriptor, builder)
|
||||
renderTypeParameters(classDescriptor.declaredTypeParameters, builder, false)
|
||||
@@ -663,7 +663,7 @@ internal class DescriptorRendererImpl(
|
||||
renderValueParameters(constructor.valueParameters, constructor.hasSynthesizedParameterNames(), builder)
|
||||
|
||||
if (secondaryConstructorsAsPrimary) {
|
||||
renderWhereSuffix(constructor.getTypeParameters(), builder)
|
||||
renderWhereSuffix(constructor.typeParameters, builder)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -673,9 +673,9 @@ internal class DescriptorRendererImpl(
|
||||
val upperBoundStrings = ArrayList<String>(0)
|
||||
|
||||
for (typeParameter in typeParameters) {
|
||||
typeParameter.getUpperBounds()
|
||||
typeParameter.upperBounds
|
||||
.drop(1) // first parameter is rendered by renderTypeParameter
|
||||
.mapTo(upperBoundStrings) { renderName(typeParameter.getName()) + " : " + escape(renderType(it)) }
|
||||
.mapTo(upperBoundStrings) { renderName(typeParameter.name) + " : " + escape(renderType(it)) }
|
||||
}
|
||||
|
||||
if (!upperBoundStrings.isEmpty()) {
|
||||
@@ -736,11 +736,11 @@ internal class DescriptorRendererImpl(
|
||||
}
|
||||
|
||||
private fun renderValVarPrefix(variable: VariableDescriptor, builder: StringBuilder) {
|
||||
builder.append(renderKeyword(if (variable.isVar()) "var" else "val")).append(" ")
|
||||
builder.append(renderKeyword(if (variable.isVar) "var" else "val")).append(" ")
|
||||
}
|
||||
|
||||
private fun renderVariable(variable: VariableDescriptor, includeName: Boolean, builder: StringBuilder, topLevel: Boolean) {
|
||||
val realType = variable.getType()
|
||||
val realType = variable.type
|
||||
|
||||
val varargElementType = (variable as? ValueParameterDescriptor)?.varargElementType
|
||||
val typeToRender = varargElementType ?: realType
|
||||
@@ -769,7 +769,7 @@ internal class DescriptorRendererImpl(
|
||||
private fun renderProperty(property: PropertyDescriptor, builder: StringBuilder) {
|
||||
if (!startFromName) {
|
||||
renderAnnotations(property, builder)
|
||||
renderVisibility(property.getVisibility(), builder)
|
||||
renderVisibility(property.visibility, builder)
|
||||
|
||||
if (property.isConst) {
|
||||
builder.append("const ")
|
||||
@@ -780,23 +780,23 @@ internal class DescriptorRendererImpl(
|
||||
renderLateInit(property, builder)
|
||||
renderMemberKind(property, builder)
|
||||
renderValVarPrefix(property, builder)
|
||||
renderTypeParameters(property.getTypeParameters(), builder, true)
|
||||
renderTypeParameters(property.typeParameters, builder, true)
|
||||
renderReceiver(property, builder)
|
||||
}
|
||||
|
||||
renderName(property, builder)
|
||||
builder.append(": ").append(escape(renderType(property.getType())))
|
||||
builder.append(": ").append(escape(renderType(property.type)))
|
||||
|
||||
renderReceiverAfterName(property, builder)
|
||||
|
||||
renderInitializer(property, builder)
|
||||
|
||||
renderWhereSuffix(property.getTypeParameters(), builder)
|
||||
renderWhereSuffix(property.typeParameters, builder)
|
||||
}
|
||||
|
||||
private fun renderInitializer(variable: VariableDescriptor, builder: StringBuilder) {
|
||||
if (includePropertyConstant) {
|
||||
variable.getCompileTimeInitializer()?.let { constant ->
|
||||
variable.compileTimeInitializer?.let { constant ->
|
||||
builder.append(" = ").append(escape(renderConstant(constant)))
|
||||
}
|
||||
}
|
||||
@@ -861,7 +861,7 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
if (KotlinBuiltIns.isNothing(klass.defaultType)) return
|
||||
|
||||
val supertypes = klass.getTypeConstructor().getSupertypes()
|
||||
val supertypes = klass.typeConstructor.supertypes
|
||||
if (supertypes.isEmpty() || supertypes.size == 1 && KotlinBuiltIns.isAnyOrNullableAny(supertypes.iterator().next())) return
|
||||
|
||||
renderSpaceIfNeeded(builder)
|
||||
@@ -890,7 +890,7 @@ internal class DescriptorRendererImpl(
|
||||
builder.append(renderFqName(fragment.fqName.toUnsafe()))
|
||||
if (debugMode) {
|
||||
builder.append(" in ")
|
||||
renderName(fragment.getContainingDeclaration(), builder)
|
||||
renderName(fragment.containingDeclaration, builder)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -918,7 +918,7 @@ internal class DescriptorRendererImpl(
|
||||
if (renderAccessors) {
|
||||
renderAccessorModifiers(descriptor, builder)
|
||||
builder.append("getter for ")
|
||||
renderProperty(descriptor.getCorrespondingProperty(), builder)
|
||||
renderProperty(descriptor.correspondingProperty, builder)
|
||||
}
|
||||
else {
|
||||
visitFunctionDescriptor(descriptor, builder)
|
||||
@@ -930,7 +930,7 @@ internal class DescriptorRendererImpl(
|
||||
if (renderAccessors) {
|
||||
renderAccessorModifiers(descriptor, builder)
|
||||
builder.append("setter for ")
|
||||
renderProperty(descriptor.getCorrespondingProperty(), builder)
|
||||
renderProperty(descriptor.correspondingProperty, builder)
|
||||
}
|
||||
else {
|
||||
visitFunctionDescriptor(descriptor, builder)
|
||||
@@ -999,5 +999,5 @@ internal class DescriptorRendererImpl(
|
||||
private fun differsOnlyInNullability(lower: String, upper: String)
|
||||
= lower == upper.replace("?", "") || upper.endsWith("?") && ("$lower?") == upper || "($lower)?" == upper
|
||||
|
||||
private fun overridesSomething(callable: CallableMemberDescriptor) = !callable.getOverriddenDescriptors().isEmpty()
|
||||
private fun overridesSomething(callable: CallableMemberDescriptor) = !callable.overriddenDescriptors.isEmpty()
|
||||
}
|
||||
|
||||
@@ -25,15 +25,15 @@ import kotlin.properties.ObservableProperty
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
|
||||
internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions {
|
||||
public var isLocked: Boolean = false
|
||||
var isLocked: Boolean = false
|
||||
private set
|
||||
|
||||
public fun lock() {
|
||||
fun lock() {
|
||||
assert(!isLocked)
|
||||
isLocked = true
|
||||
}
|
||||
|
||||
public fun copy(): DescriptorRendererOptionsImpl {
|
||||
fun copy(): DescriptorRendererOptionsImpl {
|
||||
val copy = DescriptorRendererOptionsImpl()
|
||||
|
||||
//TODO: use Kotlin reflection
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user