Use DescriptorRenderer to render annotations everywhere

This commit is contained in:
Andrey Breslav
2014-01-14 15:40:38 +04:00
parent 9fa29535b4
commit 65d90e18a2
60 changed files with 272 additions and 102 deletions
@@ -29,12 +29,12 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.TypeProjection;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import org.jetbrains.jet.renderer.DescriptorRendererBuilder;
import java.io.File;
import java.io.IOException;
@@ -43,6 +43,11 @@ import java.util.Collections;
import java.util.List;
public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFixture {
private static final DescriptorRenderer WITH_ANNOTATION_ARGUMENT_TYPES = new DescriptorRendererBuilder()
.setVerbose(true)
.setShortNames(true)
.build();
private static final String PATH = "compiler/testData/resolveAnnotations/testFile.kt";
private static final FqName PACKAGE = new FqName("test");
@@ -277,7 +282,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
String actual = StringUtil.join(member.getAnnotations(), new Function<AnnotationDescriptor, String>() {
@Override
public String fun(AnnotationDescriptor annotationDescriptor) {
return annotationDescriptor.getType().toString() + DescriptorUtils.getSortedValueArguments(annotationDescriptor, DescriptorRenderer.TEXT);
return WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(annotationDescriptor);
}
}, " ");
assertEquals("Failed to resolve annotation descriptor for " + member.toString(), expectedAnnotation, actual);
@@ -288,7 +293,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
return StringUtil.join(member.getAnnotations(), new Function<AnnotationDescriptor, String>() {
@Override
public String fun(AnnotationDescriptor annotationDescriptor) {
return annotationDescriptor.getType().toString() + DescriptorUtils.getSortedValueArguments(annotationDescriptor, DescriptorRenderer.TEXT);
return WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(annotationDescriptor);
}
}, " ");
}
@@ -21,73 +21,73 @@ import java.io.IOException;
public class AnnotationDescriptorResolveTest extends AbstractAnnotationDescriptorResolveTest {
public void testIntAnnotation() throws IOException {
String content = getContent("AnnInt(1)");
String expectedAnnotation = "AnnInt[a = IntegerValueType(1): IntegerValueType(1)]";
String expectedAnnotation = "AnnInt(a = IntegerValueType(1): IntegerValueType(1))";
doTest(content, expectedAnnotation);
}
public void testStringAnnotation() throws IOException {
String content = getContent("AnnString(\"test\")");
String expectedAnnotation = "AnnString[a = \"test\": jet.String]";
String expectedAnnotation = "AnnString(a = \"test\": String)";
doTest(content, expectedAnnotation);
}
public void testEnumAnnotation() throws IOException {
String content = getContent("AnnEnum(MyEnum.A)");
String expectedAnnotation = "AnnEnum[a = MyEnum.A: test.MyEnum]";
String expectedAnnotation = "AnnEnum(a = MyEnum.A: MyEnum)";
doTest(content, expectedAnnotation);
}
public void testQualifiedEnumAnnotation() throws IOException {
String content = getContent("AnnEnum(test.MyEnum.A)");
String expectedAnnotation = "AnnEnum[a = MyEnum.A: test.MyEnum]";
String content = getContent("AnnEnum(MyEnum.A)");
String expectedAnnotation = "AnnEnum(a = MyEnum.A: MyEnum)";
doTest(content, expectedAnnotation);
}
public void testUnqualifiedEnumAnnotation() throws IOException {
String content = getContent("AnnEnum(A)");
String expectedAnnotation = "AnnEnum[a = MyEnum.A: test.MyEnum]";
String expectedAnnotation = "AnnEnum(a = MyEnum.A: MyEnum)";
doTest(content, expectedAnnotation);
}
public void testIntArrayAnnotation() throws IOException {
String content = getContent("AnnIntArray(intArray(1, 2))");
String expectedAnnotation = "AnnIntArray[a = [IntegerValueType(1), IntegerValueType(2)]: jet.IntArray]";
String expectedAnnotation = "AnnIntArray(a = {IntegerValueType(1), IntegerValueType(2)}: IntArray)";
doTest(content, expectedAnnotation);
}
public void testIntArrayVarargAnnotation() throws IOException {
String content = getContent("AnnIntVararg(1, 2)");
String expectedAnnotation = "AnnIntVararg[a = [IntegerValueType(1), IntegerValueType(2)]: jet.IntArray]";
String expectedAnnotation = "AnnIntVararg(a = {IntegerValueType(1), IntegerValueType(2)}: IntArray)";
doTest(content, expectedAnnotation);
}
public void testStringArrayVarargAnnotation() throws IOException {
String content = getContent("AnnStringVararg(\"a\", \"b\")");
String expectedAnnotation = "AnnStringVararg[a = [\"a\", \"b\"]: jet.Array<jet.String>]";
String expectedAnnotation = "AnnStringVararg(a = {\"a\", \"b\"}: Array<String>)";
doTest(content, expectedAnnotation);
}
public void testStringArrayAnnotation() throws IOException {
String content = getContent("AnnStringArray(array(\"a\"))");
String expectedAnnotation = "AnnStringArray[a = [\"a\"]: jet.Array<jet.String>]";
String expectedAnnotation = "AnnStringArray(a = {\"a\"}: Array<String>)";
doTest(content, expectedAnnotation);
}
public void testEnumArrayAnnotation() throws IOException {
String content = getContent("AnnArrayOfEnum(array(MyEnum.A))");
String expectedAnnotation = "AnnArrayOfEnum[a = [MyEnum.A]: jet.Array<test.MyEnum>]";
String expectedAnnotation = "AnnArrayOfEnum(a = {MyEnum.A}: Array<MyEnum>)";
doTest(content, expectedAnnotation);
}
public void testAnnotationAnnotation() throws Exception {
String content = getContent("AnnAnn(AnnInt(1))");
String expectedAnnotation = "AnnAnn[a = AnnInt[a = IntegerValueType(1)]: test.AnnInt]";
String expectedAnnotation = "AnnAnn(a = AnnInt(a = IntegerValueType(1): IntegerValueType(1)): AnnInt)";
doTest(content, expectedAnnotation);
}
public void testJavaClassAnnotation() throws Exception {
String content = getContent("AnnClass(javaClass<MyClass>())");
String expectedAnnotation = "AnnClass[a = MyClass.class: java.lang.Class<test.MyClass>]";
String expectedAnnotation = "AnnClass(a = MyClass.class: Class<MyClass>)";
doTest(content, expectedAnnotation);
}
}