Incendo / Incendo/cloud

Registering parsers with a narrower type of the sender type

Open
#770 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
548
Forks
60
PR merge metrics
No merged PRs in 30d

Description

Making a custom parser that accepts a subtype of your sender type (in my case org.bukkit.entity.Player of org.bukkit.command.CommandSender) is very useful as to automatically utilize existing error infrastructure (specifically the TerminalConsoleCommandSender is not allowed to execute that command. Must be of type Player message).

Currently, the existing ParserRegistry#registerParser(ParserDescriptor) method does not allow type narrowing and requires an unchecked cast to allow it to compile.

Example in Kotlin:

manager.parserRegistry().registerParser(ParserDescriptor.of(MineParser() as ArgumentParser<CommandSender, Mine>, Mine::class.java))

I was told by @jpenilla that there could be a method added that gives a view of the parser registry for subtypes specifically, so that this can be validated correctly. Here is the Discord message where this was mentioned.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ParserRegistry#registerParser(ParserDescriptor), ParserDescriptor, and ArgumentParser, then inspect how sender-type validation produces the existing error message. Define the subtype-specific registry view described in the issue so a Player parser can be registered without an unchecked cast, while preserving validation for incompatible senders; confirm the Kotlin example compiles against the resulting API.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.