NamespaceComparator.Configuration introduced
This commit is contained in:
@@ -22,10 +22,8 @@ import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.psi.impl.PsiFileFactoryImpl;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.CompileCompilerDependenciesTest;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.TestJdkKind;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.lang.BuiltinsScopeExtensionMode;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
@@ -59,7 +57,7 @@ public abstract class AbstractReadJavaBinaryClassTest extends TestCaseWithTmpdir
|
||||
File txtFile = new File(javaFile.getPath().replaceFirst("\\.java$", ".txt"));
|
||||
NamespaceDescriptor nsa = compileKotlin(ktFile);
|
||||
NamespaceDescriptor nsb = LoadJavaDescriptorUtil.compileJava(Collections.singletonList(javaFile), tmpdir, myTestRootDisposable);
|
||||
NamespaceComparator.compareNamespaces(nsa, nsb, false, txtFile);
|
||||
NamespaceComparator.compareNamespaces(nsa, nsb, NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT, txtFile);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -53,7 +53,7 @@ public final class LoadJavaDescriptorsTest extends KotlinTestWithEnvironment {
|
||||
File tmpDir = JetTestUtils.tmpDir(expected.getName());
|
||||
NamespaceDescriptor javaNamespaceDescriptor = LoadJavaDescriptorUtil.compileJava(files, tmpDir, getTestRootDisposable());
|
||||
//NOTE: comparing namespace to file (hack)
|
||||
NamespaceComparator.compareNamespaces(javaNamespaceDescriptor, javaNamespaceDescriptor, false, expected);
|
||||
NamespaceComparator.compareNamespaces(javaNamespaceDescriptor, javaNamespaceDescriptor, NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT, expected);
|
||||
}
|
||||
|
||||
public void testPackageLocalVisibility() throws Exception {
|
||||
|
||||
@@ -97,7 +97,7 @@ public class ReadKotlinBinaryClassTest extends TestCaseWithTmpdir {
|
||||
JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver();
|
||||
NamespaceDescriptor namespaceFromClass = javaDescriptorResolver.resolveNamespace(FqName.topLevel(Name.identifier("test")), DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN);
|
||||
|
||||
NamespaceComparator.compareNamespaces(namespaceFromSource, namespaceFromClass, false, txtFile);
|
||||
NamespaceComparator.compareNamespaces(namespaceFromSource, namespaceFromClass, NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT, txtFile);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
|
||||
+19
-10
@@ -33,6 +33,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -48,16 +49,24 @@ public abstract class AbstractLazyResolveDiagnosticsTest extends AbstractJetDiag
|
||||
ModuleDescriptor eagerModule = LazyResolveTestUtil.resolveEagerly(jetFiles, getEnvironment());
|
||||
|
||||
String path = JetTestUtils.getFilePath(new File(FileUtil.getRelativePath(TEST_DATA_DIR, testDataFile)));
|
||||
String txtFileRelativePath = path.replaceAll("\\.kt$|\\.ktscript", ".txt");
|
||||
File txtFile = new File("compiler/testData/lazyResolve/diagnostics/" + txtFileRelativePath);
|
||||
NamespaceComparator.compareNamespaces(eagerModule.getRootNamespace(), lazyModule.getRootNamespace(), false,
|
||||
new Predicate<NamespaceDescriptor>() {
|
||||
@Override
|
||||
public boolean apply(NamespaceDescriptor descriptor) {
|
||||
return !Name.identifier("jet").equals(descriptor.getName());
|
||||
}
|
||||
},
|
||||
txtFile);
|
||||
Set<Name> names = LazyResolveTestUtil.getTopLevelPackagesFromFileList(jetFiles);
|
||||
for (Name name : names) {
|
||||
NamespaceDescriptor expected = eagerModule.getRootNamespace().getMemberScope().getNamespace(name);
|
||||
NamespaceDescriptor actual = lazyModule.getRootNamespace().getMemberScope().getNamespace(name);
|
||||
|
||||
String txtFileRelativePath = path.replaceAll("\\.kt$|\\.ktscript", "." + name.getName() + ".txt");
|
||||
File txtFile = new File("compiler/testData/lazyResolve/diagnostics/" + txtFileRelativePath);
|
||||
|
||||
NamespaceComparator.compareNamespaces(expected, actual,
|
||||
NamespaceComparator.RECURSIVE.filterOutput(new Predicate<NamespaceDescriptor>() {
|
||||
@Override
|
||||
public boolean apply(NamespaceDescriptor descriptor) {
|
||||
return !Name.identifier("jet").equals(descriptor.getName());
|
||||
}
|
||||
}),
|
||||
txtFile);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
+8
-11
@@ -46,8 +46,7 @@ public abstract class AbstractLazyResolveNamespaceComparingTest extends KotlinTe
|
||||
}
|
||||
|
||||
private void doTest(
|
||||
String testFileName,
|
||||
boolean includeMembersOfObject
|
||||
String testFileName
|
||||
) throws IOException {
|
||||
List<JetFile> files = JetTestUtils
|
||||
.createTestFiles(testFileName, FileUtil.loadFile(new File(testFileName), true),
|
||||
@@ -65,21 +64,19 @@ public abstract class AbstractLazyResolveNamespaceComparingTest extends KotlinTe
|
||||
NamespaceDescriptor actual = lazyModule.getRootNamespace().getMemberScope().getNamespace(test);
|
||||
NamespaceDescriptor expected = eagerModule.getRootNamespace().getMemberScope().getNamespace(test);
|
||||
|
||||
Predicate<NamespaceDescriptor> filterJetNamespace = new Predicate<NamespaceDescriptor>() {
|
||||
@Override
|
||||
public boolean apply(NamespaceDescriptor namespaceDescriptor) {
|
||||
return !namespaceDescriptor.getName().equals(Name.identifier("jet"));
|
||||
}
|
||||
};
|
||||
|
||||
File serializeResultsTo = new File(FileUtil.getNameWithoutExtension(testFileName) + ".txt");
|
||||
|
||||
NamespaceComparator.compareNamespaces(expected, actual,
|
||||
includeMembersOfObject, filterJetNamespace, serializeResultsTo);
|
||||
NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT.filterOutput(new Predicate<NamespaceDescriptor>() {
|
||||
@Override
|
||||
public boolean apply(NamespaceDescriptor namespaceDescriptor) {
|
||||
return !namespaceDescriptor.getName().equals(Name.identifier("jet"));
|
||||
}
|
||||
}), serializeResultsTo);
|
||||
}
|
||||
|
||||
protected void doTestSinglePackage(String testFileName) throws Exception {
|
||||
doTest(testFileName, false);
|
||||
doTest(testFileName);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public class LazyResolveBuiltinClassesTest extends KotlinTestWithEnvironment {
|
||||
jetNamespaceFromJSL.getName());
|
||||
|
||||
NamespaceComparator.compareNamespaces(jetNamespaceFromJSL, jetNamespaceFromLazy,
|
||||
true, Predicates.<NamespaceDescriptor>alwaysTrue(),
|
||||
NamespaceComparator.RECURSIVE,
|
||||
new File("compiler/testData/builtin-classes.txt"));
|
||||
|
||||
}
|
||||
|
||||
+1
-3
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.lazy;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -62,8 +61,7 @@ public class LazyResolveStdlibLoadingTest extends KotlinTestWithEnvironmentManag
|
||||
for (Name name : namespaceShortNames) {
|
||||
NamespaceDescriptor a = module.getRootNamespace().getMemberScope().getNamespace(name);
|
||||
NamespaceDescriptor b = lazyModule.getRootNamespace().getMemberScope().getNamespace(name);
|
||||
NamespaceComparator.assertNamespacesEqual(a, b,
|
||||
true, Predicates.<NamespaceDescriptor>alwaysTrue());
|
||||
NamespaceComparator.assertNamespacesEqual(a, b, NamespaceComparator.RECURSIVE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,20 +51,10 @@ public class NamespaceComparator {
|
||||
public static void compareNamespaces(
|
||||
@NotNull NamespaceDescriptor nsa,
|
||||
@NotNull NamespaceDescriptor nsb,
|
||||
boolean includeObject,
|
||||
@NotNull Configuration configuration,
|
||||
@NotNull File txtFile
|
||||
) {
|
||||
compareNamespaces(nsa, nsb, includeObject, Predicates.<NamespaceDescriptor>alwaysTrue(), txtFile);
|
||||
}
|
||||
|
||||
public static void compareNamespaces(
|
||||
@NotNull NamespaceDescriptor nsa,
|
||||
@NotNull NamespaceDescriptor nsb,
|
||||
boolean includeObject,
|
||||
@NotNull Predicate<NamespaceDescriptor> includeIntoOutput,
|
||||
@NotNull File txtFile
|
||||
) {
|
||||
String serializedFormWithDemarkedNames = assertNamespacesEqual(nsa, nsb, includeObject, includeIntoOutput);
|
||||
String serializedFormWithDemarkedNames = assertNamespacesEqual(nsa, nsb, configuration);
|
||||
// The serializer puts "!" in front of the name because it allows for speedy sorting of members
|
||||
// see MemberComparator.normalize()
|
||||
String serialized = serializedFormWithDemarkedNames.replace("!", "");
|
||||
@@ -83,23 +73,43 @@ public class NamespaceComparator {
|
||||
}
|
||||
}
|
||||
|
||||
public static String assertNamespacesEqual(NamespaceDescriptor nsa,
|
||||
public static String assertNamespacesEqual(
|
||||
NamespaceDescriptor nsa,
|
||||
NamespaceDescriptor nsb,
|
||||
boolean includeObject,
|
||||
Predicate<NamespaceDescriptor> includeIntoOutput) {
|
||||
NamespaceComparator comparator = new NamespaceComparator(includeObject, includeIntoOutput);
|
||||
@NotNull Configuration configuration
|
||||
) {
|
||||
NamespaceComparator comparator = new NamespaceComparator(configuration);
|
||||
String serialized = comparator.doCompareNamespaces(nsa, nsb);
|
||||
comparator.deferred.throwFailures();
|
||||
return serialized;
|
||||
}
|
||||
|
||||
private final boolean includeObject;
|
||||
private final Predicate<NamespaceDescriptor> includeIntoOutput;
|
||||
public static final Configuration DONT_INCLUDE_METHODS_OF_OBJECT = new Configuration(false, true, Predicates.<NamespaceDescriptor>alwaysTrue());
|
||||
public static final Configuration RECURSIVE = new Configuration(true, true, Predicates.<NamespaceDescriptor>alwaysTrue());
|
||||
public static final Configuration NON_RECURSIVE = new Configuration(true, true, Predicates.<NamespaceDescriptor>alwaysTrue());
|
||||
|
||||
public static class Configuration {
|
||||
|
||||
private final boolean includeObject;
|
||||
private final boolean recursive;
|
||||
private final Predicate<NamespaceDescriptor> includeIntoOutput;
|
||||
|
||||
public Configuration(boolean includeObject, boolean recursive, Predicate<NamespaceDescriptor> includeIntoOutput) {
|
||||
this.includeObject = includeObject;
|
||||
this.recursive = recursive;
|
||||
this.includeIntoOutput = includeIntoOutput;
|
||||
}
|
||||
|
||||
public Configuration filterOutput(@NotNull Predicate<NamespaceDescriptor> includeIntoOutput) {
|
||||
return new Configuration(includeObject, recursive, includeIntoOutput);
|
||||
}
|
||||
}
|
||||
|
||||
private final Configuration conf;
|
||||
private final DeferredAssertions deferred = new DeferredAssertions();
|
||||
|
||||
private NamespaceComparator(boolean includeObject, Predicate<NamespaceDescriptor> includeIntoOutput) {
|
||||
this.includeObject = includeObject;
|
||||
this.includeIntoOutput = includeIntoOutput;
|
||||
private NamespaceComparator(@NotNull Configuration conf) {
|
||||
this.conf = conf;
|
||||
}
|
||||
|
||||
private String doCompareNamespaces(@NotNull NamespaceDescriptor nsa, @NotNull NamespaceDescriptor nsb) {
|
||||
@@ -125,18 +135,20 @@ public class NamespaceComparator {
|
||||
functionNames.add(ad.getName());
|
||||
}
|
||||
else if (ad instanceof NamespaceDescriptor) {
|
||||
NamespaceDescriptor namespaceDescriptorA = (NamespaceDescriptor) ad;
|
||||
NamespaceDescriptor namespaceDescriptorB = nsb.getMemberScope().getNamespace(namespaceDescriptorA.getName());
|
||||
//deferred.assertNotNull("Namespace not found: " + namespaceDescriptorA.getQualifiedName(), namespaceDescriptorB);
|
||||
if (namespaceDescriptorB == null) {
|
||||
System.err.println("Namespace not found: " + namespaceDescriptorA.getQualifiedName());
|
||||
}
|
||||
else {
|
||||
String comparison = doCompareNamespaces(namespaceDescriptorA, namespaceDescriptorB);
|
||||
if (includeIntoOutput.apply(namespaceDescriptorA)) {
|
||||
sb.append("// <namespace name=\"" + namespaceDescriptorA.getName() + "\">\n");
|
||||
sb.append(comparison);
|
||||
sb.append("// </namespace name=\"" + namespaceDescriptorA.getName() + "\">\n");
|
||||
if (conf.recursive) {
|
||||
NamespaceDescriptor namespaceDescriptorA = (NamespaceDescriptor) ad;
|
||||
NamespaceDescriptor namespaceDescriptorB = nsb.getMemberScope().getNamespace(namespaceDescriptorA.getName());
|
||||
//deferred.assertNotNull("Namespace not found: " + namespaceDescriptorA.getQualifiedName(), namespaceDescriptorB);
|
||||
if (namespaceDescriptorB == null) {
|
||||
System.err.println("Namespace not found: " + namespaceDescriptorA.getQualifiedName());
|
||||
}
|
||||
else {
|
||||
String comparison = doCompareNamespaces(namespaceDescriptorA, namespaceDescriptorB);
|
||||
if (conf.includeIntoOutput.apply(namespaceDescriptorA)) {
|
||||
sb.append("// <namespace name=\"" + namespaceDescriptorA.getName() + "\">\n");
|
||||
sb.append(comparison);
|
||||
sb.append("// </namespace name=\"" + namespaceDescriptorA.getName() + "\">\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -702,7 +714,7 @@ public class NamespaceComparator {
|
||||
|
||||
JetScope memberScope = klass.getMemberScope(typeArguments);
|
||||
for (DeclarationDescriptor member : memberScope.getAllDescriptors()) {
|
||||
if (!includeObject) {
|
||||
if (!conf.includeObject) {
|
||||
if (member.getName().getName().matches("equals|hashCode|finalize|wait|notify(All)?|toString|clone|getClass")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user