This commit is contained in:
Valentin Kipyatkov
2015-07-14 15:52:14 +03:00
parent be5c0ea28b
commit f5e7483d19
6 changed files with 25 additions and 25 deletions
@@ -76,7 +76,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature; import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature; import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
import org.jetbrains.kotlin.resolve.scopes.receivers.*; import org.jetbrains.kotlin.resolve.scopes.receivers.*;
import org.jetbrains.kotlin.synthetic.SyntheticExtensionPropertyDescriptor; import org.jetbrains.kotlin.synthetic.SyntheticJavaBeansPropertyDescriptor;
import org.jetbrains.kotlin.types.JetType; import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.TypeProjection; import org.jetbrains.kotlin.types.TypeProjection;
import org.jetbrains.kotlin.types.TypeUtils; import org.jetbrains.kotlin.types.TypeUtils;
@@ -2145,8 +2145,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
@NotNull MethodKind methodKind, @NotNull MethodKind methodKind,
StackValue receiver StackValue receiver
) { ) {
if (propertyDescriptor instanceof SyntheticExtensionPropertyDescriptor) { if (propertyDescriptor instanceof SyntheticJavaBeansPropertyDescriptor) {
return intermediateValueForSyntheticExtensionProperty((SyntheticExtensionPropertyDescriptor) propertyDescriptor, receiver); return intermediateValueForSyntheticExtensionProperty((SyntheticJavaBeansPropertyDescriptor) propertyDescriptor, receiver);
} }
DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration(); DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
@@ -2242,7 +2242,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
} }
@NotNull @NotNull
private StackValue.Property intermediateValueForSyntheticExtensionProperty(@NotNull SyntheticExtensionPropertyDescriptor propertyDescriptor, StackValue receiver) { private StackValue.Property intermediateValueForSyntheticExtensionProperty(@NotNull SyntheticJavaBeansPropertyDescriptor propertyDescriptor, StackValue receiver) {
Type type = typeMapper.mapType(propertyDescriptor.getOriginal().getType()); Type type = typeMapper.mapType(propertyDescriptor.getOriginal().getType());
CallableMethod callableGetter = typeMapper.mapToCallableMethod(propertyDescriptor.getGetMethod(), false, context); CallableMethod callableGetter = typeMapper.mapToCallableMethod(propertyDescriptor.getGetMethod(), false, context);
FunctionDescriptor setMethod = propertyDescriptor.getSetMethod(); FunctionDescriptor setMethod = propertyDescriptor.getSetMethod();
@@ -37,12 +37,12 @@ import org.jetbrains.kotlin.utils.addIfNotNull
import java.beans.Introspector import java.beans.Introspector
import java.util.ArrayList import java.util.ArrayList
interface SyntheticExtensionPropertyDescriptor : PropertyDescriptor { interface SyntheticJavaBeansPropertyDescriptor : PropertyDescriptor {
val getMethod: FunctionDescriptor val getMethod: FunctionDescriptor
val setMethod: FunctionDescriptor? val setMethod: FunctionDescriptor?
companion object { companion object {
fun findByGetterOrSetter(getterOrSetter: FunctionDescriptor, resolutionScope: JetScope): SyntheticExtensionPropertyDescriptor? { fun findByGetterOrSetter(getterOrSetter: FunctionDescriptor, resolutionScope: JetScope): SyntheticJavaBeansPropertyDescriptor? {
val name = getterOrSetter.getName() val name = getterOrSetter.getName()
if (propertyNameByGetMethodName(name) == null && propertyNameBySetMethodName(name) == null) return null // optimization if (propertyNameByGetMethodName(name) == null && propertyNameBySetMethodName(name) == null) return null // optimization
@@ -50,7 +50,7 @@ interface SyntheticExtensionPropertyDescriptor : PropertyDescriptor {
if (owner !is JavaClassDescriptor) return null if (owner !is JavaClassDescriptor) return null
return resolutionScope.getSyntheticExtensionProperties(owner.getDefaultType()) return resolutionScope.getSyntheticExtensionProperties(owner.getDefaultType())
.filterIsInstance<SyntheticExtensionPropertyDescriptor>() .filterIsInstance<SyntheticJavaBeansPropertyDescriptor>()
.firstOrNull { getterOrSetter == it.getMethod || getterOrSetter == it.setMethod } .firstOrNull { getterOrSetter == it.getMethod || getterOrSetter == it.setMethod }
} }
@@ -72,12 +72,12 @@ interface SyntheticExtensionPropertyDescriptor : PropertyDescriptor {
} }
class AdditionalScopesWithSyntheticExtensions(storageManager: StorageManager) : FileScopeProvider.AdditionalScopes() { class AdditionalScopesWithSyntheticExtensions(storageManager: StorageManager) : FileScopeProvider.AdditionalScopes() {
private val scope = SyntheticExtensionsScope(storageManager) private val scope = JavaBeansExtensionsScope(storageManager)
override fun scopes(file: JetFile) = listOf(scope) override fun scopes(file: JetFile) = listOf(scope)
} }
class SyntheticExtensionsScope(storageManager: StorageManager) : JetScope by JetScope.Empty { class JavaBeansExtensionsScope(storageManager: StorageManager) : JetScope by JetScope.Empty {
private val syntheticPropertyInClass = storageManager.createMemoizedFunctionWithNullableValues<Triple<JavaClassDescriptor, JetType, Name>, PropertyDescriptor> { triple -> private val syntheticPropertyInClass = storageManager.createMemoizedFunctionWithNullableValues<Triple<JavaClassDescriptor, JetType, Name>, PropertyDescriptor> { triple ->
syntheticPropertyInClassNotCached(triple.first, triple.second, triple.third) syntheticPropertyInClassNotCached(triple.first, triple.second, triple.third)
} }
@@ -157,7 +157,7 @@ class SyntheticExtensionsScope(storageManager: StorageManager) : JetScope by Jet
if (classifier is JavaClassDescriptor) { if (classifier is JavaClassDescriptor) {
for (descriptor in classifier.getMemberScope(type.getArguments()).getAllDescriptors()) { for (descriptor in classifier.getMemberScope(type.getArguments()).getAllDescriptors()) {
if (descriptor is FunctionDescriptor) { if (descriptor is FunctionDescriptor) {
val propertyName = SyntheticExtensionPropertyDescriptor.propertyNameByGetMethodName(descriptor.getName()) ?: continue val propertyName = SyntheticJavaBeansPropertyDescriptor.propertyNameByGetMethodName(descriptor.getName()) ?: continue
addIfNotNull(syntheticPropertyInClass(Triple(classifier, type, propertyName))) addIfNotNull(syntheticPropertyInClass(Triple(classifier, type, propertyName)))
} }
} }
@@ -191,7 +191,7 @@ class SyntheticExtensionsScope(storageManager: StorageManager) : JetScope by Jet
name: Name, name: Name,
type: JetType, type: JetType,
receiverType: JetType receiverType: JetType
) : SyntheticExtensionPropertyDescriptor, PropertyDescriptorImpl( ) : SyntheticJavaBeansPropertyDescriptor, PropertyDescriptorImpl(
DescriptorUtils.getContainingModule(javaClass)/* TODO:is it ok? */, DescriptorUtils.getContainingModule(javaClass)/* TODO:is it ok? */,
null, null,
Annotations.EMPTY, Annotations.EMPTY,
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.synthetic.SyntheticExtensionPropertyDescriptor import org.jetbrains.kotlin.synthetic.SyntheticJavaBeansPropertyDescriptor
import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.checker.JetTypeChecker import org.jetbrains.kotlin.types.checker.JetTypeChecker
@@ -75,7 +75,7 @@ public class ReferenceVariantsHelper(
if (filterOutJavaGettersAndSetters) { if (filterOutJavaGettersAndSetters) {
val accessorMethodsToRemove = HashSet<FunctionDescriptor>() val accessorMethodsToRemove = HashSet<FunctionDescriptor>()
for (variant in variants) { for (variant in variants) {
if (variant is SyntheticExtensionPropertyDescriptor) { if (variant is SyntheticJavaBeansPropertyDescriptor) {
accessorMethodsToRemove.add(variant.getMethod) accessorMethodsToRemove.add(variant.getMethod)
accessorMethodsToRemove.addIfNotNull(variant.setMethod) accessorMethodsToRemove.addIfNotNull(variant.setMethod)
} }
@@ -26,17 +26,17 @@ import org.jetbrains.kotlin.psi.JetNameReferenceExpression
import org.jetbrains.kotlin.psi.JetPsiFactory import org.jetbrains.kotlin.psi.JetPsiFactory
import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.synthetic.SyntheticExtensionPropertyDescriptor import org.jetbrains.kotlin.synthetic.SyntheticJavaBeansPropertyDescriptor
import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addIfNotNull
sealed class SyntheticPropertyAccessorReference(expression: JetNameReferenceExpression, private val getter: Boolean) : JetSimpleReference<JetNameReferenceExpression>(expression) { sealed class SyntheticPropertyAccessorReference(expression: JetNameReferenceExpression, private val getter: Boolean) : JetSimpleReference<JetNameReferenceExpression>(expression) {
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> { override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
val descriptors = super.getTargetDescriptors(context) val descriptors = super.getTargetDescriptors(context)
if (descriptors.none { it is SyntheticExtensionPropertyDescriptor }) return emptyList() if (descriptors.none { it is SyntheticJavaBeansPropertyDescriptor }) return emptyList()
val result = SmartList<FunctionDescriptor>() val result = SmartList<FunctionDescriptor>()
for (descriptor in descriptors) { for (descriptor in descriptors) {
if (descriptor is SyntheticExtensionPropertyDescriptor) { if (descriptor is SyntheticJavaBeansPropertyDescriptor) {
if (getter) { if (getter) {
result.add(descriptor.getMethod) result.add(descriptor.getMethod)
} }
@@ -57,9 +57,9 @@ sealed class SyntheticPropertyAccessorReference(expression: JetNameReferenceExpr
val newNameAsName = Name.identifier(newElementName) val newNameAsName = Name.identifier(newElementName)
val newName = if (getter) val newName = if (getter)
SyntheticExtensionPropertyDescriptor.propertyNameByGetMethodName(newNameAsName) SyntheticJavaBeansPropertyDescriptor.propertyNameByGetMethodName(newNameAsName)
else else
SyntheticExtensionPropertyDescriptor.propertyNameBySetMethodName(newNameAsName) SyntheticJavaBeansPropertyDescriptor.propertyNameBySetMethodName(newNameAsName)
if (newName == null) return expression //TODO: handle the case when get/set becomes ordinary method if (newName == null) return expression //TODO: handle the case when get/set becomes ordinary method
val nameIdentifier = JetPsiFactory(expression).createNameIdentifier(newName.getIdentifier()) val nameIdentifier = JetPsiFactory(expression).createNameIdentifier(newName.getIdentifier())
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.JetScope import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.synthetic.SyntheticExtensionPropertyDescriptor import org.jetbrains.kotlin.synthetic.SyntheticJavaBeansPropertyDescriptor
class UsePropertyAccessSyntaxInspection : IntentionBasedInspection<JetCallExpression>(UsePropertyAccessSyntaxIntention()) class UsePropertyAccessSyntaxInspection : IntentionBasedInspection<JetCallExpression>(UsePropertyAccessSyntaxIntention())
@@ -87,8 +87,8 @@ class UsePropertyAccessSyntaxIntention : JetSelfTargetingOffsetIndependentIntent
return property return property
} }
private fun findSyntheticProperty(function: FunctionDescriptor, resolutionScope: JetScope): SyntheticExtensionPropertyDescriptor? { private fun findSyntheticProperty(function: FunctionDescriptor, resolutionScope: JetScope): SyntheticJavaBeansPropertyDescriptor? {
SyntheticExtensionPropertyDescriptor.findByGetterOrSetter(function, resolutionScope)?.let { return it } SyntheticJavaBeansPropertyDescriptor.findByGetterOrSetter(function, resolutionScope)?.let { return it }
for (overridden in function.getOverriddenDescriptors()) { for (overridden in function.getOverriddenDescriptors()) {
findSyntheticProperty(overridden, resolutionScope)?.let { return it } findSyntheticProperty(overridden, resolutionScope)?.let { return it }
@@ -29,8 +29,8 @@ import org.jetbrains.kotlin.idea.JetFileType
import org.jetbrains.kotlin.idea.caches.resolve.getJavaMethodDescriptor import org.jetbrains.kotlin.idea.caches.resolve.getJavaMethodDescriptor
import org.jetbrains.kotlin.psi.JetProperty import org.jetbrains.kotlin.psi.JetProperty
import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.synthetic.SyntheticExtensionPropertyDescriptor import org.jetbrains.kotlin.synthetic.SyntheticJavaBeansPropertyDescriptor
import org.jetbrains.kotlin.synthetic.SyntheticExtensionsScope import org.jetbrains.kotlin.synthetic.JavaBeansExtensionsScope
public class KotlinPropertyAccessorsReferenceSearcher() : QueryExecutorBase<PsiReference, MethodReferencesSearch.SearchParameters>(true) { public class KotlinPropertyAccessorsReferenceSearcher() : QueryExecutorBase<PsiReference, MethodReferencesSearch.SearchParameters>(true) {
override fun processQuery(queryParameters: MethodReferencesSearch.SearchParameters, consumer: Processor<PsiReference>) { override fun processQuery(queryParameters: MethodReferencesSearch.SearchParameters, consumer: Processor<PsiReference>) {
@@ -54,8 +54,8 @@ public class KotlinPropertyAccessorsReferenceSearcher() : QueryExecutorBase<PsiR
} }
val functionDescriptor = method.getJavaMethodDescriptor() ?: return null val functionDescriptor = method.getJavaMethodDescriptor() ?: return null
val syntheticExtensionsScope = SyntheticExtensionsScope(LockBasedStorageManager()) val syntheticExtensionsScope = JavaBeansExtensionsScope(LockBasedStorageManager())
val property = SyntheticExtensionPropertyDescriptor.findByGetterOrSetter(functionDescriptor, syntheticExtensionsScope) ?: return null val property = SyntheticJavaBeansPropertyDescriptor.findByGetterOrSetter(functionDescriptor, syntheticExtensionsScope) ?: return null
return property.getName().asString() return property.getName().asString()
} }