Print out all methods in a program...

I am looking for a way to write a piece of code that recognizes methods, for instance if I were to put this program through the code:
class bd220p1 {
     public static void main(String args[])  {
          int lightspeedi,lightspeedm;
          long days;
          long seconds;
          long distancei;
          long distancem;
          // approximate speed of light in miles per second
          lightspeedi = 186000;
            // approximate speed of light in Kilometers per second
          lightspeedm = 300000;
          days = 1000; // specify number of days here
          seconds = days * 24 * 60 * 60; // convert to seconds
          distancem = lightspeedm * seconds; // compute distance in English system
          distancei = lightspeedi * seconds;// compute distance in Metric system
          System.out.print("In " + days);
          System.out.print(" days light will travel about ");
          System.out.println(distancei + " miles and");
          System.out.print(distancem + " Kilometers ");
}The code would locate 5 methods and print them out like so:
1.main method
2. print method
3. print method
4. println method
5. print method
So far I havent been able to find a way to do this, so any help would be appreciated. If I am vague or unclear on what I am trying to do please let me know.

Regular expressions are rules for creating (and thus matching) strings of characters. So for example this:
^a*dogb+$matches "dogb", or "adogb", or "aaaaaaaadogbbbbbbb", or "aaaaadogbcat".
There's been a regular expression library in java since jdk 1.4. Look at java.util.regex, or some tutorials. It's not something you can sum up in a couple lines; there are a bunch of little rules to learn and to apply.
It may be easier to start out with Perl. Perl is an interpreted language with regexps built in, so it's a lot faster to fiddle around with them in perl. So for example (if you're using a real OS like linux, with Perl installed) you can type this at the command line:
$ perl -ne 'print (/YOUR REGEXP HERE/ ? "yes\n" : "no\n");'and then type in strings on the console and see if the regexp matches them -- a quick way to experiment and learn.

Similar Messages

  • Print out all methods in program with print statements

    Does anyone know how I would be able to print out all the methods in a program. For example:
    class bd220p1 {
         public static void main(String args[])  {
              int lightspeedi,lightspeedm;
              long days;
              long seconds;
              long distancei;
              long distancem;
              // approximate speed of light in miles per second
              lightspeedi = 186000;
                // approximate speed of light in Kilometers per second
              lightspeedm = 300000;
              days = 1000; // specify number of days here
              seconds = days * 24 * 60 * 60; // convert to seconds
              distancem = lightspeedm * seconds; // compute distance in English system
              distancei = lightspeedi * seconds;// compute distance in Metric system
              System.out.print("In " + days);
              System.out.print(" days light will travel about ");
              System.out.println(distancei + " miles and");
              System.out.print(distancem + " Kilometers ");
    }This code would produce 5 print statements for the 4 methods:
    1 Main method
    2 Print method
    3 Print method
    4 Println method
    5 Print method
    Does anyone know I can write the could to accomplish this? Right now I am experimenting with try/catch statements. Any help is greatly appreciated.

    It seems to me the easiest approaches (other than using a tool someone else has already written) are:
    1) Compile the source, and then use BCEL
    2) Try some regular expressions; it won't be perfect but maybe you can tweak it until it's good enough.
    3) Parse the source, and examine the parse tree.
    1 and 3 will give you much better results, but require you to use outside libraries (or write a parser yourself).
    You can do 2 using standard stuff from the JDK, but you may spend a lot of trial-and-error gettng the regexps right.
    Which you choose will depend a lot on what the prof giving the assignment allows.
    Also he may have some particular kind of solution in mind -- did he say anything?
    If you're not sure what to do, ask your prof for clarification.

  • How can I print out all notes?

    I have over 200 notes and I would like to print out a copy to keep as a reference. Is it possible to somehow print out all of the notes at once without having to open up each one individually and print them out.

    It's not a file, so you can't "open" one file. Every message (and note) is a single file on the computer.
    This Applescript will grab all the notes in the selected mailbox (i.e. the selected Notes item in Mail) and put them in a textEdit document.
    Note that Mail doesn't differentiate between a note and an email message, so if you run this while a normal email mailbox is selected, it will gather all of your email messages.
    tell application "Mail"
    set theMailboxes to the selected mailboxes of message viewer 0
    repeat with aMailbox in theMailboxes
    set theNotes to the messages of aMailbox
    set theText to ""
    repeat with aNote in theNotes
    set theText to theText & content of aNote & return
    end repeat
    end repeat
    end tell
    tell application "TextEdit"
    set myDocument to make new document at end of documents with properties {text:theText}
    end tell
    Copy and paste this into a new AppleScript Editor Document, select the Notes mailboxes you want to print the notes from, and click the Run button (Green button with arrow).
    This may take a while.

  • How can I print out all notes or export the entire file?

    I have around 300 notes that include a variety of information. I would like to print out a hard copy. I don't want to open and print out each one individually. Is there a way to print out all of them at once. Also, is there a way export the file so I can open it in another application like Excel or Word?

    It's not a file, so you can't "open" one file. Every message (and note) is a single file on the computer.
    This Applescript will grab all the notes in the selected mailbox (i.e. the selected Notes item in Mail) and put them in a textEdit document.
    Note that Mail doesn't differentiate between a note and an email message, so if you run this while a normal email mailbox is selected, it will gather all of your email messages.
    tell application "Mail"
    set theMailboxes to the selected mailboxes of message viewer 0
    repeat with aMailbox in theMailboxes
    set theNotes to the messages of aMailbox
    set theText to ""
    repeat with aNote in theNotes
    set theText to theText & content of aNote & return
    end repeat
    end repeat
    end tell
    tell application "TextEdit"
    set myDocument to make new document at end of documents with properties {text:theText}
    end tell
    Copy and paste this into a new AppleScript Editor Document, select the Notes mailboxes you want to print the notes from, and click the Run button (Green button with arrow).
    This may take a while.

  • How to print out all files in a specified directory

    Now, I have some problem which prints out the entire content of all of the .txt files in a specified directory.
    what method i can use?
    Can anyone give me some examples?
    Many Thanks

    Read the API for java.io.File, in particular the list and listFiles methods, and java.io.FilenameFilter.

  • Print out all contacts with all info showing in Outlook 2013

    In Outlook 2013, if you click the Contacts group you want to print, then go to File...Print, the only option is to essentially print the view you have when clicking into the People menu.
    How can I print out every contact showing all the info in each contact?

    Hi,
    Do you want to print each contact into each printout page with all the info? If so, you can try printing using the
    Memo Style. To do this, click the contact group you want to print, select one contact and then press Ctrl + A to select all contacts in the contact group. Then, click File > Print. Under
    Settings in the Print tab, select Memo Style. Click
    Print.
    For more information about print contacts in Outlook 2013, please refer:
    http://office.microsoft.com/en-us/outlook-help/print-your-contacts-HA102749446.aspx
    Regards,
    Steve Fan
    Forum Support
    Come back and mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback on our support, please click
    here

  • Is It Possible To Print Out All The Names In Address Book At Once?

    I have got rather a lot of names and email addresses in my Address Book.
    I would like to print them on a few sheets of A4 but the only print options I can find are to print out a single card (with one name) at a time.
    Is it possible to print them all in one go?
    Ian.

    Yes, this is very easy. Select the 'All' group, then choose Print from the File menu. Choose your printing options from the menus and send it to your printer.
    Mulder
    If this answered you question, please consider awarding some points. Why Reward Points?
    iMac G4 700Mhz   Mac OS X (10.3.9)  

  • Items List won't print out all columns.

    When I try to print an Items List it only prints out a few of the columns.

    I tried to follow your instructions and got down to where you say, "Right click on template > Document properties"  I get nothing about properties when I right click on any of the templates for the sales document. I only have the choice to edit a template, then save it as default.
    Next, you said, "Change the layout from portrait to landscape" I am not seeing that option anywhere in the edit of the template window.
    Then you said, "Add the fields you like to add and save it as new name" How do you do that? I find no easy way to add the fields I want to add while in the print editor. Am I missing something here?
    I appreciate your help, and it sounds very simple the way you state it, but I am not following how you do this. Can you please elaborate?
    Thanks,

  • How can I print out all texts from one person

    How can I printall of my texts from my very bad lawyer?

    It's not a file, so you can't "open" one file. Every message (and note) is a single file on the computer.
    This Applescript will grab all the notes in the selected mailbox (i.e. the selected Notes item in Mail) and put them in a textEdit document.
    Note that Mail doesn't differentiate between a note and an email message, so if you run this while a normal email mailbox is selected, it will gather all of your email messages.
    tell application "Mail"
    set theMailboxes to the selected mailboxes of message viewer 0
    repeat with aMailbox in theMailboxes
    set theNotes to the messages of aMailbox
    set theText to ""
    repeat with aNote in theNotes
    set theText to theText & content of aNote & return
    end repeat
    end repeat
    end tell
    tell application "TextEdit"
    set myDocument to make new document at end of documents with properties {text:theText}
    end tell
    Copy and paste this into a new AppleScript Editor Document, select the Notes mailboxes you want to print the notes from, and click the Run button (Green button with arrow).
    This may take a while.

  • [php+mysql] how to insert 3 records at once and print out all 3 records?

    Hi all,
    I have to create a serie of pages that allow the user to:
    1- Insert 3 records in a mysql db at once
    2- click NEXT
    3- viewverify//print the data that he has entered (all 3
    records)
    4- click PRINT
    5- click FINISH
    then, restart from 1
    What is the best way to do this?
    TIA for any suggestion.
    tony

    The best way is usually to use a stored procedure. Do you
    know if the version of MySQL you are using supports sprocs?

  • Trouble with printing. Seems to print out all hotmail email plus all frames. Can;t seem to adjust it to print normally

    When I want to print an email I have received on hotmail it prints all frames from screen. I have tried to alter print settings accordingly but it doesn't let me

    tman: that's the first thing I tried, but it still prints off to the left and slightly moved up. My printer is a Konica Minolta C253. My predecessor has left files on the computer that print just fine, but when I use them as a template and put my own graphics in, it works some of the time and then for no reason just decides to stop printing in the center. I think it might have to do with the positioning of the paper in the printer....?

  • Would it have been too much for Apple to warn me it would wipe out all my pre-Intel programs when I updated to Lion?

    Wiped everything out. Disaster. No warning....

    You can redownload iTunes pruchases by:
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer
    The iPod backup that iTunes makes during every sync and and as the a early step of an USB update does not contain synced media like apps and music. It has aloways been that way. If rhe synced media is not in your iTunes library when you do the restore it can't be synced to the iPod during a latter part of the update. See:
    iTunes: About iOS backups
    iOS 5: Updating your device to iOS 5

  • Print out a page with a all controls

    Hello
    Is it possible to print out all the controls on a page.
    I meam all together with one function?
    Thanks
    Phil1

    I assume you're asking how do you print an MFC dialog with all of its controls. Is that correct? If so, try adding a method to your dialog class with this code:
    CPrintDialog printDlg(FALSE);
    if (printDlg.DoModal() != IDOK)
    return;
    DOCINFO documentInfo;
    ::ZeroMemory(&documentInfo, sizeof(documentInfo));
    documentInfo.cbSize = sizeof(documentInfo);
    documentInfo.lpszDocName = _T("Dialog Document");
    HDC hdcPrinter = printDlg.GetPrinterDC();
    CDC printerDC;
    printerDC.Attach(hdcPrinter);
    printerDC.StartDoc(&documentInfo);
    printerDC.StartPage();
    HDC hdcScreen = ::GetDC(NULL);
    CDC screenDC;
    screenDC.Attach(hdcScreen);
    long screenPpiX = ::GetDeviceCaps(hdcScreen, LOGPIXELSX)
    long screenPpiY = ::GetDeviceCaps(hdcScreen, LOGPIXELSY);
    long printerPpiX = ::GetDeviceCaps(hdcPrinter, LOGPIXELSX);
    long printerPpiY = ::GetDeviceCaps(hdcPrinter, LOGPIXELSY);
    long xRatio = printerPpiX / screenPpiX;
    long yRatio = printerPpiY / screenPpiY;
    CRect windowRect;
    GetWindowRect(&windowRect);
    CRect targetRect = windowRect;
    targetRect.right = targetRect.left + (targetRect.Width() * xRatio);
    targetRect.bottom = targetRect.top + (targetRect.Height() * yRatio);
    targetRect.OffsetRect(
    -targetRect.left + (targetRect.left * xRatio),
    -targetRect.top + (targetRect.top * yRatio)
    CDC* dialogDC = GetDC();
    printerDC.StretchBlt(
    0,
    0,
    targetRect.Width(),
    targetRect.Height(),
    dialogDC,
    0,
    0,
    windowRect.Width(),
    windowRect.Height(),
    SRCCOPY
    ReleaseDC(dialogDC);
    screenDC.Detach();
    p
    rinterDC.EndPage();
    printerDC.EndDoc();
    printerDC.Detach();
    This isn't perfect, but hopefully it can get you started.
    - Elton

  • Unable to print out at one time and in one file ALL of the individual Facebook Postings...I only get three (3) pages when printing...in prior versions of Firefox I could print do this but in this version I cannot: WHY?

    Three (3) Pages are:
    1) Page showing only the name and the remainder of the page blank;
    2) Page with only the most recent posts (last post on page cut off);
    3) Page with nothing on it.
    Mozilla Firefox is my preferred and primary browser, however, I went to Safari and was able to print out ALL of the Facebook Posts WITHOUT Photos/Thumbnails showing up....
    I would like Firefox to do what it used to and work for me!!!!

    Right click any tab and choose "Bookmark All Tabs".

  • If I print an email after it's sent, it prints out Subj, from,date,to and text info. I want to print all this info before I send, not just the text. How?

    If I address and compose an email and try to print it before I send it, it only prints the text, not the "Subject," "From, Date," and "To" lines in the email. After I send it, if I go into the sent register and print the same e-mail it prints out all these lines along with the text.
    I want to print the email before I send it and have the print-out contain all these lines along with the text. How do I set Thunderbird to do this all the time?

    You will get the details you want if you print from the draft folder.

Maybe you are looking for