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