I’ve seen this article: Refactor Data Registration by gabizou · Pull Request #1531 · SpongePowered/SpongeAPI · GitHub that talks about the changes to the custom-data system, and registration…
However, the changes are presented as “It is going to be like…” but the actual stuff is different.
It shows to replace
Sponge.getDataManager().register(MyCustomData.class, ImmutableCustomData.class, new CustomDataBuilder());
as like
DataRegistration.<MyCustomData, ImmutableCustomData>builder()
.setDataClass(MyCustomData.class)
.setImmutableDataClass(ImmutableCustomData.class)
.setBuilder(new CustomDataBuilder())
.setManipulatorId("my_custom")
.buildAndRegister(this);
There are no setX methods - there are similar without the set part, but this then results in builder() being both the datareg builder command, and the builder-specifier… ? ?
It also specifies that we NEED to provide the data-typing in the dataregistration line, but whenever I try to produce a similar opening construction in Eclipse to what is listed above, I get a much bigger pile of spaghetti.
For me trying to migrate
Sponge.getDataManager().register(FrameLockData.class, new FrameLockDataManipulatorBuilder());
I can get something like below by forcibly overwriting what eclipse auto-fills for me:
DataRegistration.<FrameLockData, ImmutableFrameLockData> builder()
.dataClass(FrameLockData.class)
.immutableClass(ImmutableFrameLockData.class)
.builder(new FrameLockDataManipulatorBuilder())
.manipulatorId("booFLD")
.buildAndRegister(this.container);
But then Eclipse is tossing warnings at me “Unused type arguments for the non generic method builder() of type DataRegistration; it should not be parameterized with arguments <FrameLockData, ImmutableFrameLockData>” because if I go ahead and just type DataRegistration as soon as I press the period and left brace, it auto-fills in as
DataRegistration.Builder<DataManipulator<T,I>, ImmutableDataManipulator<I,T>>
Which to my small brain says that it wants to go inception-like and simply replacing with the mut and immutable data class names isn’t enough, it wants something more from each still… plus, I can’t seem to then manipulate that form into one into a working builder-construct.
Its possible my eclipse settings are such as to over-warn something, or to auto-do something that shouldn’t be done, and I need to disable something, but what should the REAL CORRECT END-PRODUCT LOOK LIKE now for the sample code, since the “will look like” is not accurate and there may be other issues at stake now.
DataRegistration.builder()
gives no warnings, and compiles, but goes against the exposition in the PR about how the generics need to be specified because thats how Java is in this case… and it also ends up resulting in a NPE: Data name is null! error when compiled.
Please help me produce the correct migratory code form, and if my eclipse settings will not permit it without a warning or restructuring it, indicate what setting i should toggle if that is known.
Thanks