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

Fix renaming of classes in presence of generic signatures and nested classes. #299

Merged
merged 3 commits into from May 11, 2022

Conversation

pietrobraione
Copy link
Contributor

This is a possible fix for issue #298 that allows to rename a class and its nested classes in presence of generics. If for example we consider the following class:

package a.b;

public class C<W> {
  private class D<X> {
    private class E<Y> { }
  }

  D<Integer> d;
  D<Float>.E<Double> e;
  public static <Z> C<Z> make() { return new C<Z>(); }
}

the fix allows, e.g., to rename the class a.b.C to p.q.R and keep unchanged the names of the nested classes as follows:

ClassFile cf = new ClassFile(new DataInputStream(new ByteArrayInputStream(Files.readAllBytes(...))));
final HashMap<String, String> renames = new HashMap<>();
renames.put("a/b/C", "p/q/R");
renames.put("a/b/C$D", "p/q/R$D");
renames.put("a/b/C$D$E", "p/q/R$D$E");
cf.renameClass(renames);
cf.compact();
cf.write(new DataOutputStream(new FileOutputStream("...")));
//do this for C.class, C$D.class and C$D$E.class

I am not sure that this semantics complies with the meant one for Javassist.

@chibash chibash merged commit c8b54b3 into jboss-javassist:master May 11, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants