Get the method text where cursor is present?
已回答
Hello, I want the text of the method where cursor is. I can get the offset by editor.getCaretModel().getOffset(). I want to use this offset to get the text of enclosing method.
请先登录再写评论。
Is the PsiMethod class not there anymore? I want to get the parameter type of the method as well. For example if the function was
if the cursor was present at “return” I want to get the whole function text and the parameter a and b datatypes. So, int and char. I also want to get the return type of function “f”. I figures something like PsiMethod can help but it's not there?
Please be more specific. What context do you operate in? Is it a Java file? What is the full use case/feature you are trying to implement?
hello, the file is a java file. we basically want the text of the method where cursor is present and definitions of types used as arguments and definition of function return type.
Suppose class A obj is an argument of a function, then I want the whole code of class A as well. I am assuming we can go to the file from where it's imported and get the whole code of class A or if Class A is present in that file only, it would be easier. I am able to get the text of the function without using PsiMethod.
UPDATE: just able to get the method text where cursor is present is enough but the file could be of any language.