Refactoring: code duplication removed from accessor generators

This commit is contained in:
Mikhael Bogdanov
2013-03-13 12:03:42 +04:00
parent 86f5114b7d
commit d9fd04dd43
32 changed files with 1026 additions and 521 deletions
@@ -36,7 +36,16 @@ import static org.jetbrains.jet.test.util.NamespaceComparator.compareNamespaces;
*/
@SuppressWarnings("JUnitTestCaseWithNoTests")
public abstract class AbstractLoadCompiledKotlinTest extends TestCaseWithTmpdir {
public void doTest(@NotNull String ktFileName) throws Exception {
doTest(ktFileName, false);
}
public void doTestWithAccessors(@NotNull String ktFileName) throws Exception {
doTest(ktFileName, true);
}
private void doTest(@NotNull String ktFileName, boolean includeAccessors) throws Exception {
File ktFile = new File(ktFileName);
File txtFile = new File(ktFileName.replaceFirst("\\.kt$", ".txt"));
AnalyzeExhaust exhaust = compileKotlinToDirAndGetAnalyzeExhaust(ktFile, tmpdir, getTestRootDisposable(),
@@ -49,6 +58,9 @@ public abstract class AbstractLoadCompiledKotlinTest extends TestCaseWithTmpdir
NamespaceDescriptor namespaceFromClass = LoadDescriptorUtil.loadTestNamespaceAndBindingContextFromJavaRoot(
tmpdir, getTestRootDisposable(), ConfigurationKind.JDK_ONLY).first;
compareNamespaces(namespaceFromSource, namespaceFromClass,
NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT.checkPrimaryConstructors(true), txtFile);
NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT
.checkPrimaryConstructors(true)
.checkPropertyAccessors(includeAccessors),
txtFile);
}
}
File diff suppressed because it is too large Load Diff
@@ -42,14 +42,18 @@ public abstract class AbstractLazyResolveNamespaceComparingTest extends KotlinTe
}
protected void doTestCheckingPrimaryConstructors(String testFileName) throws IOException {
doTest(testFileName, true);
doTest(testFileName, true, false);
}
protected void doTestCheckingPrimaryConstructorsAndAccessors(String testFileName) throws IOException {
doTest(testFileName, true, true);
}
protected void doTestNotCheckingPrimaryConstructors(String testFileName) throws IOException {
doTest(testFileName, false);
doTest(testFileName, false, false);
}
private void doTest(String testFileName, boolean checkPrimaryConstructors) throws IOException {
private void doTest(String testFileName, boolean checkPrimaryConstructors, boolean checkPropertyAccessors) throws IOException {
List<JetFile> files = JetTestUtils
.createTestFiles(testFileName, FileUtil.loadFile(new File(testFileName), true),
new JetTestUtils.TestFileFactory<JetFile>() {
@@ -75,6 +79,6 @@ public abstract class AbstractLazyResolveNamespaceComparingTest extends KotlinTe
public boolean apply(FqNameUnsafe fqName) {
return !KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.toUnsafe().equals(fqName);
}
}).checkPrimaryConstructors(checkPrimaryConstructors), serializeResultsTo);
}).checkPrimaryConstructors(checkPrimaryConstructors).checkPropertyAccessors(checkPropertyAccessors), serializeResultsTo);
}
}
@@ -45,8 +45,8 @@ import java.util.Collections;
import java.util.List;
public class NamespaceComparator {
public static final Configuration DONT_INCLUDE_METHODS_OF_OBJECT = new Configuration(false, false, Predicates.<FqNameUnsafe>alwaysTrue());
public static final Configuration RECURSIVE = new Configuration(false, true, Predicates.<FqNameUnsafe>alwaysTrue());
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());
private static final DescriptorRenderer RENDERER = new DescriptorRendererBuilder()
.setWithDefinedIn(false)
@@ -98,6 +98,22 @@ public class NamespaceComparator {
printer.popIndent().println("}");
}
}
else if (conf.checkPropertyAccessors && descriptor instanceof PropertyDescriptor) {
printer.printlnWithNoIndent();
printer.pushIndent();
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
PropertyGetterDescriptor getter = propertyDescriptor.getGetter();
if (getter != null) {
printer.println(RENDERER.render(getter));
}
PropertySetterDescriptor setter = propertyDescriptor.getSetter();
if (setter != null) {
printer.println(RENDERER.render(setter));
}
printer.popIndent();
}
else {
printer.printlnWithNoIndent();
}
@@ -198,25 +214,32 @@ public class NamespaceComparator {
public static class Configuration {
private final boolean checkPrimaryConstructors;
private final boolean checkPropertyAccessors;
private final boolean includeMethodsOfJavaObject;
private final Predicate<FqNameUnsafe> recurseIntoPackage;
public Configuration(
boolean checkPrimaryConstructors,
boolean checkPropertyAccessors,
boolean includeMethodsOfJavaObject,
Predicate<FqNameUnsafe> recurseIntoPackage
) {
this.checkPrimaryConstructors = checkPrimaryConstructors;
this.checkPropertyAccessors = checkPropertyAccessors;
this.includeMethodsOfJavaObject = includeMethodsOfJavaObject;
this.recurseIntoPackage = recurseIntoPackage;
}
public Configuration filterRecursion(@NotNull Predicate<FqNameUnsafe> recurseIntoPackage) {
return new Configuration(checkPrimaryConstructors, includeMethodsOfJavaObject, recurseIntoPackage);
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfJavaObject, recurseIntoPackage);
}
public Configuration checkPrimaryConstructors(boolean checkPrimaryConstructors) {
return new Configuration(checkPrimaryConstructors, includeMethodsOfJavaObject, recurseIntoPackage);
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfJavaObject, recurseIntoPackage);
}
public Configuration checkPropertyAccessors(boolean checkPropertyAccessors) {
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfJavaObject, recurseIntoPackage);
}
}
}