There isn't a solution boxed up by webdriver for this problem. What you'll need to figure out is how to generate a locator such as xpath or css selector based on what you click. This very likely will need to be in the form of some injected javascript on the page that listens for clicks. Quick google search yielded this answer How to get the xpath by clicking an html element
Once you have that locator, your next task will be to get it brought into scope of your webdriver code, so that you may use it's value in your test.
Just off the top of my head, one way you could do this is to use that the same javascript injection to create a hidden element on the page off in a corner that has it's value attribute updated on each click to the output of whatever you decide will generate your locator. This will allow your java code to fetch that secret element and ask it for the xpath to the previously clicked element.
One caveat though, if you were to inject anything on the page, make sure that your injections don't change the context of the elements on the page. If you inject anything that has a functional impact on real page elements, you may put yourself into a place where your xpaths stop working the moment you restore the page to it's natural state (through a page refresh or whatever).
Generally speaking, injections into the page are bad for testing because it invalidates the known state of the page. However, it sounds like you're trying to accomplish an xpath aid tool for assisting in writing webdriver code in another context, which could be fine as long as your xpaths are properly generated, and injections aren't changing their absolute locations.
One more thing to think about, are you hoping for locators to be generated that are concise and well built? Any generated locator you find will likely be the result of crawling the dom and building a long-winded absolute path, which will be broken much much easier by an actively developed site.