How to count number of lines inside methods() using the Doclet API

Wrote a custom doclet using the [Doclet API|http://java.sun.com/j2se/1.3/docs/tooldocs/javadoc/doclet/index.html ] .
The purpose for the doclet is to load Java source files and create stubs (which are identical Java source files but do not contain any method implementation details).
Instead, the method implementation details need to be replaced with blank lines...
public class MyDoclet {
     private static String TAB = "\t";
     public static boolean start(RootDoc root) {
          ClassDoc[] classes = root.classes();
          // Parse through class or interface
          for (ClassDoc clazz : classes) {
               Type superClass = clazz.superclassType();     
               // Print Methods
               MethodDoc[] methods = clazz.methods();
               for (MethodDoc method : methods) {
                    Parameter[] parameters = method.parameters();
                    println();
                    if (!method.isPrivate()) {
                         print(TAB + method.modifiers() + " "
                                                + method.returnType().simpleTypeName() + " " + method.name());
                         print("(");
                         for (int i=0; i < parameters.length; i++) {
                              Parameter parameter = (Parameter) parameters;
                              print(parameter.type().simpleTypeName() + " " + parameter.name());
                              if (i != parameters.length - 1) {
                                   print(", ");
                         print(")");
                         println(" {");
                         println("\n");
                         println(TAB + "}");
          return true;
As one can see, I am just creating the method and placing the opening and closing curly braces (along with a new \n line escape sequence, in between).
Am not really that familiar with the Doclet API...
Question(s):
(1) What is the best way to figure out how many lines of code are inside each method and then use a for loop to insert the exact same number of blank lines inside the methods?
(2) Is there a way to do it using the com.sun.javadoc.SourcePosition.line() method?
Would really appreciate it if someone could help me because this is an important requirement (hence the 10 Duke Stars).
Happy coding to all,
Mike                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

This is not possible using the Doclet API, because JavaDoc does not store any information regarding implementation detail. Although MethodDoc#position will give you the line where the method is declared, there is no way to determine where the method body starts and ends.
If you need that much information, maybe you would be better of using a tool such as Eclipse's Abstract Syntax Tree parser. AST will provide you with line numbers for each code expression, hence it is relatively easy to compute the first and last line in a method body.

Similar Messages

  • Placing commas inside method parameters with Doclet API

    I wrote a custom Doclet using the [Doclet API|http://java.sun.com/j2se/1.3/docs/tooldocs/javadoc/doclet/index.html ] (located in the JDK's tools.jar).
    The purpose for the Doclet is to load Java source files and create stubs (which are identical Java source files).
    Here's my Docklet:
    public class MyDoclet {
         private static String DEST_DIR = "./destination/";
         private static String TAB = "\t";
         public static boolean start(RootDoc root) {
             ClassDoc[] classes = root.classes();
             // Parse through class or interface
             for (ClassDoc clazz : classes) {
                    // Print Methods
                    MethodDoc[] methods = clazz.methods();
                    for (MethodDoc method : methods) {
                           Parameter[] parameters = method.parameters();
                           println();
                              print(TAB + method.modifiers() + " " + method.returnType().simpleTypeName() + " " + method.name());
                              print("(");
                              for (Parameter parameter : parameters) {
                                  p.print(parameter.type().simpleTypeName() + " " + parameter.name());
                              print(")");
                              println(" {");
                              println("\n");
                              println(TAB + "}");
              return stub(root);
    }When I run this doclet, it generates the correct code but for methods which have multiple parameters, I can't seem to figure out how to place a comma, after each variable...
    For example, if this was the target class:
    public class Inventory {
       public double adjustTax(int newCoffee, double SALES_TAX) {
          // Implementation
    }My parsed code looks like this:
    public class Inventory {
       public double adjustTax(int newCoffeedouble SALES_TAX) {
          // Implementation
    }Does anyone have a suggestion on how I can calculate or accurately place commas in between the method parameters?
    Thank you,
    Mike

    Already found the solution...

  • How to count number of lines in a file?

    I am using a BufferedReader to read my file, but I like to know how to count the number of lines in a file is there a way to do that in Buffered Reader or do I have to use FileInputLineStream?

    Well, if you know how to read one line with a Buffered reader, and you know how to keep reading lines until you run out, then all you have to to is initialize a counter to zero before you start reading, add 1 to it each time you read a line, and then examine its value when you're done.
    Try that, and post again if you get stuck.
    Just be careful how you construct your loop. "Off by one" errors are a common way to get bitten. It could happen if you count what you think is the last line, but you've actually already counted all the lines and you end up counting one extra for "there are no more lines".

  • How to count number of lines in a DMEE Tree

    Hi all,
    My requirement is that in my DMEE tree I have to count entries of line item data(FPAYP). Suppose for entry of FPAYH there are two entries in FPAYP then for first line of FPAYP 1 should be printed and for next line of FPAYP 2 should be printed and so on.
    Can anybody tell me how to do this?
    Regards,
    Azra.

    Well, if you know how to read one line with a Buffered reader, and you know how to keep reading lines until you run out, then all you have to to is initialize a counter to zero before you start reading, add 1 to it each time you read a line, and then examine its value when you're done.
    Try that, and post again if you get stuck.
    Just be careful how you construct your loop. "Off by one" errors are a common way to get bitten. It could happen if you count what you think is the last line, but you've actually already counted all the lines and you end up counting one extra for "there are no more lines".

  • How to count number of rows as well as the sum of a column in a procedure

    Hi, i need to count the number of rows a sql returns in a procedure.
    as well as i need to sum up a different column.
    i need the following output:
    count the number of rows output
    and sum the total column
    code:
    procedure samba_extraction (p_errmsg IN out varchar2
    ,p_errcode IN out NUMBER
    ,p_filename in varchar2
    ,p_start_date varchar2
    ,p_end_date varchar2)
    is
    file_handle utl_file.file_type; -- file handle of os flat file
    -- cursor to select the c_samba_resources
    cursor c_samba is
    select
    lpad(h.contract_number,15,'0') contract_number
    ,h.short_description description
    ,h.attribute_category context_value
    ,h.attribute7 samba
    ,h.attribute8 samba_number
    ,h.start_date start_date
    ,h.end_date end_date
    ,h.sts_code active_inactive
    ,l.price_negotiated price
    ,l.tax_amount tax
    ,LTRIM(to_char((l.price_negotiated + l.tax_amount),'00000000.00')) total
    from
    oks_auth_headers_v h
    ,oks_auth_lines_v l
    where h.id = l.chr_id
    and ((h.start_date <= (p_end_date))
    and (h.end_date >= (p_start_date)))
    and h.attribute7 = 'SAMBA'
    -- and h.sts_code = 'ACTIVE'
    and ((h.attribute_category = 'SUBSCRIPTION.DURATION')
    or (h.attribute_category = 'SUBSCRIPTION.VALUE')
    or (h.attribute_category ='SUBSCRIPTION.QUANTITY'));
    l_output varchar2(1000);
    l_counter varchar2(11);
    l_total varchar2(11);
    l_filename varchar2(30);
    begin
    if p_filename IS NOT NULL then
    -- l_batch_no := 'T';
    l_filename := p_filename || '.txt';
    -- open file to write into and obtain its file_handle.
    file_handle := utl_file.fopen('/usr/tmp',l_filename,'W');
    fnd_file.put_line(fnd_file.log,'The '|| l_filename||' file you have requested has been placed in the usr/tmp directory');
    for l_info in c_samba
    loop
    -- l_output := null;
    l_output := l_info.samba_number||'+'||l_info.total||l_info.contract_number;
    utl_file.put_line(file_handle,l_output);
    fnd_file.put_line(fnd_file.output, l_output);
    dbms_output.put_line(l_output);
    end loop;
    else
    p_errmsg := ('Please enter a filename for this file ');
    write_log('UPDATE : ' ||p_errmsg);
    end if;
    -- close the file.
    utl_file.fclose(file_handle);
    exception
    when no_data_found then
    dbms_output.put_line('no_data_found');
    utl_file.fclose(file_handle);
    when utl_file.invalid_path then
    dbms_output.put_line('UTL_FILE.INVALID_PATH');
    utl_file.fclose(file_handle);
    when utl_file.read_error then
    dbms_output.put_line(' UTL_FILE.READ_ERROR');
    utl_file.fclose(file_handle);
    when utl_file.write_error then
    dbms_output.put_line('UTL_FILE.WRITE_ERROR');
    utl_file.fclose(file_handle);
    when others then
    dbms_output.put_line('other stuff');
    utl_file.fclose(file_handle);
    end samba_extraction;
    end xx_samba;

    Hi,
    Initialise one variable TOT_ROWS to 0.
    Then in the for loop
    tot_rows := tot_rows + +1 ;
    so after for loop the value in the tot_rows will be the total records..
    If u want it to get this value in the calling procedure of this , just declare tot_rows parameter as out parameter.
    For sum of a column:
    Initialise a variable sum_col to 0.
    In the for loop
    sum_col := sum_col+I_info.column_name
    aprameter if u wish return this value as out..
    I think this wil give u the o/p..
    cheers,
    Sivarama

  • How to count number of line items in BEX

    Hello friends,
    I am showing summarized data in BEX but i have to show one column number of records for that line .
    For e.g.
    Profit Center                        Document Number          amount 
    Newyork                                101                             1000
    Newyork                                102                             2000
    I have to show as
    Profit Centre        Amount      Line Items
    Newyork             3000           2
    Please give me suggestion how to do it in BEX ?
    Regards
    Nilesh Vakil

    Hi Nilesh,
              Check here...
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/009819ab-c96e-2910-bbb2-c85f7bdec04a
    Re: Count the values of a characteristic
    Thanks,
    Vijay.

  • How to write a Mail Java program without using the JavaMail api?

    Can I do that?
    if so, which classes should be used?
    and how can i use Javamail to write a program which
    allows me to write Email.

    You can open up raw sockets to an SMTP server to send email.
    Here is one article that has code for how to send email using sockets.
    http://www.javaworld.com/jw-12-1996/jw-12-sockets.html

  • How to Count Number of completed line items in past 6 months / 12 months ?

    How to Count Number of completed line items in past 6 months / 12 months ?
    Hi,
    I am trying to count "Number of Completed Line Items in Purchase Order Document" for my Key Figure ZPO_CNT.
    Purchase Order document = ZEBELN
    Line Item = ZEBELP.
    I need to find and count if the Line Item has been received in the past 6 months from today and similarly in the past 12 months.
    I have "Delivery Completed" field, ELIKZ.
    So, based on this would I be able to calculate it in Query Designer?
    If so, Please let me know how

    Hello Deva
    If youe want to calculate the completed line item for last 6 or 12 month then i think u will be displaying the query data for these montrhs...create a customer exit to give you date range and restric it in filter area....
    Now Choose any of the below option
    1. I would suggest to implement an additional key figure "counter" in cube and fill values with one for which delivery is completed.
    Now use calculated key figure in Query Designer based on logic
    IF counter = 1 THEN counter ELSE 0
    OR
    2. create a formula variable based on ELIKZ and use replacement path variable, it will display you no. of docs for which delivery is completed....
    Award points if it solves your problem
    Revert back in case of further assistance...
    Thanks
    Tripple k

  • Please let me know how to Count Number of completed line items in past 6 mo

    How to Count Number of completed line items in past 6 months / 12 months ?
    Hi,
    I am trying to count "Number of Completed Line Items in Purchase Order Document" for my Key Figure ZPO_CNT.
    Purchase Order document = ZEBELN
    Line Item = ZEBELP.
    I need to find and count if the Line Item has been received in the past 6 months from today and similarly in the past 12 months.
    I have "Delivery Completed" field, ELIKZ.
    So, based on this would I be able to calculate it in Query Designer?
    If so, Please let me know how
    Krishna

    Hi Experts,
    I dont have a defined Restricted key figure yet.
    I have populated 0COMPL_DEL(Delivery Completed Indicator)  and 0EBELN (Purchasing Document Number) and 0EBELP (Line Item Number in Purchasing Document) .
    This is what I think how I need to calculate:
    Number of completed line items in past 6 months:
    If  Delilvery Completed Indicator (0COMPL_DEL) = x, calculate No. of Line Items (ZPO_CNT) from 0CALDAY to 6 months
    and
    Number of completed line items in past 12 months:
    If  Delilvery Completed Indicator (0COMPL_DEL) = x, calculate No. of Line Items (ZPO_CNT) from 0CALDAY to 12 months
    Please let me know if the logic is correct. If so, how I can create this in report

  • How to count number of ones in table

    Hello,
     i created one table 16x32 each cell is updating 1 byte of data,how to count number of one in all cell,and is it right way to calculate check sum??
    thank you

    The simplest way is to call GetTableCellRangeValues with VAL_ENTIRE_TABLE as the range, next summing array elements.
    But I don't understand your comment on checksum, so this may not be the more correct method for your actual needs: can you explain what do you mean?
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • How to count number of sales orders generated in a month in SAP SD

    Hi SD Gurus,
    I have a very strange query from client. I have to count the number of sales order created in a month for a z report. For example 30 in Jan, 25 in Feb etc. Could anyone suggest me How to count number of sales orders generated in a month in SAP SD.
    Regards
    Vinod Kumar

    Hi,
    Goto the T.Code "SE16" or "SE16n" or "SE11".
    Enter the table name as VBAK
    Enter the created on date as the starting date of the period and to date as the end date.
    Enter.
    Click on "Number of Entries".It will tell you the number of entries created in a particular period.
    If you want a report,goto the T.Code "VA05n".
    Regards,
    Krishna.

  • How to count number of rows in table

    can I get number of row in table except Count(*) in pl/sql
    is there any other way

    Also posted and answered here
    how to count number of rows in table
    count(*) will be the fastest way. It is only slow if the table has a vast number of rows, in which case why do you need to know the tables has 73552436467721 rows and not 73552436467737 rows. It doesn't seem to be much use. Either that or you are counting them a lot, which again seems rather pointless.

  • How to count number of online user

    i am developing bid application using servlet/jsp. how to count number of online user ple help me.

    hi,
    may be the following code help you...
    import javax.servlet.http.HttpSessionListener;
    import javax.servlet.http.HttpSessionEvent;
    public class ActiveUserCount implements HttpSessionListener {
         private static int activeUsers = 0;
         public void sessionCreated(HttpSessionEvent se) {
              activeUsers++;
         public void sessionDestroyed(HttpSessionEvent se) {
              if(activeUsers > 0)
                   activeUsers--;
         public static int getActiveUsers() {
              return activeUsers;
    }Dhaval

  • How would I go about adding multiple rectangles using the same lines of code?

    How would I go about adding multiple rectangles using the same lines of code? I would prefer to just run through a set of code every time I need a polygon. If I just have to create multiple polygon adding statements that's fine but I'd prefer just 1.

    >>How would I go about adding multiple rectangles using the same lines of code?
    You could create a method that creates and returns x number of Rectangle elements:
    public IEnumerable<Rectangle> CreateRectangles(int numberOfRectsToCreate)
    for (int i = 0; i < numberOfRectsToCreate; ++i)
    Rectangle rect = new Rectangle();
    rect.Fill = Brushes.Blue;
    rect.Width = 100;
    rect.Height = 100;
    yield return rect;
    ..and then call this method from anywhere in your code:
    IEnumerable<Rectangle> rects = CreateRectangles(5);
    foreach (Rectangle rect in rects)
    //add to StackPanel or do whatever with the Rectangle elements:
    yourStackPanel.Children.Add(rect);
    >>If I just have to create multiple polygon adding statements that's fine but I'd prefer just 1.
    When adding Point objects to a Polygon you can only add one per call to the Add method but you could call the Add method inside a loop, e.g:
    for(int i = 0; i < 10; ++i)
    //add to StackPanel or do whatever with the Rectangle elements:
    Polygon p = new Polygon();
    p.Points.Add(new Point());
    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't post several questions in the same thread.

  • How to create a muli line text area using JavaFx

    Hi all,
    Since the preview SDK does not contain TextArea any more, I am wondering how to create a muli line text area using JavaFX. The behaviour of this text area/field should be somehow similar to JTextArea in Swing or StyledTextWidget in SWT.
    Does JavaFX have any support for this? What would be a sensible approach to create such a widget?
    Thanks for your suggestions,
    br michael

    This is a pretty old thread (I know I came across this while searching for something similar recently), but I figured I'd throw this out there in case other people might find this useful. As I write this, JavaFX's latest version is 1.3... which may have added the needed functionality since the last post.
    You can now create a multi-line text area using a TextBox and by specifying the nubmer of lines and setting the "multiline" value to true. It may not offer all of the same functionality as JTextArea, but it did the job for what I needed... newlines by pressing enter, scrollbar if text surpasses height, etc.
    Here's a simple example:
    Group {
       content: [
          TextBox {
             text: "This is a multi-line textbox"
             lines: 10  // <-- this may/may not be necessary depending on your situation. Default is 5.
             multiline: true
    }Edited by: loeschg on Jul 29, 2010 2:59 PM

Maybe you are looking for

  • Problems with string array, please help!

    I have a String array floor[][], it has 20 rows and columns After I do some statement to modify it, I print this array out in JTextArea, why the output be like this? null* null.... null null... null null... How to correct it?

  • External Hard Drive not showing up as a back up disk

    Please Help, I'm freaking out! I received a message stating "Time Machine has not backed up in 10 Days." So I tried to do a manual back up, a manual back up as worked before. Time Machine looked like it was beginning a back, but then it stopped. So I

  • Can't find programs in the CC app

    Could someone help me with downloading Lightroom 6/CC? When I launch the CC app on my computer, and press "Install Adobe apps", nothing happens. Sometimes even the CC app crashes and the app turns black... Does anybody have any solutions?

  • RAID-5 over RAID-1, with encryption

    I'm planning to restructure my fileserver.  It has (well, will have) 8 hard drives for data, each 1.5 TB in size.  I want to create 4 mirrored pairs, and then place each pair in a RAID-5 array, for a total usable space of 4.5 TB.  I want to place enc

  • High CPU usage new MBP C2D

    I was working on laptop today and all of a sudden both fans kicked in full speed. I noticed in the past sometimes Safari was get a glitch and lock cpu usage at 98%. But today it was a process RPC.net? I force quit, required password and all normal. W