Php Open API - get referenced class or type
已回答
Hello,
Is there a way in Php open API to find the PHP class or type from the reference?
So for example when i have a PhpReference I would like to know if it refers to a class and which class it is.
What I discovered so far was doing something like this would give me the type
if(reference.getFirstPsiChild() instanceof PhpTypedElement) {
PhpTypedElement typedElement = (PhpTypedElement) reference.getFirstPsiChild();
PhpIndex.getInstance(reference.getProject())
.getClassesByFQN(typedElement.getType().toString())
.forEach(phpClazz -> {
System.out.println(phpClazz.getFQN());
});
}
This does however not work if there are multiple possible types, like in this example
/**
* @return Test|User
*/
function createTest() : Test{
return new Test();
}
So what I am looking for is a way to get all the known return types.
请先登录再写评论。
My bad, did not realise that a type had a getTypes method.