I need a listener that can notify if PsiElement is not vaild. PsiTreeChangeListener seems not fit for this. Is there any other listener that can tell this. Or i have to create a listener ? How to create this listener?
You can use SmartPsiElementPointer class to create and maintain list of psi elements.
SmartPsiElementPointer is a pointer to a PsiElement which doesn't become invalid even if the psi element it points to was deleted. In that case it's getElement() method will simply return null. You can detect and handle this.
To wrap an element into SmartPsiElementPointer you can use the following code:
SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element);