I asked the question on github and got the following reply:
Assuming stack analysis has been performed and the function has been
marked with stack references as shown above, you can iterate over the
references "from" the body of the function (i.e., AddressSetView). The
references returned would need to be filtered as other type of
references would also be returned. Although there are a variety of
ways to obtain references here is one example:
Function f;
Program p;
ReferenceManager refMgr = p.getReferenceManager();
for (Address fromAddr : refMgr.getReferenceSourceIterator(f.getBody(), true)) {
for (Reference ref : refMgr.getReferencesFrom(fromAddr)) {
if (ref.isStackReference()) {
StackReference stackRef = (StackReference) ref;
}
}
}
The important part is that your analysis must take place AFTER the stack analysis happened, which is quite late. You can control when your analysis runs in the constructor by passing the point where you want to run into the parent constructor.