Skip to content

Commit

Permalink
Change path name comparison to be naturally ordered (alpha-numeric)
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Jun 12, 2024
1 parent 860e4de commit 0ccfae9
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 10 deletions.
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ llzip = "2.5.0"
logback-classic = { strictly = "1.4.11" } # newer releases break in jar releases
mapping-io = "0.5.1"
mockito = "5.11.0"
natural-order = "1.1"
openrewrite = "8.19.0"
picocli = "4.7.5"
procyon = "0.6.0"
Expand Down Expand Up @@ -104,6 +105,8 @@ mapping-io = { module = "net.fabricmc:mapping-io", version.ref = "mapping-io" }

mockito = { module = "org.mockito:mockito-core", version.ref = "mockito" }

natural-order = { module = "net.grey-panther:natural-comparator", version.ref = "natural-order" }

openrewrite = { module = "org.openrewrite:rewrite-java-17", version.ref = "openrewrite" }

picocli = { module = "info.picocli:picocli", version.ref = "picocli" }
Expand Down
1 change: 1 addition & 0 deletions recaf-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
api(libs.llzip)
api(libs.bundles.logging)
api(libs.mapping.io)
api(libs.natural.order)
api(libs.picocli)
api(libs.procyon)
api(libs.jackson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator;
import software.coley.recaf.workspace.model.bundle.AndroidClassBundle;
import software.coley.recaf.workspace.model.bundle.Bundle;
import software.coley.recaf.workspace.model.bundle.JvmClassBundle;
Expand Down Expand Up @@ -138,7 +139,7 @@ public int localCompare(PathNode<?> o) {
.map(Map.Entry::getKey)
.findFirst()
.orElse(null);
return String.CASE_INSENSITIVE_ORDER.compare(dexName, otherDexName);
return CaseInsensitiveSimpleNaturalComparator.getInstance().compare(dexName, otherDexName);
}
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator;
import org.objectweb.asm.tree.AbstractInsnNode;
import software.coley.recaf.info.ClassInfo;
import software.coley.recaf.info.InnerClassInfo;
Expand Down Expand Up @@ -188,7 +189,7 @@ public int localCompare(PathNode<?> o) {
// Just sort alphabetically if parent not known.
String key = member.getName() + member.getDescriptor();
String otherKey = otherMember.getName() + member.getDescriptor();
cmp = String.CASE_INSENSITIVE_ORDER.compare(key, otherKey);
cmp = CaseInsensitiveSimpleNaturalComparator.getInstance().compare(key, otherKey);
}
return cmp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator;
import software.coley.recaf.info.ClassInfo;
import software.coley.recaf.info.InnerClassInfo;
import software.coley.recaf.info.annotation.AnnotationInfo;
Expand Down Expand Up @@ -134,7 +135,7 @@ public int localCompare(PathNode<?> o) {
if (o instanceof ClassPathNode classPathNode) {
String name = getValue().getName();
String otherName = classPathNode.getValue().getName();
return String.CASE_INSENSITIVE_ORDER.compare(name, otherName);
return CaseInsensitiveSimpleNaturalComparator.getInstance().compare(name, otherName);
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator;
import software.coley.recaf.info.ClassInfo;
import software.coley.recaf.info.FileInfo;
import software.coley.recaf.workspace.model.bundle.Bundle;
Expand Down Expand Up @@ -124,7 +125,7 @@ public int localCompare(PathNode<?> o) {
if (o instanceof DirectoryPathNode pathNode) {
String name = getValue();
String otherName = pathNode.getValue();
return String.CASE_INSENSITIVE_ORDER.compare(name, otherName);
return CaseInsensitiveSimpleNaturalComparator.getInstance().compare(name, otherName);
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator;
import software.coley.recaf.info.ClassInfo;
import software.coley.recaf.info.FileInfo;

Expand Down Expand Up @@ -87,7 +88,7 @@ public int localCompare(PathNode<?> o) {
if (o instanceof FilePathNode fileNode) {
String name = getValue().getName();
String otherName = fileNode.getValue().getName();
return String.CASE_INSENSITIVE_ORDER.compare(name, otherName);
return CaseInsensitiveSimpleNaturalComparator.getInstance().compare(name, otherName);
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator;
import software.coley.recaf.info.ClassInfo;
import software.coley.recaf.info.InnerClassInfo;
import software.coley.recaf.info.annotation.AnnotationInfo;
Expand Down Expand Up @@ -63,7 +64,7 @@ public int localCompare(PathNode<?> o) {
if (o instanceof InnerClassPathNode innerClassPathNode) {
String name = getValue().getInnerClassName();
String otherName = innerClassPathNode.getValue().getInnerClassName();
return String.CASE_INSENSITIVE_ORDER.compare(name, otherName);
return CaseInsensitiveSimpleNaturalComparator.getInstance().compare(name, otherName);
}

// Show before members
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator;
import software.coley.collections.Maps;
import software.coley.collections.Unchecked;
import software.coley.recaf.workspace.model.Workspace;
Expand Down Expand Up @@ -114,7 +115,7 @@ public int localCompare(PathNode<?> o) {
Map<WorkspaceFileResource, String> lookup = Maps.reverse(parentOfParent.getValue().getEmbeddedResources());
String ourKey = lookup.getOrDefault(resource, "?");
String otherKey = lookup.getOrDefault(otherResource, "?");
return String.CASE_INSENSITIVE_ORDER.compare(ourKey, otherKey);
return CaseInsensitiveSimpleNaturalComparator.getInstance().compare(ourKey, otherKey);
} else {
if (workspace != null) {
if (resource == otherResource)
Expand All @@ -125,7 +126,7 @@ public int localCompare(PathNode<?> o) {
return Integer.compare(resources.indexOf(resource), resources.indexOf(otherResource));
} else {
// Enforce some ordering. Not ideal but works.
return String.CASE_INSENSITIVE_ORDER.compare(
return CaseInsensitiveSimpleNaturalComparator.getInstance().compare(
resource.getClass().getSimpleName(),
otherResource.getClass().getSimpleName()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import jakarta.annotation.Nullable;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator;
import software.coley.recaf.info.*;
import software.coley.recaf.path.*;
import software.coley.recaf.services.cell.CellConfigurationService;
Expand Down Expand Up @@ -106,7 +107,7 @@ private void createResourceSubTree(@Nonnull WorkspaceResource resource) {
if (!embeddedResources.isEmpty()) {
EmbeddedResourceContainerPathNode containerPath = resourcePath.embeddedChildContainer();
embeddedResources.entrySet().stream() // Insert in sorted order of path name
.sorted((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getKey(), o2.getKey()))
.sorted((o1, o2) -> CaseInsensitiveSimpleNaturalComparator.getInstance().compare(o1.getKey(), o2.getKey()))
.map(Map.Entry::getValue)
.forEach(embeddedResource -> {
ResourcePathNode resourcePathEmbedded = containerPath.child(embeddedResource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator;
import org.kordamp.ikonli.carbonicons.CarbonIcons;
import software.coley.recaf.info.Accessed;
import software.coley.recaf.info.ClassInfo;
Expand Down Expand Up @@ -175,7 +176,7 @@ private void refreshTreeSort() {
// Then by alphabetic order.
if (result == 0 && sortAlphabetically.get()) {
if (valueA instanceof Named namedA && valueB instanceof Named namedB) {
result = String.CASE_INSENSITIVE_ORDER.compare(namedA.getName(), namedB.getName());
result = CaseInsensitiveSimpleNaturalComparator.getInstance().compare(namedA.getName(), namedB.getName());
}
}

Expand Down

0 comments on commit 0ccfae9

Please sign in to comment.