There are many ways to do this, one of them which is using aspect is already mentioned by another answer.
I would like to suggest a lighter alternative, which is to just extend the generated class:
public GeneratedClass {
public void doThis();
}
public ImprovedClass extends GeneratedClass {
public void doExtraStuff();
}
The advantage of this is that you have a clear definition of that GeneratedClass can do. If you start weaving methods into the GeneratedClass, the one who work on the project a few years later on might get the idea that all similar instance of the generated class have the same method. Or they might be confused why some generated classes have these extra methods, and some not. The extra functionality should be kept in a clearly defined class. Only the subclass of that type can do the extra stuff. This makes it clear where the method comes from.
It's not like I have something against code weaving, but I think code weaving should only be used for something that doesn't involve business logic like logs, metrics, or for inside a framework. Business logic related code should not be weaved to a class.
Anyway, another way to do this is to wrap the class, but this will need an interface.
public GeneratedClass implements SomeInterface {
public void doThis();
}
public ImprovedClass implements SomeInterface {
public SomeInterface impl;
public Improvedclass(SomeInterface impl) {
this.impl = impl;
}
public void doThis() {
this.impl.doThis();
}
public void doExtraStuff() {
// the extra stuff
}
}