Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C#
1) I have to read a txt file in java. Find out the methods in the class and also find out what are all the methods called by a single method.

For eg -> Sport is my main method. That method might call external methods like cricket football and tennis.

Country is a method. It calls India, USA and england.

2) My output should be like sport then cricket football tennis. Followed by Country then India USA England.

3) basically all the functions and the functions which are being called inside a function.

4) have to do this in Java. I am very new to Java. Searched in net and found stack trace concept.

I know to use buffered reader in Java to read contents from file. And

.Getmethodname to find out method names .getstacktrace to get all the element names. But i am not sure if this is correct. Please help me to finish this task.

What I have tried:

I used buffered reader in Java to read contents from file. And

.Getmethodname to find out method names .getstacktrace to get all the element names. But i am not sure if this is correct. Please tell me correct approach or code.
Posted
Updated 9-May-16 9:26am
Comments
Sergey Alexandrovich Kryukov 9-May-16 15:21pm    
And where is your question?
—SA

1 solution

Reading Java text files would be a bad idea, because you would need to implement most of the parts of a fully-fledged Java compiler, starting from reading the files, scanning, will all the lexical analysis and most other things.

It would be much better to use compiled code and perform static analysis of it. It could be dove via Java reflection. You can start here: Trail: The Reflection API (The Java™ Tutorials)[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900