-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor CallGraph to not be tied directly to CDI. Create wrapping se…
…rvice.
- Loading branch information
Showing
9 changed files
with
123 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
recaf-core/src/main/java/software/coley/recaf/services/callgraph/CallGraphService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package software.coley.recaf.services.callgraph; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import jakarta.annotation.Nullable; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import software.coley.recaf.analytics.logging.DebuggingLogger; | ||
import software.coley.recaf.analytics.logging.Logging; | ||
import software.coley.recaf.cdi.EagerInitialization; | ||
import software.coley.recaf.services.Service; | ||
import software.coley.recaf.services.workspace.WorkspaceCloseListener; | ||
import software.coley.recaf.services.workspace.WorkspaceManager; | ||
import software.coley.recaf.services.workspace.WorkspaceOpenListener; | ||
import software.coley.recaf.workspace.model.Workspace; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* Service offering the creation of {@link CallGraph call graphs} for workspaces. | ||
* | ||
* @author Matt Coley | ||
* @see CallGraph | ||
*/ | ||
@EagerInitialization | ||
@ApplicationScoped | ||
public class CallGraphService implements Service, WorkspaceOpenListener, WorkspaceCloseListener { | ||
public static final String SERVICE_ID = "graph-calls"; | ||
private static final DebuggingLogger logger = Logging.get(CallGraphService.class); | ||
private final CallGraphConfig config; | ||
private CallGraph currentWorkspaceGraph; | ||
|
||
/** | ||
* @param workspaceManager | ||
* Manager to register listeners for, in order to manage a shared graph for the current workspace. | ||
* @param config | ||
* Graphing config options. | ||
*/ | ||
@Inject | ||
public CallGraphService(@Nonnull WorkspaceManager workspaceManager, @Nonnull CallGraphConfig config) { | ||
this.config = config; | ||
|
||
workspaceManager.addWorkspaceOpenListener(this); | ||
workspaceManager.addWorkspaceCloseListener(this); | ||
} | ||
|
||
/** | ||
* @param workspace | ||
* Workspace to pull classes from. | ||
* | ||
* @return New call graph model for the given workspace. | ||
*/ | ||
@Nonnull | ||
public CallGraph newGraph(@Nonnull Workspace workspace) { | ||
return new CallGraph(workspace); | ||
} | ||
|
||
/** | ||
* @return Call graph model for the {@link WorkspaceManager#getCurrent() current workspace} or {@code null} | ||
* if no workspace is currently open. | ||
*/ | ||
@Nullable | ||
public CallGraph getCurrentWorkspaceGraph() { | ||
CallGraph graph = currentWorkspaceGraph; | ||
|
||
// Lazily initialize the graph so that we don't do a full graph | ||
if (!graph.isInitialized()) | ||
CompletableFuture.runAsync(graph::initialize); | ||
|
||
return graph; | ||
} | ||
|
||
@Override | ||
public void onWorkspaceOpened(@Nonnull Workspace workspace) { | ||
currentWorkspaceGraph = newGraph(workspace); | ||
} | ||
|
||
@Override | ||
public void onWorkspaceClosed(@Nonnull Workspace workspace) { | ||
currentWorkspaceGraph = null; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getServiceId() { | ||
return SERVICE_ID; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public CallGraphConfig getServiceConfig() { | ||
return config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters