More correct detection of super property
This commit is contained in:
@@ -16,13 +16,23 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.j2k
|
package org.jetbrains.kotlin.idea.j2k
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiMethod
|
||||||
import org.jetbrains.kotlin.j2k.*
|
import org.jetbrains.kotlin.j2k.*
|
||||||
|
|
||||||
object IdeaJavaToKotlinServices: JavaToKotlinConverterServices {
|
object IdeaJavaToKotlinServices : JavaToKotlinConverterServices {
|
||||||
override val referenceSearcher: ReferenceSearcher
|
override val referenceSearcher: ReferenceSearcher
|
||||||
get() = IdeaReferenceSearcher
|
get() = IdeaReferenceSearcher
|
||||||
|
|
||||||
|
override val superMethodsSearcher: SuperMethodsSearcher
|
||||||
|
get() = IdeaSuperMethodSearcher
|
||||||
|
|
||||||
override val resolverForConverter: ResolverForConverter
|
override val resolverForConverter: ResolverForConverter
|
||||||
get() = IdeaResolverForConverter
|
get() = IdeaResolverForConverter
|
||||||
|
|
||||||
override val docCommentConverter: DocCommentConverter
|
override val docCommentConverter: DocCommentConverter
|
||||||
get() = IdeaDocCommentConverter
|
get() = IdeaDocCommentConverter
|
||||||
|
}
|
||||||
|
|
||||||
|
object IdeaSuperMethodSearcher : SuperMethodsSearcher {
|
||||||
|
override fun findDeepestSuperMethods(method: PsiMethod) = method.findDeepestSuperMethods().asList()
|
||||||
}
|
}
|
||||||
@@ -49,4 +49,4 @@ public object IdeaReferenceSearcher: ReferenceSearcher {
|
|||||||
val searchScope = GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.projectScope(element.getProject()), *fileTypes.toTypedArray())
|
val searchScope = GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.projectScope(element.getProject()), *fileTypes.toTypedArray())
|
||||||
return ReferencesSearch.search(element, searchScope).findAll()
|
return ReferencesSearch.search(element, searchScope).findAll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.j2k
|
package org.jetbrains.kotlin.j2k
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiMethod
|
||||||
|
|
||||||
interface JavaToKotlinConverterServices {
|
interface JavaToKotlinConverterServices {
|
||||||
val referenceSearcher: ReferenceSearcher
|
val referenceSearcher: ReferenceSearcher
|
||||||
|
val superMethodsSearcher: SuperMethodsSearcher
|
||||||
val resolverForConverter: ResolverForConverter
|
val resolverForConverter: ResolverForConverter
|
||||||
val docCommentConverter: DocCommentConverter
|
val docCommentConverter: DocCommentConverter
|
||||||
}
|
}
|
||||||
@@ -25,8 +28,22 @@ interface JavaToKotlinConverterServices {
|
|||||||
object EmptyJavaToKotlinServices: JavaToKotlinConverterServices {
|
object EmptyJavaToKotlinServices: JavaToKotlinConverterServices {
|
||||||
override val referenceSearcher: ReferenceSearcher
|
override val referenceSearcher: ReferenceSearcher
|
||||||
get() = EmptyReferenceSearcher
|
get() = EmptyReferenceSearcher
|
||||||
|
|
||||||
|
override val superMethodsSearcher: SuperMethodsSearcher
|
||||||
|
get() = SuperMethodsSearcher.Default
|
||||||
|
|
||||||
override val resolverForConverter: ResolverForConverter
|
override val resolverForConverter: ResolverForConverter
|
||||||
get() = EmptyResolverForConverter
|
get() = EmptyResolverForConverter
|
||||||
|
|
||||||
override val docCommentConverter: DocCommentConverter
|
override val docCommentConverter: DocCommentConverter
|
||||||
get() = EmptyDocCommentConverter
|
get() = EmptyDocCommentConverter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface SuperMethodsSearcher {
|
||||||
|
fun findDeepestSuperMethods(method: PsiMethod): Collection<PsiMethod>
|
||||||
|
|
||||||
|
object Default : SuperMethodsSearcher {
|
||||||
|
// use simple findSuperMethods by default because findDeepestSuperMethods requires some service from IDEA
|
||||||
|
override fun findDeepestSuperMethods(method: PsiMethod) = method.findSuperMethods().asList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -255,17 +255,15 @@ private class PropertyDetector(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createAccessorInfo(getOrSetMethod: PsiMethod, field: PsiField?, kind: AccessorKind, propertyName: String): AccessorInfo? {
|
private fun createAccessorInfo(getOrSetMethod: PsiMethod, field: PsiField?, kind: AccessorKind, propertyName: String): AccessorInfo? {
|
||||||
//TODO: deepest method
|
|
||||||
//TODO: multiple
|
//TODO: multiple
|
||||||
for (superSignature in getOrSetMethod.hierarchicalMethodSignature.superSignatures) {
|
for (superMethod in converter.services.superMethodsSearcher.findDeepestSuperMethods(getOrSetMethod)) {
|
||||||
val method = superSignature.method
|
val containingClass = superMethod.containingClass!!
|
||||||
val containingClass = method.containingClass!!
|
|
||||||
val superPropertyInfo: SuperPropertyInfo? = if (converter.inConversionScope(containingClass)) {
|
val superPropertyInfo: SuperPropertyInfo? = if (converter.inConversionScope(containingClass)) {
|
||||||
val propertyInfo = converter.propertyDetectionCache[containingClass][method]
|
val propertyInfo = converter.propertyDetectionCache[containingClass][superMethod]
|
||||||
if (propertyInfo != null) SuperPropertyInfo(propertyInfo.isVar) else null
|
if (propertyInfo != null) SuperPropertyInfo(propertyInfo.isVar) else null
|
||||||
}
|
}
|
||||||
else if (method is KotlinLightMethod) {
|
else if (superMethod is KotlinLightMethod) {
|
||||||
val origin = method.getOrigin()
|
val origin = superMethod.getOrigin()
|
||||||
if (origin is JetProperty) SuperPropertyInfo(origin.isVar) else null
|
if (origin is JetProperty) SuperPropertyInfo(origin.isVar) else null
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
Vendored
+11
@@ -1,7 +1,10 @@
|
|||||||
package javaApi;
|
package javaApi;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.lang.String;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import kotlinApi.KotlinClassWithProperties;
|
||||||
|
|
||||||
public @interface Anon1 {
|
public @interface Anon1 {
|
||||||
String[] value();
|
String[] value();
|
||||||
@@ -103,4 +106,12 @@ public class JavaClassWithProperties {
|
|||||||
|
|
||||||
public int getValue4() { return 1; }
|
public int getValue4() { return 1; }
|
||||||
public void setValue4(int value) { }
|
public void setValue4(int value) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class JavaClassDerivedFromKotlinClassWithProperties extends KotlinClassWithProperties {
|
||||||
|
@Override
|
||||||
|
public String getSomeVar1() { return ""; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSomeVar2(String value) { }
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import kotlinApi.KotlinClassWithProperties;
|
import kotlinApi.KotlinClassWithProperties;
|
||||||
import javaApi.JavaClassWithProperties;
|
import javaApi.JavaClassWithProperties;
|
||||||
|
import javaApi.JavaClassDerivedFromKotlinClassWithProperties;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -100,4 +101,13 @@ class C extends A {
|
|||||||
public String getSomeVar1() {
|
public String getSomeVar1() {
|
||||||
return super.getSomeVar1();
|
return super.getSomeVar1();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class D extends JavaClassDerivedFromKotlinClassWithProperties {
|
||||||
|
@Override
|
||||||
|
public String getSomeVar1() { return "a"; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSomeVar2(String value) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,11 @@
|
|||||||
// ERROR: Property must be initialized
|
// ERROR: Property must be initialized
|
||||||
// ERROR: Property must be initialized
|
// ERROR: Property must be initialized
|
||||||
// ERROR: Property must be initialized
|
// ERROR: Property must be initialized
|
||||||
|
// ERROR: Property must be initialized
|
||||||
|
// ERROR: Property must be initialized
|
||||||
import kotlinApi.KotlinClassWithProperties
|
import kotlinApi.KotlinClassWithProperties
|
||||||
import javaApi.JavaClassWithProperties
|
import javaApi.JavaClassWithProperties
|
||||||
|
import javaApi.JavaClassDerivedFromKotlinClassWithProperties
|
||||||
|
|
||||||
internal open class A : KotlinClassWithProperties() {
|
internal open class A : KotlinClassWithProperties() {
|
||||||
override var someVar1: String
|
override var someVar1: String
|
||||||
@@ -82,4 +85,16 @@ internal class C : A() {
|
|||||||
get() {
|
get() {
|
||||||
return super.someVar1
|
return super.someVar1
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class D : JavaClassDerivedFromKotlinClassWithProperties() {
|
||||||
|
override var someVar1: String
|
||||||
|
get() {
|
||||||
|
return "a"
|
||||||
|
}
|
||||||
|
|
||||||
|
override var someVar2: String
|
||||||
|
set(value: String) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user