Use type from compile time value for prefix expression
This commit is contained in:
@@ -2749,6 +2749,21 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
doTest("compiler/testData/diagnostics/tests/evaluate/otherOverflow.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unaryMinusDepOnExpType.kt")
|
||||
public void testUnaryMinusDepOnExpType() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/evaluate/unaryMinusDepOnExpType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unaryMinusIndepWoExpType.kt")
|
||||
public void testUnaryMinusIndepWoExpType() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/evaluate/unaryMinusIndepWoExpType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unaryMinusIndependentExpType.kt")
|
||||
public void testUnaryMinusIndependentExpType() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/evaluate/unaryMinusIndependentExpType.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/extensions")
|
||||
|
||||
@@ -28,25 +28,57 @@ import kotlin.test.assertNotNull
|
||||
import java.util.regex.Pattern
|
||||
import org.intellij.lang.annotations.RegExp
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import org.jetbrains.jet.JetTestUtils
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant
|
||||
|
||||
abstract class AbstractEvaluateExpressionTest: AbstractAnnotationDescriptorResolveTest() {
|
||||
|
||||
// Test directives should look like [// val testedPropertyName: expectedValue]
|
||||
fun doTest(path: String) {
|
||||
val fileText = FileUtil.loadFile(File(path))
|
||||
fun doConstantTest(path: String) {
|
||||
doTest(path) {
|
||||
property, context ->
|
||||
val compileTimeConstant = context.get(BindingContext.COMPILE_TIME_VALUE, property.getInitializer())
|
||||
compileTimeConstant.toString()
|
||||
}
|
||||
}
|
||||
|
||||
// Test directives should look like [// val testedPropertyName: expectedValue]
|
||||
fun doIsPureTest(path: String) {
|
||||
doTest(path) {
|
||||
property, context ->
|
||||
val isPureKey = context.get(BindingContext.IS_PURE_CONSTANT_EXPRESSION, property.getInitializer())
|
||||
isPureKey.toString()
|
||||
}
|
||||
}
|
||||
|
||||
private fun doTest(path: String, getValueToTest: (JetProperty, BindingContext) -> String) {
|
||||
val myFile = File(path)
|
||||
val fileText = FileUtil.loadFile(myFile)
|
||||
val namespaceDescriptor = getNamespaceDescriptor(fileText)
|
||||
|
||||
val propertiesForTest = getObjectsToTest(fileText)
|
||||
|
||||
val expectedActual = hashMapOf<String, String>()
|
||||
|
||||
for (propertyName in propertiesForTest) {
|
||||
val expectedProperyPrefix = "// val ${propertyName}: "
|
||||
val expected = InTextDirectivesUtils.findStringWithPrefixes(fileText, expectedProperyPrefix)
|
||||
assertNotNull(expected, "Failed to find expected directive: $expectedProperyPrefix")
|
||||
|
||||
val property = AbstractAnnotationDescriptorResolveTest.getPropertyDescriptor(namespaceDescriptor, propertyName)
|
||||
val jetProperty = BindingContextUtils.descriptorToDeclaration(context!!, property) as JetProperty
|
||||
val compileTimeConstant = context!!.get(BindingContext.COMPILE_TIME_VALUE, jetProperty.getInitializer())
|
||||
|
||||
val expected = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// val ${propertyName}: ")
|
||||
assertNotNull(expected, "Failed to find expected directive: // val ${propertyName}: ")
|
||||
assertEquals(expected, StringUtil.unquoteString(compileTimeConstant.toString()), "Failed for $propertyName")
|
||||
val testedObject = getValueToTest(jetProperty, context!!)
|
||||
expectedActual[expectedProperyPrefix + expected!!] = expectedProperyPrefix + StringUtil.unquoteString(testedObject)
|
||||
}
|
||||
|
||||
var actualFileText = fileText
|
||||
for ((expected, actual) in expectedActual) {
|
||||
actualFileText = actualFileText.replace(expected, actual)
|
||||
}
|
||||
|
||||
JetTestUtils.assertEqualsToFile(myFile, actualFileText)
|
||||
}
|
||||
|
||||
fun getObjectsToTest(fileText: String): List<String> {
|
||||
|
||||
@@ -30,30 +30,98 @@ import org.jetbrains.jet.evaluate.AbstractEvaluateExpressionTest;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("compiler/testData/evaluate")
|
||||
@InnerTestClasses({EvaluateExpressionTestGenerated.Constant.class, EvaluateExpressionTestGenerated.IsPure.class})
|
||||
public class EvaluateExpressionTestGenerated extends AbstractEvaluateExpressionTest {
|
||||
public void testAllFilesPresentInEvaluate() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/evaluate"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
@TestMetadata("compiler/testData/evaluate/constant")
|
||||
public static class Constant extends AbstractEvaluateExpressionTest {
|
||||
public void testAllFilesPresentInConstant() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/evaluate/constant"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("compareTo.kt")
|
||||
public void testCompareTo() throws Exception {
|
||||
doConstantTest("compiler/testData/evaluate/constant/compareTo.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("divideByZero.kt")
|
||||
public void testDivideByZero() throws Exception {
|
||||
doConstantTest("compiler/testData/evaluate/constant/divideByZero.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("equals.kt")
|
||||
public void testEquals() throws Exception {
|
||||
doConstantTest("compiler/testData/evaluate/constant/equals.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("floatsAndDoubles.kt")
|
||||
public void testFloatsAndDoubles() throws Exception {
|
||||
doConstantTest("compiler/testData/evaluate/constant/floatsAndDoubles.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("integers.kt")
|
||||
public void testIntegers() throws Exception {
|
||||
doConstantTest("compiler/testData/evaluate/constant/integers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("strings.kt")
|
||||
public void testStrings() throws Exception {
|
||||
doConstantTest("compiler/testData/evaluate/constant/strings.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unaryMinusIndepWoExpType.kt")
|
||||
public void testUnaryMinusIndepWoExpType() throws Exception {
|
||||
doConstantTest("compiler/testData/evaluate/constant/unaryMinusIndepWoExpType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unaryMinusIndependentExpType.kt")
|
||||
public void testUnaryMinusIndependentExpType() throws Exception {
|
||||
doConstantTest("compiler/testData/evaluate/constant/unaryMinusIndependentExpType.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("divideByZero.kt")
|
||||
public void testDivideByZero() throws Exception {
|
||||
doTest("compiler/testData/evaluate/divideByZero.kt");
|
||||
@TestMetadata("compiler/testData/evaluate/isPure")
|
||||
public static class IsPure extends AbstractEvaluateExpressionTest {
|
||||
public void testAllFilesPresentInIsPure() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/evaluate/isPure"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("enum.kt")
|
||||
public void testEnum() throws Exception {
|
||||
doIsPureTest("compiler/testData/evaluate/isPure/enum.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("innerToType.kt")
|
||||
public void testInnerToType() throws Exception {
|
||||
doIsPureTest("compiler/testData/evaluate/isPure/innerToType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("strings.kt")
|
||||
public void testStrings() throws Exception {
|
||||
doIsPureTest("compiler/testData/evaluate/isPure/strings.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("toType.kt")
|
||||
public void testToType() throws Exception {
|
||||
doIsPureTest("compiler/testData/evaluate/isPure/toType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unaryMinusIndepWoExpType.kt")
|
||||
public void testUnaryMinusIndepWoExpType() throws Exception {
|
||||
doIsPureTest("compiler/testData/evaluate/isPure/unaryMinusIndepWoExpType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unaryMinusIndependentExpType.kt")
|
||||
public void testUnaryMinusIndependentExpType() throws Exception {
|
||||
doIsPureTest("compiler/testData/evaluate/isPure/unaryMinusIndependentExpType.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("floatsAndDoubles.kt")
|
||||
public void testFloatsAndDoubles() throws Exception {
|
||||
doTest("compiler/testData/evaluate/floatsAndDoubles.kt");
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("EvaluateExpressionTestGenerated");
|
||||
suite.addTestSuite(Constant.class);
|
||||
suite.addTestSuite(IsPure.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
@TestMetadata("integers.kt")
|
||||
public void testIntegers() throws Exception {
|
||||
doTest("compiler/testData/evaluate/integers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("strings.kt")
|
||||
public void testStrings() throws Exception {
|
||||
doTest("compiler/testData/evaluate/strings.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
@@ -281,4 +281,14 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
|
||||
}, " ");
|
||||
assertEquals("Failed to resolve annotation descriptor for " + member.toString(), expectedAnnotation, actual);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static String getAnnotations(DeclarationDescriptor member) {
|
||||
return StringUtil.join(member.getAnnotations(), new Function<AnnotationDescriptor, String>() {
|
||||
@Override
|
||||
public String fun(AnnotationDescriptor annotationDescriptor) {
|
||||
return annotationDescriptor.getType().toString() + DescriptorUtils.getSortedValueArguments(annotationDescriptor, DescriptorRenderer.TEXT);
|
||||
}
|
||||
}, " ");
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -19,6 +19,7 @@ package org.jetbrains.jet.resolve.annotation
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.jet.InTextDirectivesUtils
|
||||
import java.io.File
|
||||
import org.jetbrains.jet.JetTestUtils
|
||||
|
||||
public abstract class AbstractAnnotationParameterTest : AbstractAnnotationDescriptorResolveTest() {
|
||||
fun doTest(path: String) {
|
||||
@@ -27,6 +28,8 @@ public abstract class AbstractAnnotationParameterTest : AbstractAnnotationDescri
|
||||
val classDescriptor = AbstractAnnotationDescriptorResolveTest.getClassDescriptor(namespaceDescriptor, "MyClass")
|
||||
|
||||
val expected = InTextDirectivesUtils.findListWithPrefixes(fileText, "// EXPECTED: ").makeString(", ")
|
||||
AbstractAnnotationDescriptorResolveTest.checkDescriptor(expected, classDescriptor)
|
||||
val actual = AbstractAnnotationDescriptorResolveTest.getAnnotations(classDescriptor)
|
||||
|
||||
JetTestUtils.assertEqualsToFile(File(path), fileText.replace(expected, actual))
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -21,7 +21,7 @@ import java.io.IOException;
|
||||
public class AnnotationDescriptorResolveTest extends AbstractAnnotationDescriptorResolveTest {
|
||||
public void testIntAnnotation() throws IOException {
|
||||
String content = getContent("AnnInt(1)");
|
||||
String expectedAnnotation = "AnnInt[a = 1.toInt(): jet.Int]";
|
||||
String expectedAnnotation = "AnnInt[a = IntegerValueType(1): IntegerValueType(1)]";
|
||||
doTest(content, expectedAnnotation);
|
||||
}
|
||||
|
||||
@@ -51,13 +51,13 @@ public class AnnotationDescriptorResolveTest extends AbstractAnnotationDescripto
|
||||
|
||||
public void testIntArrayAnnotation() throws IOException {
|
||||
String content = getContent("AnnIntArray(intArray(1, 2))");
|
||||
String expectedAnnotation = "AnnIntArray[a = [1.toInt(), 2.toInt()]: jet.IntArray]";
|
||||
String expectedAnnotation = "AnnIntArray[a = [IntegerValueType(1), IntegerValueType(2)]: jet.IntArray]";
|
||||
doTest(content, expectedAnnotation);
|
||||
}
|
||||
|
||||
public void testIntArrayVarargAnnotation() throws IOException {
|
||||
String content = getContent("AnnIntVararg(1, 2)");
|
||||
String expectedAnnotation = "AnnIntVararg[a = [1.toInt(), 2.toInt()]: jet.IntArray]";
|
||||
String expectedAnnotation = "AnnIntVararg[a = [IntegerValueType(1), IntegerValueType(2)]: jet.IntArray]";
|
||||
doTest(content, expectedAnnotation);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class AnnotationDescriptorResolveTest extends AbstractAnnotationDescripto
|
||||
|
||||
public void testAnnotationAnnotation() throws Exception {
|
||||
String content = getContent("AnnAnn(AnnInt(1))");
|
||||
String expectedAnnotation = "AnnAnn[a = AnnInt[a = 1.toInt()]: test.AnnInt]";
|
||||
String expectedAnnotation = "AnnAnn[a = AnnInt[a = IntegerValueType(1)]: test.AnnInt]";
|
||||
doTest(content, expectedAnnotation);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user