psiMethod.getBody() returns null when psiMethod instance is from external libraries

PsiClass klass = JavaPsiFacade.getInstance(project).findClass("org.apache.commons.lang3.ClassUtils", GlobalSearchScope.allScope(project));
PsiMethod method= klass.findMethodsByName("getShortClassName", true)[0];
System.out.println(method.getBody()); // it prints null
0
4 comments
Official comment

Yes, compiled code doesn't have method bodies.

Avatar
Permanently deleted user

Is there any other way to traverse through method bodies (of external library instance methods) like manually loading source code(if we have it) of libraries into current project??

0
Avatar
Permanently deleted user

or, adding my own data(external java source files) into project's data context?

0

If you attach source jars (or dirs) to the library, you'll be able to get a source PsiMethod by calling getNavigationElement on the compiled PsiMethod. The source should have getBody (unless it's an abstract or native method, of course)

0

Please sign in to leave a comment.