takenaka icon indicating copy to clipboard operation
takenaka copied to clipboard

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

Open Misat11 opened this issue 9 months ago • 0 comments

This PR aims to merge generated accessor fields when it comes to chained accessors. Currently, requesting a chain results in multiple unnecessarry 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_1
 */
@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_1
 */
@NotNull
Supplier<Method> METHOD_GET_ID_1 = LazySupplier.of(ConnectionProtocol$PacketSetMapping.METHOD_GET_ID_1::getMethod);

TODO:

  • [ ] Kotlin support
  • [x] Correct Javadoc format for Java
  • [ ] Use the lowest possible index from the chain, possibly removing the numeric suffix.
  • [ ] Merge also in the respective Mapping class (will it make any sense for us?)

Misat11 avatar May 15 '24 20:05 Misat11