Fixed assertion in j2k on updating external usages

This commit is contained in:
Valentin Kipyatkov
2015-09-07 21:16:29 +03:00
parent 67f714434f
commit aec661aeff
3 changed files with 6 additions and 8 deletions
@@ -32,9 +32,7 @@ import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.psi.JetPsiFactory
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
import java.util.ArrayList
import java.util.Comparator
import java.util.LinkedHashMap
import java.util.*
public interface PostProcessor {
public fun insertImport(file: JetFile, fqName: FqName)
@@ -143,6 +141,7 @@ public class JavaToKotlinConverter(
val processings: Collection<UsageProcessing>
) {
val depth: Int by lazy(LazyThreadSafetyMode.NONE) { target.parentsWithSelf.takeWhile { it !is PsiFile }.count() }
val offset: Int by lazy(LazyThreadSafetyMode.NONE) { reference.element.textRange.startOffset }
}
private fun buildExternalCodeProcessing(
@@ -217,17 +216,14 @@ public class JavaToKotlinConverter(
private object ReferenceComparator : Comparator<ReferenceInfo> {
override fun compare(info1: ReferenceInfo, info2: ReferenceInfo): Int {
val element1 = info1.reference.getElement()
val element2 = info2.reference.getElement()
val depth1 = info1.depth
val depth2 = info2.depth
if (depth1 != depth2) { // put deeper elements first to not invalidate them when processing ancestors
return -depth1.compareTo(depth2)
}
// process elements with the same parent from right to left so that right-side of assignments is not invalidated by processing of the left one
return -element1.getStartOffsetInParent().compareTo(element2.getStartOffsetInParent())
// process elements with the same deepness from right to left so that right-side of assignments is not invalidated by processing of the left one
return -info1.offset.compareTo(info2.offset)
}
}
@@ -8,5 +8,6 @@ class C extends JavaClass {
javaClass.field -= field;
field = myProperty;
field *= 2;
field = field * 2;
}
}
@@ -8,5 +8,6 @@ class C extends JavaClass {
javaClass.setField(javaClass.getField() - getField());
setField(getProperty());
setField(getField() * 2);
setField(getField() * 2);
}
}