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. 

0

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 

 

int f(int a, char b)
{
   return a+(int)b
}

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?

0

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?

0

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. 

0

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. 

0

UPDATE: just able to get the method text where cursor is present is enough but the file could be of any language. 

0

请先登录再写评论。