Record COMPILE_TIME_INITIALIZER for all final variables

This commit is contained in:
Natalia Ukhorskaya
2014-01-17 13:10:55 +04:00
parent 2ddda59465
commit 97da2def08
23 changed files with 611 additions and 52 deletions
@@ -2889,6 +2889,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest("compiler/testData/diagnostics/tests/evaluate/parentesized.kt");
}
@TestMetadata("qualifiedExpressions.kt")
public void testQualifiedExpressions() throws Exception {
doTest("compiler/testData/diagnostics/tests/evaluate/qualifiedExpressions.kt");
}
@TestMetadata("unaryMinusDepOnExpType.kt")
public void testUnaryMinusDepOnExpType() throws Exception {
doTest("compiler/testData/diagnostics/tests/evaluate/unaryMinusDepOnExpType.kt");
@@ -32,6 +32,7 @@ import org.jetbrains.jet.JetTestUtils
import org.jetbrains.jet.util.slicedmap.WritableSlice
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant
import org.jetbrains.jet.lang.resolve.constants.StringValue
import org.jetbrains.jet.lang.descriptors.VariableDescriptor
abstract class AbstractEvaluateExpressionTest: AbstractAnnotationDescriptorResolveTest() {
@@ -72,7 +73,9 @@ abstract class AbstractEvaluateExpressionTest: AbstractAnnotationDescriptorResol
val expected = InTextDirectivesUtils.findStringWithPrefixes(fileText, expectedPropertyPrefix)
assertNotNull(expected, "Failed to find expected directive: $expectedPropertyPrefix")
val property = AbstractAnnotationDescriptorResolveTest.getPropertyDescriptor(packageView, propertyName)
val property = AbstractAnnotationDescriptorResolveTest.getPropertyDescriptor(packageView, propertyName, false)
?: AbstractAnnotationDescriptorResolveTest.getLocalVarDescriptor(context!!, propertyName)
val jetProperty = BindingContextUtils.descriptorToDeclaration(context!!, property) as JetProperty
val testedObject = getValueToTest(jetProperty, context!!)
@@ -38,6 +38,11 @@ public class EvaluateExpressionTestGenerated extends AbstractEvaluateExpressionT
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/evaluate/constant"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("classObjectProperty.kt")
public void testClassObjectProperty() throws Exception {
doConstantTest("compiler/testData/evaluate/constant/classObjectProperty.kt");
}
@TestMetadata("compareTo.kt")
public void testCompareTo() throws Exception {
doConstantTest("compiler/testData/evaluate/constant/compareTo.kt");
@@ -58,6 +63,11 @@ public class EvaluateExpressionTestGenerated extends AbstractEvaluateExpressionT
doConstantTest("compiler/testData/evaluate/constant/exceptionWhenEvaluate.kt");
}
@TestMetadata("finalProperty.kt")
public void testFinalProperty() throws Exception {
doConstantTest("compiler/testData/evaluate/constant/finalProperty.kt");
}
@TestMetadata("float.kt")
public void testFloat() throws Exception {
doConstantTest("compiler/testData/evaluate/constant/float.kt");
@@ -78,11 +88,36 @@ public class EvaluateExpressionTestGenerated extends AbstractEvaluateExpressionT
doConstantTest("compiler/testData/evaluate/constant/integers.kt");
}
@TestMetadata("localVal.kt")
public void testLocalVal() throws Exception {
doConstantTest("compiler/testData/evaluate/constant/localVal.kt");
}
@TestMetadata("localVar.kt")
public void testLocalVar() throws Exception {
doConstantTest("compiler/testData/evaluate/constant/localVar.kt");
}
@TestMetadata("nonFinalProperty.kt")
public void testNonFinalProperty() throws Exception {
doConstantTest("compiler/testData/evaluate/constant/nonFinalProperty.kt");
}
@TestMetadata("strings.kt")
public void testStrings() throws Exception {
doConstantTest("compiler/testData/evaluate/constant/strings.kt");
}
@TestMetadata("topLevelVal.kt")
public void testTopLevelVal() throws Exception {
doConstantTest("compiler/testData/evaluate/constant/topLevelVal.kt");
}
@TestMetadata("topLevelVar.kt")
public void testTopLevelVar() throws Exception {
doConstantTest("compiler/testData/evaluate/constant/topLevelVar.kt");
}
@TestMetadata("unaryMinusIndepWoExpType.kt")
public void testUnaryMinusIndepWoExpType() throws Exception {
doConstantTest("compiler/testData/evaluate/constant/unaryMinusIndepWoExpType.kt");
@@ -20,6 +20,7 @@ package org.jetbrains.jet.resolve.annotation;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetLiteFixture;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
@@ -87,7 +88,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
FunctionDescriptor topFoo = getFunctionDescriptor(test, "topFoo");
checkAnnotationsOnFunction(expectedAnnotation, topFoo);
PropertyDescriptor topProp = getPropertyDescriptor(test, "topProp");
PropertyDescriptor topProp = getPropertyDescriptor(test, "topProp", true);
checkAnnotationsOnProperty(expectedAnnotation, topProp);
checkDescriptor(expectedAnnotation, getClassDescriptor(test, "MyObject"));
@@ -100,7 +101,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
checkDescriptor(expectedAnnotation, getLocalClassDescriptor("LocalClass"));
checkDescriptor(expectedAnnotation, getLocalObjectDescriptor("LocalObject"));
checkDescriptor(expectedAnnotation, getLocalFunDescriptor("localFun"));
checkDescriptor(expectedAnnotation, getLocalVarDescriptor("localVar"));
checkDescriptor(expectedAnnotation, getLocalVarDescriptor(context, "localVar"));
}
private static void checkAnnotationsOnProperty(String expectedAnnotation, PropertyDescriptor prop) {
@@ -134,12 +135,30 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
return functions.iterator().next();
}
@NotNull
protected static PropertyDescriptor getPropertyDescriptor(@NotNull PackageViewDescriptor packageView, @NotNull String name) {
@Nullable
protected static PropertyDescriptor getPropertyDescriptor(@NotNull PackageViewDescriptor packageView, @NotNull String name, boolean failOnMissing) {
Name propertyName = Name.identifier(name);
JetScope memberScope = packageView.getMemberScope();
Collection<VariableDescriptor> properties = memberScope.getProperties(propertyName);
assert properties.size() == 1 : "Failed to find property " + propertyName + " in class " + packageView.getName();
if (properties.isEmpty()) {
for (DeclarationDescriptor descriptor : memberScope.getAllDescriptors()) {
if (descriptor instanceof ClassDescriptor) {
Collection<VariableDescriptor> classProperties =
((ClassDescriptor) descriptor).getMemberScope(Collections.<TypeProjection>emptyList())
.getProperties(propertyName);
if (!classProperties.isEmpty()) {
properties = classProperties;
break;
}
}
}
}
if (failOnMissing) {
assert properties.size() == 1 : "Failed to find property " + propertyName + " in class " + packageView.getName();
}
else if (properties.size() != 1) {
return null;
}
return (PropertyDescriptor) properties.iterator().next();
}
@@ -216,7 +235,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
}
@NotNull
private VariableDescriptor getLocalVarDescriptor(@NotNull String name) {
protected static VariableDescriptor getLocalVarDescriptor(@NotNull BindingContext context, @NotNull String name) {
for (VariableDescriptor descriptor : context.getSliceContents(BindingContext.VARIABLE).values()) {
if (descriptor.getName().asString().equals(name)) {
return descriptor;