Is it possible to get a LexicalScope for Java clas...
# kontributors
j
Is it possible to get a LexicalScope for Java class descriptors ? Or is this concept only tied to Kotlin classes ? I'd like to get the descriptor of an extension method of a Java class but I don't know how to achieve that..
d
-
LexicalScope
and descriptors are kinda opposite objects. LexicalScope is tied to some lexical construct, i.e. place in code, while descriptors are more abstract objects (sort of compiler symbols, if you want). So getting "LexicalScope for descriptor" is a bit weird (I think it's possible, but it's just weird) - As far as I understand, ultimately you want to "get the descriptor of an extension method of a Java class". It shouldn't be too hard, but it highly depends on the context: where you want to get it, what do you have, what do you know about that method, etc. etc. Can you please provide more details about your case?
j
I don't have much at hand, except the current Project. I am creating a custom Action that converts an XML hierarchy into Kotlin code, where each XML tag is associated to a Java or Kotlin class. At some point, I need a descriptor of all available functions (extensions included) on each of those classes. The descriptor I need for each function should allow me to reflect on its arguments types.
d
@jdemeulenaere I suggest taking look into
UnusedSymbolInspection
. I'm not completely sure that this is exactly what you're looking for here, but at least it'll provide you general direction
j
@dsavvinov I just had a look at that class, and I didn't find anything I could use unfortunately. Here is what I have: 1) The com.intellij.psi.xml.XmlFile on which I ran my custom action. 2) Let's say my xml file has as content '<com.example.User name="Foo"> ... </com.example.User>', I want a descriptor of all functions named "name" or "setName" on the class com.example.User. I can - use 'PsiShortNamesCache.getClassesByName()' to get the PsiClass associated to User. - use 'org.jetbrains.kotlin.idea.caches.resolve.util.getJavaClassDescriptor' on PsiClass to get a ClassDescriptor. Now I'm stuck. ClassDescriptor has multiples MemberScopes but they don't allow me to get the descriptors of extension functions (I think). If User is a Kotlin class, then the descriptor seems to be a LazyClassDescriptor, which then I can do LazyClassDescriptor.scopeForMemberDeclarationResolution.getAllAccessibleFunctions(Name.identifier("setName")). This seems to also resolve extension functions, but I still don't have a solution if User is a Java class 😕