Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: get the code of a given method

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question get the code of a given method

    Hi,

    I work on java project and I have the task to get the code of a java method. For example we suppose that we have this method on the project :
    public void action() {
    Etat = Etats.MEDECIN_MARCHE;
    sousEtat_Marche = Marche.RECHERCHE_VICTIME;
    Ontologie.ordreExplorer oE = (Ontologie.ordreExplorer) objet;
    NZone = oE.getNumZone();
    etape = param.getParam().etape;
    Finished = true;
    }

    And I just know the method name and the list of parameters so the result of my issue will be :

    Etat = Etats.MEDECIN_MARCHE;
    sousEtat_Marche = Marche.RECHERCHE_VICTIME;
    Ontologie.ordreExplorer oE = (Ontologie.ordreExplorer) objet;
    NZone = oE.getNumZone();
    etape = param.getParam().etape;
    Finished = true;

    thank you


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: get the code of a given method

    So what seems to be the problem?
    Where are you stuck?

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: get the code of a given method

    Hi jps,
    I search a solution to retreive the contain of the method "action". we suppose that I don't know the implementation of the method I have just the method name and parameters.
    Thank you

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: get the code of a given method

    Well we don't just write code to solve problems for people. If you need help, ask a question that doesn't ask someone to do the code for you.
    If you plan to write the code, you must provide information on where the information is stored you must search, and all those icky details that makes solving the problem possible

  5. #5
    Junior Member
    Join Date
    Sep 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: get the code of a given method

    I don't search a complete solution just an idea if there is defined method as getCode(method)
    I am searching and I found that it will be may be a parser for a java file that contains the asked method.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: get the code of a given method

    I don't know the implementation of the method I have just the method name and parameters.
    Are you asking how to determine how some programmer implemented a method?
    There can be many different ways to implement a method.
    Do you have the class file? There are decompilers that will create a source file from a class file.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Sep 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: get the code of a given method

    @Norm:
    I have the java files but I need in my application to retreive some information from the code of methods for examples the noun of the used ontologie in the method action, thus i need to parser the code and extract the noun "ordreExplorer"

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: get the code of a given method

    That sounds like you need an algorithm to read source code, parse it and extract the desired information. I've never seen one like that.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: get the code of a given method

    Quote Originally Posted by aroua_doudou View Post
    I don't search a complete solution just an idea if there is defined method as getCode(method)
    If I understand what you want, I doubt there is code for that just available with a search. It does not sound like a common or difficult task.

    Quote Originally Posted by aroua_doudou View Post
    @Norm:
    I have the java files but I need in my application to retreive some information from the code of methods for examples the noun of the used ontologie in the method action, thus i need to parser the code and extract the noun "ordreExplorer"
    Quote Originally Posted by aroua_doudou View Post
    I am searching and I found that it will be may be a parser for a java file that contains the asked method.
    It sounds to me like you have the source code in the form of the class.java files, and you want to read them as text and parse the nouns(variable names?) and methods from the source code. Is that what you want?

Similar Threads

  1. Calling another method on my code
    By Caliichick in forum Java Theory & Questions
    Replies: 3
    Last Post: June 12th, 2012, 05:01 PM
  2. Java Code Help on Draw method
    By RADical in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 24th, 2012, 07:17 PM
  3. Help ! merge this code into 1 main method . ASAP :( tnx
    By anitsirc in forum Object Oriented Programming
    Replies: 2
    Last Post: November 23rd, 2011, 11:53 AM
  4. Java Code Help - Calling Method
    By KevinGreen in forum Object Oriented Programming
    Replies: 5
    Last Post: September 18th, 2009, 12:55 AM
  5. adding main method to a code
    By IDK12 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 31st, 2009, 08:52 PM