better output in ReaderClassDataTest.compareNamespaces
This commit is contained in:
@@ -7,6 +7,7 @@ import com.intellij.psi.PsiFileFactory;
|
|||||||
import com.intellij.psi.impl.PsiFileFactoryImpl;
|
import com.intellij.psi.impl.PsiFileFactoryImpl;
|
||||||
import com.intellij.testFramework.LightVirtualFile;
|
import com.intellij.testFramework.LightVirtualFile;
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
|
import org.codehaus.groovy.ast.expr.DeclarationExpression;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
||||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||||
@@ -33,7 +34,9 @@ import org.junit.Assert;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -93,32 +96,70 @@ public class ReadClassDataTest extends TestCaseWithTmpdir {
|
|||||||
private void compareNamespaces(@NotNull NamespaceDescriptor nsa, @NotNull NamespaceDescriptor nsb) {
|
private void compareNamespaces(@NotNull NamespaceDescriptor nsa, @NotNull NamespaceDescriptor nsb) {
|
||||||
Assert.assertEquals(nsa.getName(), nsb.getName());
|
Assert.assertEquals(nsa.getName(), nsb.getName());
|
||||||
System.out.println("namespace " + nsa.getName());
|
System.out.println("namespace " + nsa.getName());
|
||||||
|
|
||||||
|
Set<String> classifierNames = new HashSet<String>();
|
||||||
|
Set<String> propertyNames = new HashSet<String>();
|
||||||
|
Set<String> functionNames = new HashSet<String>();
|
||||||
|
|
||||||
for (DeclarationDescriptor ad : nsa.getMemberScope().getAllDescriptors()) {
|
for (DeclarationDescriptor ad : nsa.getMemberScope().getAllDescriptors()) {
|
||||||
if (ad instanceof ClassifierDescriptor) {
|
if (ad instanceof ClassifierDescriptor) {
|
||||||
ClassifierDescriptor bd = nsb.getMemberScope().getClassifier(ad.getName());
|
classifierNames.add(ad.getName());
|
||||||
Assert.assertTrue("classifier not found: " + ad.getName(), bd != null);
|
|
||||||
compareClassifiers((ClassifierDescriptor) ad, bd);
|
|
||||||
|
|
||||||
Assert.assertNull(nsb.getMemberScope().getClassifier(ad.getName() + JvmAbi.TRAIT_IMPL_SUFFIX));
|
|
||||||
} else if (ad instanceof FunctionDescriptor) {
|
|
||||||
Set<FunctionDescriptor> functions = nsb.getMemberScope().getFunctions(ad.getName());
|
|
||||||
Assert.assertTrue(functions.size() >= 1);
|
|
||||||
Assert.assertTrue("not implemented", functions.size() == 1);
|
|
||||||
FunctionDescriptor bd = functions.iterator().next();
|
|
||||||
compareDescriptors(ad, bd);
|
|
||||||
} else if (ad instanceof PropertyDescriptor) {
|
} else if (ad instanceof PropertyDescriptor) {
|
||||||
Set<VariableDescriptor> properties = nsb.getMemberScope().getProperties(ad.getName());
|
propertyNames.add(ad.getName());
|
||||||
Assert.assertTrue("property not found by name: " + ad.getName(), properties.size() >= 1);
|
} else if (ad instanceof FunctionDescriptor) {
|
||||||
Assert.assertTrue("not implemented", properties.size() == 1);
|
functionNames.add(ad.getName());
|
||||||
PropertyDescriptor bd = (PropertyDescriptor) properties.iterator().next();
|
|
||||||
compareDescriptors(ad, bd);
|
|
||||||
|
|
||||||
Assert.assertTrue(nsb.getMemberScope().getFunctions(PropertyCodegen.getterName(ad.getName())).isEmpty());
|
|
||||||
Assert.assertTrue(nsb.getMemberScope().getFunctions(PropertyCodegen.setterName(ad.getName())).isEmpty());
|
|
||||||
} else {
|
} else {
|
||||||
throw new AssertionError("Unknown member: " + ad);
|
throw new AssertionError("unknown member: " + ad);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (String name : classifierNames) {
|
||||||
|
ClassifierDescriptor ca = nsa.getMemberScope().getClassifier(name);
|
||||||
|
ClassifierDescriptor cb = nsb.getMemberScope().getClassifier(name);
|
||||||
|
Assert.assertTrue(ca != null);
|
||||||
|
Assert.assertTrue(cb != null);
|
||||||
|
compareClassifiers(ca, cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String name : propertyNames) {
|
||||||
|
Set<VariableDescriptor> pa = nsa.getMemberScope().getProperties(name);
|
||||||
|
Set<VariableDescriptor> pb = nsb.getMemberScope().getProperties(name);
|
||||||
|
compareDeclarationSets(pa, pb);
|
||||||
|
|
||||||
|
Assert.assertTrue(nsb.getMemberScope().getFunctions(PropertyCodegen.getterName(name)).isEmpty());
|
||||||
|
Assert.assertTrue(nsb.getMemberScope().getFunctions(PropertyCodegen.setterName(name)).isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String name : functionNames) {
|
||||||
|
Set<FunctionDescriptor> fa = nsa.getMemberScope().getFunctions(name);
|
||||||
|
Set<FunctionDescriptor> fb = nsb.getMemberScope().getFunctions(name);
|
||||||
|
compareDeclarationSets(fa, fb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void compareDeclarationSets(Set<? extends DeclarationDescriptor> a, Set<? extends DeclarationDescriptor> b) {
|
||||||
|
String at = serializedDeclarationSets(a);
|
||||||
|
String bt = serializedDeclarationSets(b);
|
||||||
|
Assert.assertEquals(at, bt);
|
||||||
|
System.out.print(at);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String serializedDeclarationSets(Collection<? extends DeclarationDescriptor> ds) {
|
||||||
|
List<String> strings = new ArrayList<String>();
|
||||||
|
for (DeclarationDescriptor d : ds) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
new Serializer(sb).serialize(d);
|
||||||
|
strings.add(sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(strings);
|
||||||
|
|
||||||
|
StringBuilder r = new StringBuilder();
|
||||||
|
for (String string : strings) {
|
||||||
|
r.append(string);
|
||||||
|
r.append("\n");
|
||||||
|
}
|
||||||
|
return r.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void compareClassifiers(@NotNull ClassifierDescriptor a, @NotNull ClassifierDescriptor b) {
|
private void compareClassifiers(@NotNull ClassifierDescriptor a, @NotNull ClassifierDescriptor b) {
|
||||||
|
|||||||
Reference in New Issue
Block a user