1

I have been trying to get the methods used in the .java file of an Android Application for my project. I have used parser that are available on internet but they parse out only the user defined methods or the core java methods. I would like to extract the methods that are also part of android framework just like how eclipse shows the list of methods and variables in the Java outline tab.

I have tried using javaparser, AST Parser and Java API java.lang.reflect.Method. For example, if I have a java file like following

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getResources().getBoolean(R.bool.portrait_only)) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
    }

    public void showLogin() {
        registerNumberEditText.setVisibility(View.VISIBLE);
        passwordEditText.setVisibility(View.VISIBLE);
        loginButton.setVisibility(View.VISIBLE);
        textView1.setVisibility(View.INVISIBLE);
        txtProg.setVisibility(View.INVISIBLE);
        loginStat = true;
    }
}

For the above code I need the list of methods and parameters used in the code like

Methods:
     OnCreate
     getResources
     getBoolean
     setRequestedOrientation
     showLogin
     setVisibility

but not

Methods:
    showLogin

Thank you for helping me out...

1 Answer 1

2

I think java reflection API works fine in this case, Please try below code :

for (Method m:MainActivity.class.getMethods()){
        System.out.println(m.getName());
    }
Sign up to request clarification or add additional context in comments.

1 Comment

thanks that was pretty much what I was expecting. I was trying getDeclaredMethods() all along....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.