mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-18 19:39:19 +00:00
refactor: remove the package objects instead of porting them
A Scala package object compiles to a class literally named 'package', and that is a Java keyword, so no Java source can declare or even name it. The characterization had to reach both through Class.forName, which is the argument in one line. There is no Java form to port to. Each held exactly one member, a logger alias for its proxy, so the indirection is inlined at its eight call sites: ConfigContent (7) and MultipartGenerator (1). The functional characterization asserted beforehand that each alias returned the very instance its proxy holds, so the substitution is an identity; both classes are descriptor-identical afterwards. Exactly four classes leave the jar and nothing else changes. No consumer referenced them, and no Java consumer could have. 120 plain-JVM tests and 22 Forge server tests pass. PackageObjectCharacterization went with its subject; ProxyLoggerFunctionalTest keeps the assertion worth having, that both proxies publish a logger during preInit.
This commit is contained in:
1 parent
d6bba7ff46
commit
d224ce116d
9 files changed
+71
-100
No files matched your search
@@ -1,7 +1,6 @@
|
||||
package codechicken.multipart.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -9,8 +8,9 @@ import codechicken.microblock.handler.MicroblockProxy;
|
||||
import codechicken.multipart.handler.MultipartProxy;
|
||||
|
||||
/**
|
||||
* Both proxies publish a logger during preInit, and code across both packages logs through them. A plain JVM test only
|
||||
* ever sees the uninitialised null, so this is the one place the real instances are observable.
|
||||
* Both proxies publish a logger during preInit, and code across both packages logs through them directly now that the
|
||||
* package-object aliases are gone. A plain JVM test only ever sees the uninitialised null, so this is the one place the
|
||||
* real instances are observable.
|
||||
*/
|
||||
class ProxyLoggerFunctionalTest {
|
||||
|
||||
@@ -19,19 +19,4 @@ class ProxyLoggerFunctionalTest {
|
||||
assertNotNull(MultipartProxy.logger(), "MultipartProxy.logger is set in preInit");
|
||||
assertNotNull(MicroblockProxy.logger(), "MicroblockProxy.logger is set in preInit");
|
||||
}
|
||||
|
||||
/**
|
||||
* The package objects are pure aliases: each returns the very instance its proxy holds, adding nothing. That is
|
||||
* what makes them safe to remove in favour of naming the proxy directly.
|
||||
*/
|
||||
@Test
|
||||
void thePackageObjectAliasesAreTheProxyLoggersThemselves() throws Exception {
|
||||
assertSame(MultipartProxy.logger(), invokeLogger("codechicken.multipart.package"));
|
||||
assertSame(MicroblockProxy.logger(), invokeLogger("codechicken.microblock.package"));
|
||||
}
|
||||
|
||||
/** Reflective because {@code package} is a Java keyword and cannot appear as a type name in Java source. */
|
||||
private static Object invokeLogger(String name) throws Exception {
|
||||
return Class.forName(name).getDeclaredMethod("logger").invoke(null);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user