-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor MappingApplier to not be workspace-scoped, and usable for an…
…y arbitrary workspace
- Loading branch information
Showing
9 changed files
with
166 additions
and
74 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
85 changes: 85 additions & 0 deletions
85
recaf-core/src/main/java/software/coley/recaf/services/mapping/MappingApplierService.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,85 @@ | ||
package software.coley.recaf.services.mapping; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import jakarta.annotation.Nullable; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import software.coley.recaf.services.Service; | ||
import software.coley.recaf.services.inheritance.InheritanceGraph; | ||
import software.coley.recaf.services.inheritance.InheritanceGraphService; | ||
import software.coley.recaf.services.mapping.aggregate.AggregateMappingManager; | ||
import software.coley.recaf.services.workspace.WorkspaceManager; | ||
import software.coley.recaf.util.threading.ThreadPoolFactory; | ||
import software.coley.recaf.workspace.model.Workspace; | ||
|
||
import java.util.Objects; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
/** | ||
* Service offering the creation of {@link MappingApplier mapping appliers} for workspaces. | ||
* | ||
* @author Matt Coley | ||
* @see MappingApplier | ||
*/ | ||
@ApplicationScoped | ||
public class MappingApplierService implements Service { | ||
public static final String SERVICE_ID = "mapping-applier"; | ||
private static final ExecutorService applierThreadPool = ThreadPoolFactory.newFixedThreadPool(SERVICE_ID); | ||
private final InheritanceGraphService inheritanceGraphService; | ||
private final AggregateMappingManager aggregateMappingManager; | ||
private final MappingListeners listeners; | ||
private final WorkspaceManager workspaceManager; | ||
private final MappingApplierConfig config; | ||
|
||
@Inject | ||
public MappingApplierService(@Nonnull MappingApplierConfig config, | ||
@Nonnull InheritanceGraphService inheritanceGraphService, | ||
@Nonnull AggregateMappingManager aggregateMappingManager, | ||
@Nonnull MappingListeners listeners, | ||
@Nonnull WorkspaceManager workspaceManager) { | ||
this.inheritanceGraphService = inheritanceGraphService; | ||
this.aggregateMappingManager = aggregateMappingManager; | ||
this.listeners = listeners; | ||
this.workspaceManager = workspaceManager; | ||
this.config = config; | ||
} | ||
|
||
/** | ||
* @param workspace | ||
* Workspace to apply mappings in. | ||
* | ||
* @return Applier for the given workspace. | ||
*/ | ||
@Nonnull | ||
public MappingApplier inWorkspace(@Nonnull Workspace workspace) { | ||
if (workspace == workspaceManager.getCurrent()) | ||
return Objects.requireNonNull(inCurrentWorkspace(), "Failed to access current workspace for mapping application"); | ||
return new MappingApplier(workspace, inheritanceGraphService.newInheritanceGraph(workspace), null, null); | ||
} | ||
|
||
/** | ||
* @return Applier for the current workspace, or {@code null} if no workspace is open. | ||
*/ | ||
@Nullable | ||
public MappingApplier inCurrentWorkspace() { | ||
Workspace workspace = workspaceManager.getCurrent(); | ||
if (workspace == null) | ||
return null; | ||
InheritanceGraph currentWorkspaceInheritanceGraph = inheritanceGraphService.getCurrentWorkspaceInheritanceGraph(); | ||
if (currentWorkspaceInheritanceGraph == null) | ||
return null; | ||
return new MappingApplier(workspace, currentWorkspaceInheritanceGraph, listeners, aggregateMappingManager); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getServiceId() { | ||
return SERVICE_ID; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public MappingApplierConfig 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
Oops, something went wrong.