Results 1 to 7 of 7
  1. #1
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Arrow need help to search 'method(s)' from java files

    hi,

    i want to build a program that can read java files and find all the METHODS in those files and print it all..
    suppose, in one java file contains methods like these:
    Java Code:
    public ReturnValues(Object first, Object second) {
                    .....
            }
            
            public Object getFirst() {
                    return first;   }
            
            public Object getSecond() {
                    return second;  }
    }
    
    public int total(int x, int y){
    ...
    }
    
    public void result(){
    return; }
    the output should like this:
    Return Value:............ Method Name:......... Parameter(if any): ...............

    anybody pls tell me or give some suggestion how can i build this program ?
    Last edited by doha786; 03-24-2010 at 10:27 AM.
    what we are thinking, it might not be true

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by doha786 View Post
    nybody pls tell me or give some suggestion how can i build this program ?

    if javadoc could be an option for your problem then read How to Write Doc Comments for the Javadoc Tool or do you really want to write your own code? parsing code is not trivial, but with the needed effort doable.

  3. #3
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Default

    thanks for ur suggestion...
    but actually i want to write code to figure out this problem and still i m new in java so need help to learn it too...

    your co-operation will be appreciated.. thanks
    what we are thinking, it might not be true

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    For what purposes do you need this?
    Different approaches exist and purpose normally detects which one you should take.

    e.g You could compile the .java files into class files and use reflection on the classes to get all the methods.

  5. #5
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Default

    Actually, this one is the part of my college mini project... and i m trying to print how many "class names" and how many "method names" have in one java file..

    For finding class names i got this code:
    String target="class";
    .....
    .....
    String className = scan.findWithinHorizon(target,0);
    but how can i make it for method ? because, methods may have the return values and sometimes include the parameters... how can my program will understand which one is return value, which one is parameter and which one is the method name for that particular java file ??
    what we are thinking, it might not be true

  6. #6
    fceruti is offline Member
    Join Date
    Mar 2010
    Posts
    20
    Rep Power
    0

    Default

    check this out

    Using Java Reflection

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default

    Quote Originally Posted by doha786 View Post
    For finding class names i got this code:
    And how would that deal with a variable declaration of type Class?
    Java Code:
    Class clazz = String.class;
    Or a method that returns a class? Or...

    db
    Last edited by DarrylBurke; 03-25-2010 at 09:58 AM.

Similar Threads

  1. Binary search tree search method
    By chopo1980 in forum New To Java
    Replies: 2
    Last Post: 12-10-2009, 01:42 AM
  2. Replies: 3
    Last Post: 08-28-2009, 03:51 AM
  3. dynamically search user input files
    By Juuno in forum Advanced Java
    Replies: 2
    Last Post: 04-29-2009, 04:51 PM
  4. Replies: 4
    Last Post: 01-14-2009, 04:12 AM
  5. How to search files with Java
    By karma in forum New To Java
    Replies: 1
    Last Post: 05-26-2007, 01:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •