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
Please sign in to leave a comment.
Yes, compiled code doesn't have method bodies.
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??
or, adding my own data(external java source files) into project's data context?
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)