Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: impl MultiInstance inject MultiInstance #240
feat: impl MultiInstance inject MultiInstance #240
Changes from all commits
eb8fb2e
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace 'this' with class name in static method for clarity.
Using
this
in static methods can be confusing becausethis
refers to the class itself. It's clearer to reference the class name directly. Replacethis.multiInstanceClazzSet
withLoadUnitMultiInstanceProtoHook.multiInstanceClazzSet
to improve readability.Apply this diff to enhance clarity:
📝 Committable suggestion
🧰 Tools
🪛 Biome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace 'this' with class name in static method for clarity.
Similarly, in the
clear
method, replacingthis
with the class name makes it explicit and avoids confusion. Changethis.multiInstanceClazzSet
toLoadUnitMultiInstanceProtoHook.multiInstanceClazzSet
.Apply this diff to enhance clarity:
📝 Committable suggestion
🧰 Tools
🪛 Biome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider refactoring to reduce code duplication between
ProtoNode
andMultiInstanceProtoNode
The classes
ProtoNode
andMultiInstanceProtoNode
share several properties and methods, such asclazz
,name
,id
,qualifiers
,initType
, and thetoString()
method. To enhance maintainability and reduce code duplication, consider extracting the shared functionality into a base class or interface that both classes can extend or implement.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Simplify node creation logic in the
build
methodIn the
build
method, the logic for creatingGraphNode
instances checks whether each class is a multi-instance prototype to decide which node type to instantiate. Consider refactoring this section to reduce complexity, possibly by using a factory pattern or a common constructor that handles the differentiation internally.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Eliminate code duplication when adding graph edges
The process of adding edges to the graph for dependency resolution is similar for both multi-instance prototypes and regular prototypes. To improve readability and reduce maintenance effort, consider refactoring the common logic into a shared helper function or method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure thread safety in
loadClazz
methodThe
loadClazz
method checks ifthis.clazzList
is uninitialized before loading classes. IfloadClazz
can be called concurrently, consider adding synchronization mechanisms to prevent race conditions and ensure thatthis.clazzList
is correctly initialized before use.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add assertion to ensure
property
is definedTo prevent potential runtime errors, consider adding an assertion after retrieving
property
to ensure it is notundefined
. This follows the pattern used elsewhere and ensures that the code fails fast ifproperty
is missing.Apply this diff to add the assertion:
for (const instanceNode of this.graph.nodes.values()) { const property = PrototypeUtil.getMultiInstanceProperty(clazz, { unitPath: instanceNode.val.moduleConfig.path, moduleName: instanceNode.val.moduleConfig.name, }); + assert(property, `multi instance property not found for ${clazz.name}`); for (const info of property?.objects || []) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Refactor duplicated code in dependency module processing
The logic for finding dependency modules and adding graph edges is duplicated in both the
if
andelse
blocks for multi-instance and regular prototypes. Consider refactoring this shared logic into a separate method to enhance code maintainability and reduce duplication.For example, you could extract the dependency processing into a method like
processDependencies
:Then call this method from both branches, passing the appropriate parameters.