Closed jdrueckert closed 9 months ago
Hello, I'm new to contributing but I would be interested in trying to work on this issue. Would that be ok ?
Using this search with regex on the repo, "org:Terasology language:Java /public void copyFrom(\w \w) {\s*}/" (I'm a bit newbie in regexes so it is not very optimised), there seems to be 95 candidates for the refactoring
Hello,
I have opened the following PRs for this issue :
DynamicCities : https://github.com/Terasology/DynamicCities/pull/113 MasterOfOreon : https://github.com/Terasology/MasterOfOreon/pull/105 MetalRenegades : https://github.com/Terasology/MetalRenegades/pull/187 Sample : https://github.com/Terasology/Sample/pull/130 GooeysQuests : https://github.com/Terasology/GooeysQuests/pull/73 Equipment : https://github.com/Terasology/Equipment/pull/140 Machines : https://github.com/Terasology/Machines/pull/57 Inferno : https://github.com/Terasology/Inferno/pull/30 Minesweeper : https://github.com/Terasology/Minesweeper/pull/29 WeatherManager : https://github.com/Terasology/WeatherManager/pull/31 Economy : https://github.com/Terasology/Economy/pull/28 GooeyDefence : https://github.com/Terasology/GooeyDefence/pull/76 ManualLabor : https://github.com/Terasology/ManualLabor/pull/63 InGameHelp : https://github.com/Terasology/InGameHelp/pull/15 FunnyBlocks : https://github.com/Terasology/FunnyBlocks/pull/30 IRLCorp : https://github.com/Terasology/IRLCorp/pull/44 WildAnimalsGenome : https://github.com/Terasology/WildAnimalsGenome/pull/19 Exoplanet : https://github.com/Terasology/Exoplanet/pull/26 EdibleSubstance : https://github.com/Terasology/EdibleSubstance/pull/9 WorkstationInGameHelp : https://github.com/Terasology/WorkstationInGameHelp/pull/13 Portals : https://github.com/Terasology/Portals/pull/7 Scenario : https://github.com/Terasology/Scenario/pull/64
@spookynutz thank you for the contributions, highly appreciated! :green_heart: I merged all linked module PRs. I'll check later, if there's any remaining occurrences. If there are not, we can close this issue.
Hi, I'm trying to help solve this issue, are there still any remaining occurrences? @jdrueckert
@5archoufa thanks for the reminder! had a quick check and didn't find any remaining occurrences, so I think we can close this issue. If we do find something after all, we can always reopen it.
Motivation
During a recent omega-wide refactoring, I noticed that we have a lot of components in engine and module land that implement gestalt's
Component
but do not involve any attributes (class fields). These components should instead extend gestalt'sEmptyComponent
which avoids the need to implementcopyFrom
.Furthermore, the refactoring will help to determine packages with many empty components which indicates further improvement potential as mentioned in the java doc of
EmptyComponent
:Proposal
Search engine and modules (repos in https://github.com/Terasology) for classes that implement
Component<T>
but do not define any class fields. For instance, in Intellij, you can search for usages of gestalt'sComponent
interface in extends/implements clauses. Refactor the identified classes to extendEmptyComponent<T>
instead and remove the implementation ofcopyFrom
.As a follow-up (not relevant for the completion of this issue), packages with a lot of empty components should be considered for refactoring into a single component with boolean attributes.
Helpful Examples
An example for a non-empty component that does not need refactoring is Health's
DamageResistComponent
.It defines a component attribute (class field)
damageTypes
, so it needs to implementComponent<T>
which it correctly does and implement the override forcopyFrom
which it also correctly does.An example for an empty component that does not need refactoring is Health's
BlockDamagedComponent
.It does not define any component attributes (class fields), so it needs to extend
EmptyComponent<T>
which it correctly does and doesn't need to implement the override forcopyFrom
.An example for an empty component that does need refactoring is WorkstationInGameHelp's
ParticipateInItemCategoryInGameHelpComponent
:It implements
Component<T>
and the override forcopyFrom
but does not define any attributes (class fields), so it would be a candidate for refactoring. A respective refactoring could look like the following: