In my plugin I'm trying to detect to which class a missing method would belong. IntelliJ does know on which class to place the method if I use the quick fix. Now I would like to know how that QuickFix 'detects' where to place the new method.
Our current implementation is getting the PsiElement from a HighLightInfo instance. Then we are using the RefactoringUtil.getTypeByExpressionWithExpectedType method to detect the type of the preceding expression of that PsiElement (often a PsiIdentifier or PsiJavaToken), but that sometimes returns a wrong type (or null which for us is better than the wrong type).
Can you please give me a hint where to look or which method to use in this case?
Several examples with the missing method underlined:
CamelCase.upper("") --> Should give "CamelCase"
CamelCase b = new CamelCase();
b.upper("") -> Should give "CamelCase"
Utils.getCamelCase().upper(); --> Should give 'CamelCase' if getCamelCase() has CamelCase as return type.
new CamelCase().upper("") --> Should give 'CamelCase'