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.JvmMethodSignature;
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.TypeProjection;
import org.jetbrains.kotlin.types.TypeUtils;
@@ -2145,8 +2145,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
@NotNull MethodKind methodKind,
StackValue receiver
) {
if (propertyDescriptor instanceof SyntheticExtensionPropertyDescriptor) {
return intermediateValueForSyntheticExtensionProperty((SyntheticExtensionPropertyDescriptor) propertyDescriptor, receiver);
if (propertyDescriptor instanceof SyntheticJavaBeansPropertyDescriptor) {
return intermediateValueForSyntheticExtensionProperty((SyntheticJavaBeansPropertyDescriptor) propertyDescriptor, receiver);
}
DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
@@ -2242,7 +2242,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
@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());
CallableMethod callableGetter = typeMapper.mapToCallableMethod(propertyDescriptor.getGetMethod(), false, context);
FunctionDescriptor setMethod = propertyDescriptor.getSetMethod();
@@ -37,12 +37,12 @@ import org.jetbrains.kotlin.utils.addIfNotNull
import java.beans.Introspector
import java.util.ArrayList
interface SyntheticExtensionPropertyDescriptor : PropertyDescriptor {
interface SyntheticJavaBeansPropertyDescriptor : PropertyDescriptor {
val getMethod: FunctionDescriptor
val setMethod: FunctionDescriptor?
companion object {
fun findByGetterOrSetter(getterOrSetter: FunctionDescriptor, resolutionScope: JetScope): SyntheticExtensionPropertyDescriptor? {
fun findByGetterOrSetter(getterOrSetter: FunctionDescriptor, resolutionScope: JetScope): SyntheticJavaBeansPropertyDescriptor? {
val name = getterOrSetter.getName()
if (propertyNameByGetMethodName(name) == null && propertyNameBySetMethodName(name) == null) return null // optimization
@@ -50,7 +50,7 @@ interface SyntheticExtensionPropertyDescriptor : PropertyDescriptor {
if (owner !is JavaClassDescriptor) return null
return resolutionScope.getSyntheticExtensionProperties(owner.getDefaultType())
.filterIsInstance<SyntheticExtensionPropertyDescriptor>()
.filterIsInstance<SyntheticJavaBeansPropertyDescriptor>()
.firstOrNull { getterOrSetter == it.getMethod || getterOrSetter == it.setMethod }
}
@@ -72,12 +72,12 @@ interface SyntheticExtensionPropertyDescriptor : PropertyDescriptor {
}
class AdditionalScopesWithSyntheticExtensions(storageManager: StorageManager) : FileScopeProvider.AdditionalScopes() {
private val scope = SyntheticExtensionsScope(storageManager)
private val scope = JavaBeansExtensionsScope(storageManager)
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 ->
syntheticPropertyInClassNotCached(triple.first, triple.second, triple.third)
}
@@ -157,7 +157,7 @@ class SyntheticExtensionsScope(storageManager: StorageManager) : JetScope by Jet
if (classifier is JavaClassDescriptor) {
for (descriptor in classifier.getMemberScope(type.getArguments()).getAllDescriptors()) {
if (descriptor is FunctionDescriptor) {
val propertyName = SyntheticExtensionPropertyDescriptor.propertyNameByGetMethodName(descriptor.getName()) ?: continue
val propertyName = SyntheticJavaBeansPropertyDescriptor.propertyNameByGetMethodName(descriptor.getName()) ?: continue
addIfNotNull(syntheticPropertyInClass(Triple(classifier, type, propertyName)))
}
}
@@ -191,7 +191,7 @@ class SyntheticExtensionsScope(storageManager: StorageManager) : JetScope by Jet
name: Name,
type: JetType,
receiverType: JetType
) : SyntheticExtensionPropertyDescriptor, PropertyDescriptorImpl(
) : SyntheticJavaBeansPropertyDescriptor, PropertyDescriptorImpl(
DescriptorUtils.getContainingModule(javaClass)/* TODO:is it ok? */,
null,
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.receivers.ExpressionReceiver
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.TypeUtils
import org.jetbrains.kotlin.types.checker.JetTypeChecker
@@ -75,7 +75,7 @@ public class ReferenceVariantsHelper(
if (filterOutJavaGettersAndSetters) {
val accessorMethodsToRemove = HashSet<FunctionDescriptor>()
for (variant in variants) {
if (variant is SyntheticExtensionPropertyDescriptor) {
if (variant is SyntheticJavaBeansPropertyDescriptor) {
accessorMethodsToRemove.add(variant.getMethod)
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.psiUtil.startOffset
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.synthetic.SyntheticExtensionPropertyDescriptor
import org.jetbrains.kotlin.synthetic.SyntheticJavaBeansPropertyDescriptor
import org.jetbrains.kotlin.utils.addIfNotNull
sealed class SyntheticPropertyAccessorReference(expression: JetNameReferenceExpression, private val getter: Boolean) : JetSimpleReference<JetNameReferenceExpression>(expression) {
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
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>()
for (descriptor in descriptors) {
if (descriptor is SyntheticExtensionPropertyDescriptor) {
if (descriptor is SyntheticJavaBeansPropertyDescriptor) {
if (getter) {
result.add(descriptor.getMethod)
}
@@ -57,9 +57,9 @@ sealed class SyntheticPropertyAccessorReference(expression: JetNameReferenceExpr
val newNameAsName = Name.identifier(newElementName)
val newName = if (getter)
SyntheticExtensionPropertyDescriptor.propertyNameByGetMethodName(newNameAsName)
SyntheticJavaBeansPropertyDescriptor.propertyNameByGetMethodName(newNameAsName)
else
SyntheticExtensionPropertyDescriptor.propertyNameBySetMethodName(newNameAsName)
SyntheticJavaBeansPropertyDescriptor.propertyNameBySetMethodName(newNameAsName)
if (newName == null) return expression //TODO: handle the case when get/set becomes ordinary method
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.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.synthetic.SyntheticExtensionPropertyDescriptor
import org.jetbrains.kotlin.synthetic.SyntheticJavaBeansPropertyDescriptor
class UsePropertyAccessSyntaxInspection : IntentionBasedInspection<JetCallExpression>(UsePropertyAccessSyntaxIntention())
@@ -87,8 +87,8 @@ class UsePropertyAccessSyntaxIntention : JetSelfTargetingOffsetIndependentIntent
return property
}
private fun findSyntheticProperty(function: FunctionDescriptor, resolutionScope: JetScope): SyntheticExtensionPropertyDescriptor? {
SyntheticExtensionPropertyDescriptor.findByGetterOrSetter(function, resolutionScope)?.let { return it }
private fun findSyntheticProperty(function: FunctionDescriptor, resolutionScope: JetScope): SyntheticJavaBeansPropertyDescriptor? {
SyntheticJavaBeansPropertyDescriptor.findByGetterOrSetter(function, resolutionScope)?.let { return it }
for (overridden in function.getOverriddenDescriptors()) {
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.psi.JetProperty
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.synthetic.SyntheticExtensionPropertyDescriptor
import org.jetbrains.kotlin.synthetic.SyntheticExtensionsScope
import org.jetbrains.kotlin.synthetic.SyntheticJavaBeansPropertyDescriptor
import org.jetbrains.kotlin.synthetic.JavaBeansExtensionsScope
public class KotlinPropertyAccessorsReferenceSearcher() : QueryExecutorBase<PsiReference, MethodReferencesSearch.SearchParameters>(true) {
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 syntheticExtensionsScope = SyntheticExtensionsScope(LockBasedStorageManager())
val property = SyntheticExtensionPropertyDescriptor.findByGetterOrSetter(functionDescriptor, syntheticExtensionsScope) ?: return null
val syntheticExtensionsScope = JavaBeansExtensionsScope(LockBasedStorageManager())
val property = SyntheticJavaBeansPropertyDescriptor.findByGetterOrSetter(functionDescriptor, syntheticExtensionsScope) ?: return null
return property.getName().asString()
}