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)
|
||||
|
||||
Reference in New Issue
Block a user