Fix tests

This commit is contained in:
Yan Zhulanow
2015-08-06 18:59:37 +03:00
parent 552211b2f4
commit 2ce9903356
84 changed files with 221 additions and 195 deletions
@@ -4605,6 +4605,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("propertyUseSiteTargetedAnnotations.kt")
public void testPropertyUseSiteTargetedAnnotations() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/propertyUseSiteTargetedAnnotations.kt");
doTest(fileName);
}
@TestMetadata("typeUsage.kt")
public void testTypeUsage() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/typeUsage.kt");
@@ -20,11 +20,9 @@ import org.jetbrains.kotlin.test.ConfigurationKind
import org.jetbrains.kotlin.test.JetTestUtils
import org.jetbrains.org.objectweb.asm.*
import java.io.File
import java.util.*
public abstract class AbstractBytecodeListingTest : CodegenTestCase() {
throws(Exception::class)
public fun doTest(filename: String) {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL)
loadFileByFullPath(filename)
@@ -152,7 +152,7 @@ public class AnnotationGenTest extends CodegenTestCase {
}
public void testPropFieldInConstructor() throws NoSuchFieldException, NoSuchMethodException {
loadText("class A (@[Deprecated] var x: Int) {}");
loadText("class A (@field:Deprecated @param:Deprecated var x: Int) {}");
Class<?> aClass = generateClass("A");
Constructor constructor = aClass.getDeclaredConstructor(int.class);
assertNotNull(constructor);
@@ -2376,12 +2376,6 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
doTestCompiledKotlin(fileName);
}
@TestMetadata("PropertyTarget.kt")
public void testPropertyTarget() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/PropertyTarget.kt");
doTestCompiledKotlin(fileName);
}
@TestMetadata("ReceiverTarget.kt")
public void testReceiverTarget() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/ReceiverTarget.kt");
@@ -485,12 +485,6 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD
doTest(fileName);
}
@TestMetadata("PropertyTarget.kt")
public void testPropertyTarget() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/PropertyTarget.kt");
doTest(fileName);
}
@TestMetadata("ReceiverTarget.kt")
public void testReceiverTarget() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/ReceiverTarget.kt");
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.analyzer.AnalysisResult;
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget;
import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor;
@@ -138,7 +139,9 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
}
}, " ");
assertEquals(expectedAnnotation, actualAnnotation);
String expectedAnnotationWithTarget = "@" + AnnotationUseSiteTarget.FILE.getRenderName() + ":" + expectedAnnotation;
assertEquals(expectedAnnotationWithTarget, actualAnnotation);
}
private void checkAnnotationOnLocalDeclarations(String expectedAnnotation) {
@@ -149,7 +152,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
}
private static void checkAnnotationsOnProperty(String expectedAnnotation, PropertyDescriptor prop) {
checkDescriptor(expectedAnnotation, prop);
checkDescriptorWithTarget(expectedAnnotation, prop, AnnotationUseSiteTarget.FIELD);
checkDescriptor(expectedAnnotation, prop.getGetter());
PropertySetterDescriptor propSetter = prop.getSetter();
assertNotNull(propSetter);
@@ -363,12 +366,16 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
return JetTestUtils.doLoadFile(file).replaceAll("ANNOTATION", annotationText);
}
private static String renderAnnotations(Annotations annotations) {
private static String renderAnnotations(Annotations annotations, @Nullable final AnnotationUseSiteTarget defaultTarget) {
return StringUtil.join(annotations.getAllAnnotations(), new Function<AnnotationWithTarget, String>() {
@Override
public String fun(AnnotationWithTarget annotationWithTarget) {
return WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(
annotationWithTarget.getAnnotation(), annotationWithTarget.getTarget());
AnnotationUseSiteTarget targetToRender = annotationWithTarget.getTarget();
if (targetToRender == defaultTarget) {
targetToRender = null;
}
return WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(annotationWithTarget.getAnnotation(), targetToRender);
}
}, " ");
}
@@ -378,9 +385,14 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
assertEquals("Failed to resolve annotation descriptor for " + member.toString(), expectedAnnotation, actual);
}
private static void checkDescriptorWithTarget(String expectedAnnotation, DeclarationDescriptor member, AnnotationUseSiteTarget target) {
String actual = renderAnnotations(member.getAnnotations(), target);
assertEquals("Failed to resolve annotation descriptor for " + member.toString(), expectedAnnotation, actual);
}
@NotNull
protected static String getAnnotations(DeclarationDescriptor member) {
return renderAnnotations(member.getAnnotations());
return renderAnnotations(member.getAnnotations(), null);
}
@Override