Put validation parameter into Configuration
This commit is contained in:
@@ -44,7 +44,6 @@ import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.test.TestCaseWithTmpdir;
|
||||
import org.jetbrains.jet.test.util.DescriptorValidator;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.File;
|
||||
@@ -56,7 +55,6 @@ import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.jvm.compiler.LoadDescriptorUtil.*;
|
||||
import static org.jetbrains.jet.test.util.DescriptorValidator.ValidationVisitor.ALLOW_ERROR_TYPES;
|
||||
import static org.jetbrains.jet.test.util.DescriptorValidator.ValidationVisitor.FORBID_ERROR_TYPES;
|
||||
import static org.jetbrains.jet.test.util.NamespaceComparator.*;
|
||||
|
||||
/*
|
||||
@@ -117,7 +115,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
Pair<NamespaceDescriptor, BindingContext> javaNamespaceAndContext = compileJavaAndLoadTestNamespaceAndBindingContextFromBinary(
|
||||
srcFiles, compiledDir, getTestRootDisposable(), ConfigurationKind.JDK_ONLY);
|
||||
|
||||
checkJavaNamespace(getTxtFile(javaFileName), javaNamespaceAndContext.first, javaNamespaceAndContext.second, configuration, FORBID_ERROR_TYPES);
|
||||
checkJavaNamespace(getTxtFile(javaFileName), javaNamespaceAndContext.first, javaNamespaceAndContext.second, configuration);
|
||||
}
|
||||
|
||||
protected void doTestSourceJava(@NotNull String javaFileName) throws Exception {
|
||||
@@ -131,7 +129,8 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
Pair<NamespaceDescriptor, BindingContext> javaNamespaceAndContext = loadTestNamespaceAndBindingContextFromJavaRoot(
|
||||
tmpdir, getTestRootDisposable(), ConfigurationKind.JDK_ONLY);
|
||||
|
||||
checkJavaNamespace(expectedFile, javaNamespaceAndContext.first, javaNamespaceAndContext.second, DONT_INCLUDE_METHODS_OF_OBJECT, ALLOW_ERROR_TYPES);
|
||||
checkJavaNamespace(expectedFile, javaNamespaceAndContext.first, javaNamespaceAndContext.second,
|
||||
DONT_INCLUDE_METHODS_OF_OBJECT.withValidationStrategy(ALLOW_ERROR_TYPES));
|
||||
}
|
||||
|
||||
protected void doTestJavaAgainstKotlin(String expectedFileName) throws Exception {
|
||||
@@ -175,7 +174,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
LoadDescriptorUtil.TEST_PACKAGE_FQNAME, DescriptorSearchRule.INCLUDE_KOTLIN);
|
||||
assert namespaceDescriptor != null : "Test namespace not found";
|
||||
|
||||
checkJavaNamespace(expectedFile, namespaceDescriptor, trace.getBindingContext(), DONT_INCLUDE_METHODS_OF_OBJECT, FORBID_ERROR_TYPES);
|
||||
checkJavaNamespace(expectedFile, namespaceDescriptor, trace.getBindingContext(), DONT_INCLUDE_METHODS_OF_OBJECT);
|
||||
}
|
||||
|
||||
private static void checkForLoadErrorsAndCompare(
|
||||
@@ -223,13 +222,12 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
final File txtFile,
|
||||
final NamespaceDescriptor javaNamespace,
|
||||
BindingContext bindingContext,
|
||||
final Configuration configuration,
|
||||
final DescriptorValidator.ValidationVisitor validationStrategy
|
||||
final Configuration configuration
|
||||
) {
|
||||
checkForLoadErrorsAndCompare(javaNamespace, bindingContext, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
validateAndCompareNamespaceWithFile(validationStrategy, javaNamespace, configuration, txtFile);
|
||||
validateAndCompareNamespaceWithFile(javaNamespace, configuration, txtFile);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+5
-2
@@ -81,13 +81,16 @@ public abstract class AbstractLazyResolveNamespaceComparingTest extends KotlinTe
|
||||
File serializeResultsTo = new File(FileUtil.getNameWithoutExtension(testFileName) + ".txt");
|
||||
|
||||
NamespaceComparator.validateAndCompareNamespaces(
|
||||
allowErrorTypes ? ALLOW_ERROR_TYPES : FORBID_ERROR_TYPES,
|
||||
expected, actual, NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT.filterRecursion(
|
||||
new Predicate<FqNameUnsafe>() {
|
||||
@Override
|
||||
public boolean apply(FqNameUnsafe fqName) {
|
||||
return !KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.toUnsafe().equals(fqName);
|
||||
}
|
||||
}).checkPrimaryConstructors(checkPrimaryConstructors).checkPropertyAccessors(checkPropertyAccessors), serializeResultsTo);
|
||||
})
|
||||
.checkPrimaryConstructors(checkPrimaryConstructors)
|
||||
.checkPropertyAccessors(checkPropertyAccessors)
|
||||
.withValidationStrategy(allowErrorTypes ? ALLOW_ERROR_TYPES : FORBID_ERROR_TYPES),
|
||||
serializeResultsTo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,9 +47,10 @@ import java.util.List;
|
||||
import static org.jetbrains.jet.test.util.DescriptorValidator.ValidationVisitor.FORBID_ERROR_TYPES;
|
||||
|
||||
public class NamespaceComparator {
|
||||
public static final Configuration DONT_INCLUDE_METHODS_OF_OBJECT = new Configuration(false, false, false, Predicates.<FqNameUnsafe>alwaysTrue());
|
||||
public static final Configuration RECURSIVE = new Configuration(false, false, true, Predicates.<FqNameUnsafe>alwaysTrue());
|
||||
public static final Configuration RECURSIVE_ALL = new Configuration(true, true, true, Predicates.<FqNameUnsafe>alwaysTrue());
|
||||
public static final Configuration DONT_INCLUDE_METHODS_OF_OBJECT = new Configuration(false, false, false, Predicates.<FqNameUnsafe>alwaysTrue(),
|
||||
FORBID_ERROR_TYPES);
|
||||
public static final Configuration RECURSIVE = new Configuration(false, false, true, Predicates.<FqNameUnsafe>alwaysTrue(), FORBID_ERROR_TYPES);
|
||||
public static final Configuration RECURSIVE_ALL = new Configuration(true, true, true, Predicates.<FqNameUnsafe>alwaysTrue(), FORBID_ERROR_TYPES);
|
||||
|
||||
private static final DescriptorRenderer RENDERER = new DescriptorRendererBuilder()
|
||||
.setWithDefinedIn(false)
|
||||
@@ -160,7 +161,7 @@ public class NamespaceComparator {
|
||||
}
|
||||
}
|
||||
|
||||
public static void compareNamespaceWithFile(
|
||||
private static void compareNamespaceWithFile(
|
||||
@NotNull NamespaceDescriptor actualNamespace,
|
||||
@NotNull Configuration configuration,
|
||||
@NotNull File txtFile
|
||||
@@ -168,7 +169,7 @@ public class NamespaceComparator {
|
||||
doCompareNamespaces(null, actualNamespace, configuration, txtFile);
|
||||
}
|
||||
|
||||
public static void compareNamespaces(
|
||||
private static void compareNamespaces(
|
||||
@NotNull NamespaceDescriptor expectedNamespace,
|
||||
@NotNull NamespaceDescriptor actualNamespace,
|
||||
@NotNull Configuration configuration,
|
||||
@@ -182,40 +183,21 @@ public class NamespaceComparator {
|
||||
}
|
||||
|
||||
public static void validateAndCompareNamespaceWithFile(
|
||||
@NotNull NamespaceDescriptor actualNamespace,
|
||||
@NotNull Configuration configuration,
|
||||
@NotNull File txtFile
|
||||
) {
|
||||
validateAndCompareNamespaceWithFile(FORBID_ERROR_TYPES, actualNamespace, configuration, txtFile);
|
||||
}
|
||||
|
||||
public static void validateAndCompareNamespaceWithFile(
|
||||
@NotNull DescriptorValidator.ValidationVisitor validationStrategy,
|
||||
@NotNull NamespaceDescriptor actualNamespace,
|
||||
@NotNull Configuration configuration,
|
||||
@NotNull File txtFile
|
||||
) {
|
||||
DescriptorValidator.validate(validationStrategy, actualNamespace);
|
||||
DescriptorValidator.validate(configuration.validationStrategy, actualNamespace);
|
||||
compareNamespaceWithFile(actualNamespace, configuration, txtFile);
|
||||
}
|
||||
|
||||
public static void validateAndCompareNamespaces(
|
||||
@NotNull NamespaceDescriptor expectedNamespace,
|
||||
@NotNull NamespaceDescriptor actualNamespace,
|
||||
@NotNull Configuration configuration,
|
||||
@Nullable File txtFile
|
||||
) {
|
||||
validateAndCompareNamespaces(FORBID_ERROR_TYPES, expectedNamespace, actualNamespace, configuration, txtFile);
|
||||
}
|
||||
|
||||
public static void validateAndCompareNamespaces(
|
||||
@NotNull DescriptorValidator.ValidationVisitor validationStrategy,
|
||||
@NotNull NamespaceDescriptor expectedNamespace,
|
||||
@NotNull NamespaceDescriptor actualNamespace,
|
||||
@NotNull Configuration configuration,
|
||||
@Nullable File txtFile
|
||||
) {
|
||||
DescriptorValidator.validate(validationStrategy, expectedNamespace, actualNamespace);
|
||||
DescriptorValidator.validate(configuration.validationStrategy, expectedNamespace, actualNamespace);
|
||||
compareNamespaces(expectedNamespace, actualNamespace, configuration, txtFile);
|
||||
}
|
||||
|
||||
@@ -260,28 +242,40 @@ public class NamespaceComparator {
|
||||
private final boolean includeMethodsOfJavaObject;
|
||||
private final Predicate<FqNameUnsafe> recurseIntoPackage;
|
||||
|
||||
private final DescriptorValidator.ValidationVisitor validationStrategy;
|
||||
|
||||
public Configuration(
|
||||
boolean checkPrimaryConstructors,
|
||||
boolean checkPropertyAccessors,
|
||||
boolean includeMethodsOfJavaObject,
|
||||
Predicate<FqNameUnsafe> recurseIntoPackage
|
||||
Predicate<FqNameUnsafe> recurseIntoPackage,
|
||||
DescriptorValidator.ValidationVisitor validationStrategy
|
||||
) {
|
||||
this.checkPrimaryConstructors = checkPrimaryConstructors;
|
||||
this.checkPropertyAccessors = checkPropertyAccessors;
|
||||
this.includeMethodsOfJavaObject = includeMethodsOfJavaObject;
|
||||
this.recurseIntoPackage = recurseIntoPackage;
|
||||
this.validationStrategy = validationStrategy;
|
||||
}
|
||||
|
||||
public Configuration filterRecursion(@NotNull Predicate<FqNameUnsafe> recurseIntoPackage) {
|
||||
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfJavaObject, recurseIntoPackage);
|
||||
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfJavaObject, recurseIntoPackage,
|
||||
validationStrategy);
|
||||
}
|
||||
|
||||
public Configuration checkPrimaryConstructors(boolean checkPrimaryConstructors) {
|
||||
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfJavaObject, recurseIntoPackage);
|
||||
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfJavaObject, recurseIntoPackage,
|
||||
validationStrategy);
|
||||
}
|
||||
|
||||
public Configuration checkPropertyAccessors(boolean checkPropertyAccessors) {
|
||||
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfJavaObject, recurseIntoPackage);
|
||||
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfJavaObject, recurseIntoPackage,
|
||||
validationStrategy);
|
||||
}
|
||||
|
||||
public Configuration withValidationStrategy(@NotNull DescriptorValidator.ValidationVisitor validationStrategy) {
|
||||
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfJavaObject, recurseIntoPackage,
|
||||
validationStrategy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user