Simplified code in NamespaceComparator.
This commit is contained in:
@@ -39,6 +39,7 @@ import org.junit.Assert;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -78,47 +79,21 @@ public class NamespaceComparator {
|
|||||||
printer.print(isPrimaryConstructor && conf.checkPrimaryConstructors ? "/*primary*/ " : "", RENDERER.render(descriptor));
|
printer.print(isPrimaryConstructor && conf.checkPrimaryConstructors ? "/*primary*/ " : "", RENDERER.render(descriptor));
|
||||||
|
|
||||||
if (descriptor instanceof ClassOrNamespaceDescriptor) {
|
if (descriptor instanceof ClassOrNamespaceDescriptor) {
|
||||||
if (topLevel) {
|
if (!topLevel) {
|
||||||
printer.println();
|
|
||||||
printer.println();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printer.printlnWithNoIndent(" {").pushIndent();
|
printer.printlnWithNoIndent(" {").pushIndent();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
List<DeclarationDescriptor> subDescriptors = Lists.newArrayList();
|
printer.println();
|
||||||
|
printer.println();
|
||||||
|
}
|
||||||
|
|
||||||
if (descriptor instanceof ClassDescriptor) {
|
if (descriptor instanceof ClassDescriptor) {
|
||||||
ClassDescriptor klass = (ClassDescriptor) descriptor;
|
ClassDescriptor klass = (ClassDescriptor) descriptor;
|
||||||
JetScope memberScope = klass.getDefaultType().getMemberScope();
|
appendSubDescriptors(klass.getDefaultType().getMemberScope(), getConstructorsAndClassObject(klass), printer);
|
||||||
|
|
||||||
subDescriptors.addAll(klass.getConstructors());
|
|
||||||
subDescriptors.addAll(memberScope.getAllDescriptors());
|
|
||||||
subDescriptors.addAll(memberScope.getObjectDescriptors());
|
|
||||||
ContainerUtil.addIfNotNull(subDescriptors, klass.getClassObjectDescriptor());
|
|
||||||
}
|
}
|
||||||
else if (descriptor instanceof NamespaceDescriptor) {
|
else if (descriptor instanceof NamespaceDescriptor) {
|
||||||
JetScope memberScope = ((NamespaceDescriptor) descriptor).getMemberScope();
|
appendSubDescriptors(((NamespaceDescriptor) descriptor).getMemberScope(),
|
||||||
subDescriptors.addAll(memberScope.getAllDescriptors());
|
Collections.<DeclarationDescriptor>emptyList(), printer);
|
||||||
subDescriptors.addAll(memberScope.getObjectDescriptors());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalStateException("Should be class or namespace: " + descriptor.getClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(subDescriptors, MemberComparator.INSTANCE);
|
|
||||||
|
|
||||||
for (DeclarationDescriptor subDescriptor : subDescriptors) {
|
|
||||||
if (!conf.includeMethodsOfJavaObject && subDescriptor instanceof FunctionDescriptor
|
|
||||||
&& JAVA_OBJECT_METHOD_NAMES.contains(subDescriptor.getName().getName())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (subDescriptor instanceof NamespaceDescriptor && !conf.recurseIntoPackage.apply(DescriptorUtils.getFQName(subDescriptor))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
appendDeclarationRecursively(subDescriptor, printer, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!topLevel) {
|
if (!topLevel) {
|
||||||
@@ -130,6 +105,43 @@ public class NamespaceComparator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static List<DeclarationDescriptor> getConstructorsAndClassObject(@NotNull ClassDescriptor klass) {
|
||||||
|
List<DeclarationDescriptor> constructorsAndClassObject = Lists.newArrayList();
|
||||||
|
constructorsAndClassObject.addAll(klass.getConstructors());
|
||||||
|
ContainerUtil.addIfNotNull(constructorsAndClassObject, klass.getClassObjectDescriptor());
|
||||||
|
return constructorsAndClassObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean shouldSkip(@NotNull DeclarationDescriptor subDescriptor) {
|
||||||
|
return subDescriptor.getContainingDeclaration() instanceof ClassDescriptor
|
||||||
|
&& subDescriptor instanceof FunctionDescriptor
|
||||||
|
&& JAVA_OBJECT_METHOD_NAMES.contains(subDescriptor.getName().getName())
|
||||||
|
&& !conf.includeMethodsOfJavaObject
|
||||||
|
||
|
||||||
|
subDescriptor instanceof NamespaceDescriptor && !conf.recurseIntoPackage.apply(DescriptorUtils.getFQName(subDescriptor));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendSubDescriptors(
|
||||||
|
@NotNull JetScope memberScope,
|
||||||
|
@NotNull Collection<DeclarationDescriptor> extraSubDescriptors,
|
||||||
|
@NotNull Printer printer
|
||||||
|
) {
|
||||||
|
List<DeclarationDescriptor> subDescriptors = Lists.newArrayList();
|
||||||
|
|
||||||
|
subDescriptors.addAll(memberScope.getAllDescriptors());
|
||||||
|
subDescriptors.addAll(memberScope.getObjectDescriptors());
|
||||||
|
subDescriptors.addAll(extraSubDescriptors);
|
||||||
|
|
||||||
|
Collections.sort(subDescriptors, MemberComparator.INSTANCE);
|
||||||
|
|
||||||
|
for (DeclarationDescriptor subDescriptor : subDescriptors) {
|
||||||
|
if (!shouldSkip(subDescriptor)) {
|
||||||
|
appendDeclarationRecursively(subDescriptor, printer, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void compareNamespaceWithFile(
|
public static void compareNamespaceWithFile(
|
||||||
@NotNull NamespaceDescriptor actualNamespace,
|
@NotNull NamespaceDescriptor actualNamespace,
|
||||||
@NotNull Configuration configuration,
|
@NotNull Configuration configuration,
|
||||||
|
|||||||
Reference in New Issue
Block a user