def getParentOfType[T <: PsiElement](element: PsiElement, aClass: Class[T], strict: Boolean = false): Option[T] = {
System.out.println(aClass.isInstance(element), aClass, element.getClass)
...
getParentOfType(el, classOf[JSClassImpl])
Prints the following:
(false,class com.intellij.lang.javascript.psi.ecmal4.impl.JSClassImpl,class com.intellij.lang.javascript.psi.ecmal4.impl.JSClassImpl)
Shouldn't these evaluate to true?
At the moment the workaround is:
System.out.println(aClass.toString == element.getClass.toString)
This seems ridiculous. I've tried everything!
And then when I return a Option(el.asInstanceOf[T])
from the method, I get the following error whenever I try to use it:
java.lang.ClassCastException: com.intellij.lang.javascript.psi.ecmal4.impl.JSClassImpl cannot be cast to com.intellij.lang.javascript.psi.ecmal4.impl.JSClassImpl
I have a feeling it has something to do with class loaders.
ClassCastException when casting to the same class
From IntelliJ support forums:
you should note that plugins have their own ClassLoader.
http://devnet.jetbrains.com/message/5259550;jsessionid=13C3F98277311F5EFFFAFD3135B42CEA