Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an API for querying inheritance #27

Open
coderbot16 opened this issue Jan 6, 2020 · 5 comments
Open

Add an API for querying inheritance #27

coderbot16 opened this issue Jan 6, 2020 · 5 comments

Comments

@coderbot16
Copy link

[2:38 PM] coderbot: patchwork needs inheritance information for figuring out when a class extends a given Minecraft class (I want to have a system for automatically detecting forge features used by a mod), and/or figuring out the list of classes that a giuven class extends (for propagating event bus handlers)
[2:39 PM] coderbot: it also needs to know if a mod extends a vanilla class for the purposes for evaluating how a mod uses their ATs for the purposes of remaking them into mixins
[2:39 PM] coderbot: if tiny-remapper had a general purpose API for querying inheritance, that would be great

As Player suggested on Discord, it seems like ClassInstance#children fufills this requirement, but there would need to be a public interface for accessing it.

@liach
Copy link
Contributor

liach commented Jul 28, 2021

@sfPlayer1 Does this

api fulfill the needs? If yes, we can close this issue.

@LogicFan
Copy link
Contributor

You can only get parents through the current API, not the childern. But I think it's possible to add an API for this. This will up to @sfPlayer1 .

@liach
Copy link
Contributor

liach commented Jul 28, 2021

Querying children is always unreliable, as even the JVM doesn't know the full set of children for any non-final (or non-sealed) class at runtime; new classes can always be loaded to extend an existing class.

@LogicFan
Copy link
Contributor

Querying children is always unreliable, as even the JVM doesn't know the full set of children for any non-final (or non-sealed) class at runtime; new classes can always be loaded to extend an existing class.

What you said is true in general. However, for tiny-remapper, if you give all class files into tiny-remapper, then it does know all the children (ofc limited in what your input is). And there is a field ClassInstance#children that contains this information after the propagation stage.

Just need to add

Collection<TrClass> getChildren() {
  return Collections.unmodifiedList(this.childern);
}

should do the trick. However, some consideration is needed.

  1. Should we return TrClass or String?
  2. Should we also have getParents?
  3. Is this good as an API design?

@liach
Copy link
Contributor

liach commented Jul 28, 2021

for the purpose seen in the original issue, I think getting the parent is enough.

In addition, we have

List<? extends TrClass> getInterfaces();

So I argue that our current api suffices for the use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants