'const val' are now considered constants by Java in IDEA
#KT-12026 Fixed
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.asJava
|
||||
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.impl.PsiVariableEx
|
||||
import com.intellij.psi.impl.light.LightElement
|
||||
import com.intellij.util.IncorrectOperationException
|
||||
import org.jetbrains.annotations.NonNls
|
||||
@@ -27,7 +28,7 @@ import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtEnumEntry
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
|
||||
interface KtLightField : PsiField, KtLightDeclaration<KtDeclaration, PsiField>
|
||||
interface KtLightField : PsiField, KtLightDeclaration<KtDeclaration, PsiField>, PsiVariableEx
|
||||
|
||||
// Copied from com.intellij.psi.impl.light.LightField
|
||||
sealed class KtLightFieldImpl(
|
||||
@@ -94,6 +95,10 @@ sealed class KtLightFieldImpl(
|
||||
|
||||
override fun getNavigationElement() = kotlinOrigin ?: super.getNavigationElement()
|
||||
|
||||
override fun computeConstantValue(visitedVars: MutableSet<PsiVariable>?): Any? {
|
||||
return (clsDelegate as PsiVariableEx).computeConstantValue(visitedVars)
|
||||
}
|
||||
|
||||
override fun isEquivalentTo(another: PsiElement?): Boolean {
|
||||
if (another is KtLightField && kotlinOrigin == another.kotlinOrigin && clsDelegate == another.clsDelegate) {
|
||||
return true
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
public class UseKotlinConstInSwitch {
|
||||
public static void main(int i) {
|
||||
switch (i) {
|
||||
case a.UseKotlinConstInSwitchKt.i:
|
||||
System.out.println("1");
|
||||
break;
|
||||
default:
|
||||
System.out.println("2");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package a
|
||||
|
||||
const val i = 45
|
||||
+6
@@ -107,6 +107,12 @@ public class JavaAgainstKotlinBinariesCheckerTestGenerated extends AbstractJavaA
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("UseKotlinConstInSwitch.kt")
|
||||
public void testUseKotlinConstInSwitch() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/kotlinAndJavaChecker/javaAgainstKotlin/UseKotlinConstInSwitch.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("UseKotlinSubclassesOfMappedTypes.kt")
|
||||
public void testUseKotlinSubclassesOfMappedTypes() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/kotlinAndJavaChecker/javaAgainstKotlin/UseKotlinSubclassesOfMappedTypes.kt");
|
||||
|
||||
+6
@@ -109,6 +109,12 @@ public class JavaAgainstKotlinSourceCheckerTestGenerated extends AbstractJavaAga
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("UseKotlinConstInSwitch.kt")
|
||||
public void testUseKotlinConstInSwitch() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/kotlinAndJavaChecker/javaAgainstKotlin/UseKotlinConstInSwitch.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("UseKotlinSubclassesOfMappedTypes.kt")
|
||||
public void testUseKotlinSubclassesOfMappedTypes() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/kotlinAndJavaChecker/javaAgainstKotlin/UseKotlinSubclassesOfMappedTypes.kt");
|
||||
|
||||
Reference in New Issue
Block a user