diff --git a/modules/decima-model/src/main/java/com/shade/decima/model/base/CoreBinary.java b/modules/decima-model/src/main/java/com/shade/decima/model/base/CoreBinary.java index 6ff7a1eba..42eb47cd2 100644 --- a/modules/decima-model/src/main/java/com/shade/decima/model/base/CoreBinary.java +++ b/modules/decima-model/src/main/java/com/shade/decima/model/base/CoreBinary.java @@ -92,18 +92,6 @@ public byte[] write(@NotNull RTTICoreFile file) { } } - @Nullable - @Override - public RTTIObject findObject(@NotNull Predicate predicate) { - for (RTTIObject object : objects) { - if (predicate.test(object)) { - return object; - } - } - - return null; - } - @Override public void visitAllObjects(@NotNull Class type, @NotNull Consumer consumer) { visitAllObjects(type::isInstance, consumer); diff --git a/modules/decima-model/src/main/java/com/shade/decima/model/rtti/RTTICoreFile.java b/modules/decima-model/src/main/java/com/shade/decima/model/rtti/RTTICoreFile.java index ea2304cfa..d372ed959 100644 --- a/modules/decima-model/src/main/java/com/shade/decima/model/rtti/RTTICoreFile.java +++ b/modules/decima-model/src/main/java/com/shade/decima/model/rtti/RTTICoreFile.java @@ -2,19 +2,14 @@ import com.shade.decima.model.rtti.objects.RTTIObject; import com.shade.util.NotNull; -import com.shade.util.Nullable; import java.util.List; import java.util.function.Consumer; -import java.util.function.Predicate; public interface RTTICoreFile { @NotNull List objects(); - @Nullable - RTTIObject findObject(@NotNull Predicate predicate); - void visitAllObjects(@NotNull String type, @NotNull Consumer consumer); void visitAllObjects(@NotNull Class type, @NotNull Consumer consumer); diff --git a/modules/decima-model/src/main/java/com/shade/decima/model/rtti/objects/RTTIReference.java b/modules/decima-model/src/main/java/com/shade/decima/model/rtti/objects/RTTIReference.java index d21c2b5bf..b270d855a 100644 --- a/modules/decima-model/src/main/java/com/shade/decima/model/rtti/objects/RTTIReference.java +++ b/modules/decima-model/src/main/java/com/shade/decima/model/rtti/objects/RTTIReference.java @@ -39,13 +39,7 @@ public FollowResult follow(@NotNull Project project, @NotNull RTTICoreFile curre final ArchiveFile file = packfile.getFile(path); final RTTICoreFile core = project.getCoreFileReader().read(file, true); - final RTTIObject object = core.findObject(obj -> obj.uuid().equals(uuid)); - - if (object == null) { - throw new IOException("Couldn't find referenced entry: " + RTTIUtils.uuidToString(uuid)); - } - - return new FollowResult(core, object); + return Internal.follow(core, uuid); } } @@ -53,13 +47,23 @@ record Internal(@NotNull Kind kind, @NotNull RTTIObject uuid) implements RTTIRef @NotNull @Override public FollowResult follow(@NotNull Project project, @NotNull RTTICoreFile current) throws IOException { - final RTTIObject object = current.findObject(obj -> obj.uuid().equals(uuid)); + return follow(current); + } - if (object == null) { - throw new IOException("Couldn't find referenced entry: " + RTTIUtils.uuidToString(uuid)); + @NotNull + public FollowResult follow(@NotNull RTTICoreFile current) throws IOException { + return follow(current, uuid); + } + + @NotNull + private static FollowResult follow(@NotNull RTTICoreFile current, @NotNull RTTIObject uuid) throws IOException { + for (RTTIObject object : current.objects()) { + if (object.uuid().equals(uuid)) { + return new FollowResult(current, object); + } } - return new FollowResult(current, object); + throw new IOException("Couldn't find referenced object: " + RTTIUtils.uuidToString(uuid)); } } diff --git a/modules/decima-ui/src/main/java/com/shade/decima/ui/editor/core/menu/ShowGraphItem.java b/modules/decima-ui/src/main/java/com/shade/decima/ui/editor/core/menu/ShowGraphItem.java index 4bafb936a..ca6756dce 100644 --- a/modules/decima-ui/src/main/java/com/shade/decima/ui/editor/core/menu/ShowGraphItem.java +++ b/modules/decima-ui/src/main/java/com/shade/decima/ui/editor/core/menu/ShowGraphItem.java @@ -2,6 +2,7 @@ import com.shade.decima.model.rtti.RTTIClass; import com.shade.decima.model.rtti.RTTICoreFile; +import com.shade.decima.model.rtti.RTTIUtils; import com.shade.decima.model.rtti.objects.RTTIObject; import com.shade.decima.model.rtti.objects.RTTIReference; import com.shade.decima.model.rtti.path.RTTIPath; @@ -24,6 +25,8 @@ import com.shade.platform.ui.menus.MenuItemRegistration; import com.shade.util.NotNull; import com.shade.util.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.swing.*; import java.awt.*; @@ -35,6 +38,8 @@ @MenuItemRegistration(parent = CTX_MENU_CORE_EDITOR_ID, name = "Show &Graph", keystroke = "ctrl alt U", group = CTX_MENU_CORE_EDITOR_GROUP_GENERAL, order = 3000) public class ShowGraphItem extends MenuItem { + private static final Logger log = LoggerFactory.getLogger(ShowGraphItem.class); + @Override public void perform(@NotNull MenuItemContext ctx) { final CoreEditor editor = (CoreEditor) ctx.getData(PlatformDataKeys.EDITOR_KEY); @@ -151,10 +156,12 @@ private static void buildGraph(@NotNull RTTICoreFile file, @NotNull RTTIObject s buildGraph(file, source, element, graph); } } else if (object instanceof RTTIReference.Internal ref) { - final RTTIObject target = file.findObject(obj -> obj.uuid().equals(ref.uuid())); - if (target != null) { + try { + final RTTIObject target = ref.follow(file).object(); graph.addVertex(target); graph.addEdge(source, target); + } catch (Exception e) { + log.warn("Can't find referenced local object: {}", RTTIUtils.uuidToString(ref.uuid()), e); } } }