zlataovce / takenaka

A Kotlin library for reconciling multiple obfuscation mapping files from multiple versions of Minecraft: JE.
Apache License 2.0
51 stars 3 forks source link

feat(generator-accessor): merge chained accessors into single accessor field #40

Closed Misat11 closed 4 months ago

Misat11 commented 4 months ago

This PR aims to merge generated accessor fields when it comes to chained accessors. Currently, requesting a chain results in multiple unnecessary fields being generated:

/**
 * Accessor for the {@code java.lang.Integer getId(java.lang.Class)} method.
 * 
 * @since 1.15
 * @version 1.19.3
 * @see org.screamingsandals.lib.impl.nms.accessors.network.ConnectionProtocol$PacketSetMapping#METHOD_GET_ID
 */
@NotNull
Supplier<Method> METHOD_GET_ID = LazySupplier.of(ConnectionProtocol$PacketSetMapping.METHOD_GET_ID::getMethod);

/**
 * Accessor for the {@code int getId(java.lang.Class)} method.
 * 
 * @since 1.19.4
 * @version 1.20.4
 * @see org.screamingsandals.lib.impl.nms.accessors.network.ConnectionProtocol$PacketSetMapping#METHOD_GET_ID
 */
@NotNull
Supplier<Method> METHOD_GET_ID_1 = LazySupplier.of(ConnectionProtocol$PacketSetMapping.METHOD_GET_ID_1::getMethod);

The second field chains the first field as requested, so the first field is useless. This information is also not part of the generated javadoc, which may confuse its users.

The new variant generates only a single field:

/**
 * Accessor for the following methods:
 * <ul>
 * <li>{@code int getId(java.lang.Class)} (1.19.4-1.20.4)</li>
 * <li>{@code java.lang.Integer getId(java.lang.Class)} (1.15-1.19.3)</li>
 * </ul>
 *     
 * @since 1.15
 * @version 1.20.4
 * @see org.screamingsandals.lib.impl.nms.accessors.network.ConnectionProtocol$PacketSetMapping#METHOD_GET_ID
 */
@NotNull
Supplier<Method> METHOD_GET_ID = LazySupplier.of(ConnectionProtocol$PacketSetMapping.METHOD_GET_ID::getMethod);

The same applies for the mapping class, the single newly generated field looks like this:

/**
 * Mapping for the following methods:
 * <ul>
 * <li>{@code int getId(java.lang.Class)} (1.19.4-1.20.4)</li>
 * <li>{@code java.lang.Integer getId(java.lang.Class)} (1.15-1.19.3)</li>
 * </ul>
 *     
 * @since 1.15
 * @version 1.20.4
 */
@NotNull
MethodMapping METHOD_GET_ID = MAPPING.getMethod("getId", 0);