Max number of lines in method.

Hi,
Syntatically a method can span for any number of lines, but is there
a limit on number of lines in a method so that it conforms to java code
conventions. Could not find anything about the number of lines in Sun java code conventions doc.
Thanks
Deepak

The whole point is write a method that does only one thing. The hard thing is to determine what one thing is. A method which only
does one thing can also become long, and needs to be broken down
to several small methods. A method name is a very good documentation
(unless you use random method names)I also use one of my few rules of thumb here:
rule#5059723586: if you can't describe in one sentence, using
appropriate detail, what a method does, it needs to be refactored to
at least two methods. repeat rule#5059723586 as long as applicable.
rule#5059723586B: The verbs and nouns of the 'appropriate detail'
mentioned in rule#5059723586 must refer to members, parameters
or other methods (see also rule# 5059723586)
kind regards,
Jos ;-)

Similar Messages

  • 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.

  • Jsp+Tomcat: Is there a max number of lines in a html file generated?

    Hi, I write a jsp page that does a lot of queries on a database and, for each query, views a table with the records return by the query. I have a problem: if the number of queries is low the page work well; if the number of queries is high the page has been truncated. If a watch at the html file of the browser it's like truncated. Are there any parameters that i have to modify? thaks very much

    Truncation usually indicates that an exception occurred after the response had already been committed (due to the output buffer becoming full which will cause it to be flushed).
    check out the logfiles of your webserver if there are any unexpected exceptions in there.

  • Number of lines in a method

    Hi all,
    can you please tell me how to get the number of lines in each method in a java file.
    class test
    public void method(){
    sop()...
    sop()...
    In that above class, the number of lines in "method" is 2.
    is there any api in java which will return us the number of lines in each method in a java file?
    Please suggest me..

    -I was wondering about some crazy bytecode reader.javap?
    -I agree it's not the best solution, but going for 100% accuracy wasn't the aim here :)Please understand that I'm not criticizing your attempt, but rather that the OP's requirements are far too vague to provide any useful advice.
    -How does it not deal with loops/code blocks? (case statements maybe as I forgot ":")Example:
    String method =
        "void method() {\n" +
        "    for (int i = 0; i < 1; i++) {\n" +
        "        System.out.println(this.toString());\n" +
        "    }\n" +
    int expectedLineCount = 3; // possibly, based on what the OP's indicated so far...
    int actualLineCount = method.split("[;{}]").length; // per your example
    assert expectedLineCount != actualLineCount;~

  • Number of Lines limited in InfoPackage Selection?

    Hello Experts!
    I have 2 InfoPackage in order to load Data from ODS1 into ODS2. Selection is made for customer number - exact criteria is made via Abap Routine in InfoPackage. (InfoPackage 1 has all customers meeting a certain criteria - InfoPackage 2 has all the ranges in between the customer Numvers of InfoPackage 1).
    Therefore the load of both InfoPackages should load all data - but the problem is, I only get a small part of the Data. In ODS 1 there are some 2.800.000 entries and in ODS2 the load of the 2 InfoPackages only select about 30.000 entries.
    Since the selection criteria in monitoring seem fine - do you have any idea where the problem comes from? Is there a max. number of lines for selection to be made in infoPackage?
    Thanks for your help!
    Angelika

    Hi Angelika,
    check out the monitor --> in the request tree check the numbers coming into the update rules an coming out of the update rules, may be you are loosing some records there. The only thing that I know about the size of selections is that you will get a dump if you have to many entries in a select-option table (and having those lines in a infopackage is nothing else).
    Another reason might be a missing alpha conversion of the entries in the infopackage.
    kind regards
    Siggi

  • What is the maximum number of line items we can enter in an order...

    Hi,
       Can anyone explain what is the max number of line items that v can enter in an order....
    or if i want to increase the number of line items than the max where it is controlled.
    Because my mm counter part is facing this in the PO he could make only 9999,the problem is when posting...the accounting document is not getting generated bcas of exceeding the limit.
    venugopal

    hi,
    this is my personal experiance that we can enter at the most 499 line items in SALES ORDER.
    This is because for every line item there will be 2 financial entries, debit and credit. and 1 FI document can have at the most 999 line items (which we can not increase without KEY fromSAP)
    If we divide 999 by 2 then it comes to 499.50 so you can enter at the most 499 line items in Sales order.
    Regards
    Vishal

  • What is the maximum number of lines per PO?

    Are their line limitations per PO? I'm trying to find out if there is a max number of lines you can have on a given PO.
    I assume performance starts to get effected at some point, but at what point might that be? 100 lines, 1000, 5000? We are looking at creating some standard PO's with 500+ lines on them, so we can create ASN against them via iSupplier.
    If you know or have any experience dealing with large PO's please fill me in.
    Thanks,
    Jeremy

    Hello,
    We used to have an interface who imported standard PO, with a contract number as PO number, then the number of lines was increasing. We had a first problem from 200 lines, we had to apply a patch, then the limit was about 900 lines. I made a few searches but this occurs 2 years ago and I'm not even able to find the SR or a patch number ...
    But from a business point of view, it's obviously a bad idea to always have the same PO with a high number of lines (hard to match invoices, PO is never closed, etc.) , from this problem we choose to import PO with PO number generated from the BL number + an suffix (to avoid duplicates PO numbers)
    Hope it helps a little,
    Kind regards,
    Xavier

  • Maximum number of lines textfield

    Hi everybody !
    I need to set a maximum number of lines on a text field that should be expandable up to that line number and not beyond.
    Who do I know how to do?

    You can control the number of chars in the field, you can limit the field to the visible area but you cannot dictate a number of lines that the field can be. The closest thing you can get is to make  the field the max number fo lines and then use "limit to visible area" so that people cannot add more text.
    Paul

  • Java Program+To count the number of lines in a method excluding comments???

    Hi friends
    can u plz help me out, the java program is counting the number of lines in a method excluding comments.
    The first thing is how to identify a method, then there can be an inner method inside the parent method,
    Please friends its urgent
    Bye
    Sandy

    There's no such thing as an inner method in Java. You can either write the code yourself to parse Java source, or maybe something like ANTLR can do it.

  • Effiecient method to get number of lines in a JEditorPane

    My Computer Science class has a major grade project to complete by Dec. 15. For my project I've decided to make a tabbed Java IDE with save, open, compile, run, and some font options. Due to the need to make Java use the command prompt to compile and run, it will be Windows specific.
    Now, next to my JEditorPane I want to put a JPanel with a GridLayout full of JLabels that will hold the line numbers. I'm having a small problem getting the precise number of lines though. Due to the nature of JEditorPane, I can't just count the number of newline characters in the JEditorPane. I've tried to use a Scanner to go through the text and find all instances of the string "<p style=\"margin-top: 0\">" but because the JEditorPane doesn't make a new <p> tag until text is entered into a new line, this only works some of the time.
    Does anyone know of a way I can effectively and efficiently find the number of lines in the JEditorPane at any given time?
    Message was edited by:
    TheGuy@YourWindow

    Swing related questions should be posted in the Swing forum.
    Normally for a text editor you would use a JTextArea for simple text or a JTextPane if you plan on doing syntax highlighting. JEditorPane is typically used to display HTML files.
    If you search the Swing forum using "utextcomponent" you will find my class that has methods that might be handy for what you want.

  • Count the number of Lines with in a method

    I am trying to write a program that will report back the number of methods/types/names and proxies as well as the number of lines of code in each method... I can not figure out how to count each methods line of code separately thanks. each method is commented by
    /* PROXY proxyname type */
    /* METHOD method name*/
    public class Assignment3
    private static BufferedReader userInput = new BufferedReader (new InputStreamReader (System.in));
         * @param args
         * @throws IOException
         * @param args
         * @throws IOException
         public static void main(String[] args) throws IOException
              System.out.print("Enter the .java file name: ");
         String input = userInput.readLine();
         while (!input.equalsIgnoreCase("stop"))
              System.out.println("Total Number of Lines: " + LOC(input) + "\n" + Method(input) + "\n" + Type(input));
              System.out.print("\nEnter file name to search again or \"stop\" to terminate the program: ");
              input = userInput.readLine();
    public static int LOC(String inputFile) throws IOException, FileNotFoundException
         int numLines = 0;
         try
                        FileReader FileIn = new FileReader(inputFile);
                        Scanner scanLines = new Scanner (FileIn);
                        String line;
                             while (scanLines.hasNext())
                                  line = scanLines.nextLine();
                                  if (line.startsWith("/*"))
                                       numLines--;
                                  else if(!line.equals(" "))
                                       numLines++;
                             FileIn.close();
              catch(IOException IOE)
                   System.out.println("\nFile Not Found!");
                   return numLines;
    public static int MethodLOC(String inputFile) throws IOException, FileNotFoundException
         File FileIn = new File(inputFile);
         Scanner scanLines = new Scanner (FileIn);
         String line = null;
         int methodLOC = 0;
         while(scanLines.hasNext())
              line = scanLines.nextLine();
              if(!line.contains("/*"))
                   StringTokenizer st = new StringTokenizer(line, "\n");
                   methodLOC = st.countTokens();
         return methodLOC;
    public static String Method(String inputFile) throws IOException, FileNotFoundException
         String line = null;
         String name = null;
         String info = null;
         File FileIn = new File(inputFile);
         Scanner scanLines = new Scanner (FileIn);
         while(scanLines.hasNext())
              line = scanLines.nextLine();
         if(line.contains("METHOD"))
              StringTokenizer st = new StringTokenizer(line, " ");
              String proxy = st.nextToken();
              String method = st.nextToken();
              name = st.nextToken();
              info = "Name of Method: " + name;
    return info;
    public static String Type(String inputFile) throws IOException, FileNotFoundException
         String line = null;
         String name = null;
         String info = null;
         String count = null;
         File FileIn = new File(inputFile);
         Scanner scanLines = new Scanner (FileIn);
         while(scanLines.hasNext())
         if(line.contains("PROXY"))
              StringTokenizer st = new StringTokenizer(line, " ");
              String proxy = st.nextToken();
              String method = st.nextToken();
              name = st.nextToken();
              String type = st.nextToken();
              info = "Name of Proxy: " + name + "\n" + "Type of Proxy: " + type;
         count = info;
    return count;
    }

    Iterate through the lines and count the opening and closing curly braces. Whenever you see an opening one, increase the counter, when you see a closing one, decrease the counter. When the counter hits 0 again, you reached the end of the method.
    I assume you know how to count lines while moving through a text line by line.

  • Counting the number of lines for each procedure in a package

    Hi,
    I would like to write a query on USER_SOURCE that can display the number of code lines for each procedure/function in a package.
    Is it possible to write such a query? Maybe by using analytical functions?
    for example in the following example i would like to count the lines between "PROCEDURE proc1 IS" and "END proc1;" and between "PROCEDURE proc2 IS" and "END proc2;"
    SQL> select text  from user_source where name='PKG_TEST' and type='PACKAGE BODY';
    TEXT
    PACKAGE BODY PKG_TEST IS
      PROCEDURE proc1 IS
      BEGIN
        update t1 set EDITION_NAME = 'AAAAAAA';
        commit;
      END proc1;
    PROCEDURE proc2 IS
      BEGIN
       update t1 set EDITION_NAME = 'AAAAAAA';
        commit;
      END proc2;
    END PKG_TEST;thanks for helping

    onedbguru wrote:
    Hopefully some idiot manager isn't trying to use this sort of thing to base their decisions on developer productivity. If so, they ARE idiots. Number of code lines NEVER, EVER, EVER!!! translates into an efficient application. If I were paid by the line, my code would look like:
    select
    1
    from
    dual
    Based on the idiocy of this method of determining "performance" I would get paid $5.00 at $1.00/line. And trust me, I saw this back in the 80's and 90's and saw similar idiotic code and had to clean up the mess. Most of it wasn't efficient code to start with let alone the number of lines generated.Or the other extreme, when the PHB firmly believed that execution efficiency was gained by reducing the number of lines of code. So instead of nicely formatted, easy to read code:
          *GET NEXT ORDER NUMBER                                                               
                EXEC SQL                                                                        
                     SELECT (MAX(ORDER_NUM) + 1)                                                
                     INTO   :NEXT-NUM:IND-NULL                                                  
                     FROM   PART_ORDER                                                          
                END-EXEC.                                                                       
                IF IND-NULL < 0                                                                 
                  MOVE 1 TO NEXT-NUM.                                                           
                EXEC SQL                                                                        
                     INSERT                                                                     
                     INTO    PART_ORDER                                                         
                            (ORDER_NUM,                                                         
                             ORIGIN_LOC,                                                        
                             ORDER_TYPE,                                                        
                             ORDER_STAT,                                                        
                             CREAT_TIME)                                                        
                     VALUES (:NEXT-NUM,                                                         
                             :LOC, 'R', 'O',                                                    
                             CURRENT TIMESTAMP)                                                 
                   END-EXEC.                                                                    
                MOVE NEXT-NUM TO MASK0.                                                         
                PERFORM HEADER-PROC THRU HEADER-EXIT.                                           
            CREATE-ORDER-EXIT. EXIT.                                                     You got this:
           *GET NEXT ORDER NUMBER
            EXEC SQL SELECT (MAX(ORDER_NUM) + 1) INTO :NEXT-NUM:IND-NULL FROM
            PART_ORDER END-EXEC. IF IND-NULL < 0 MOVE 1 TO NEXT-NUM. EXEC SQL INSERT
            INTO PART_ORDER (ORDER_NUM, ORIGIN_LOC, ORDER_TYPE, ORDER_STAT,
            CREAT_TIME) VALUES (:NEXT-NUM, :LOC, 'R', 'O', CURRENT TIMESTAMP)
            END-EXEC. MOVE NEXT-NUM TO MASK0. PERFORM HEADER-PROC THRU HEADER-EXIT.
            CREATE-ORDER-EXIT. EXIT.                 Oh, wait! See the same thing all the time in this forum ... not because someone thinks fewer lines = faster code, but simply because people are sloppy.
    INSERT INTO PART_ORDER(ORDER_NUM,ORIGIN_LOC,ORDER_TYPE,ORDER_STAT,CREAT_TIME) VALUES (:NEXT-NUM,:LOC, 'R', 'O',CURRENT TIMESTAMP) ;

  • Restriction on number of line items in an automatically generated document

    Hi all,
    As per my info, an accounting document must have a minimum of 2 line items to complete the document. At the same time an accounting document can have a maximum of 999 line items.
    My observation:-
    When I am posting depreciation using t-code AFAB, system is posting depreciation document (document type AF). While checking, I found that the system has posted around 16 document for a period.
    On further checking, I observed that the each document contains a max 100 line items.
    I am using SAP 4.7
    My Query:-
    a> Is there any way / place wherein we can restrict the maximum number of line items possible for a given docuemnt type or for all document types in the client?
    b> In case it is not possible to restrict the number of line items per document, what could be possible reason for the system behaviour wherein it is posting about 100 line items per document & thereafter starts a new document.
    Thanking you in advance
    Santosh K Agarwal

    Hi,
    I have been reading CIN. There I came across with a statement i.e. "There is restriction on no of line items to be in an Excise Invoice".
    where you read this i dont know
    but yes for outgoing excise invoice we can put limitation in sap cin
    as per incoming excise invoice i think no  limitation
    in path SPRO-tax on goods movemnet-India-basic setting-maintain excise registration here you can maintain this
    and yes this for india only for other country they may have different
    Regards
    Kailas ugale

  • ALV_GRID How to get number of lines after filted applyed?

    Hi, all!
    The task is to display title in alv_grid like
    "N records selected (X records on the screen)".
    It means, N records in dataset and X records displayed after  filter applyed by user.
    But i can't get number of lines after filter applyed from the alv_grid.
    Can anybody help me?
    Thanks & regards,
    Konstantin

    Hi,
    If it goes through PBO/PAI cycle after user sets the filter then in your PBO call method get_filtered_entries of CL_GUI_ALV_GRID and then do a describe statement on the table.
    Number of entries in your grid table - number of entries in this filtered entries table will give you the displayed entries after the filter is set.
    If it does not go through PBO/PAI cycle then register for after_user_command and I think the fcode for filter is '&FILTER' and code for the above logic in your handler method..
    Hope this helps..
    Sri

  • How to get the number of lines of a file?

    Folks:
    Is there a way to get the number of lines of a text file? I don't know if there is an existing method to do that.
    Thanks a lot.

    HI
    I found some solution
    other than increment loop and all
    here is the code it might helpful to u
    //returns the number of lines in a file
    //author : Ravindra S
    //Symphony software Hyderabad
    try
    RandomAccessFile randFile = new RandomAccessFile(csvFile,"r");
    long lastRec=randFile.length();
    randFile.close();
    FileReader fileRead = new FileReader(csvFile);
    LineNumberReader lineRead = new LineNumberReader(fileRead);
    lineRead.skip(lastRec);
    countRec=lineRead.getLineNumber()-1;
    fileRead.close();
    lineRead.close();
    catch(IOException e)

Maybe you are looking for

  • IPhone 5S Rear Microphone Causing Muffled/Quiet Voice Calls

    Hi folks, There are quite a few threads here about this issue - iPhone 5S (in my case 32GB grey) with iOS 7.0.4 - fresh install from factory - phone only a few days old - the Rear Microphone (just next to the rear camera) is causing major issues with

  • WorkOrderList TileView Row & Selected Row Background Color Change

    Hi,      can we change the background color of WorkorderList TileView Row & Selected Row Background color ?. Actually i am trying to change the color of both in WorkOrderList but it not reflecting any color on my Agentry client. I used a style on Til

  • Imported text caption objects cause errors

    I imported objects only from a similar Captivate project. When I tried to edit the text captions, I would double click the text caption and nothing would happen. Then I would get a blank gray screen of death before the application would crash. This n

  • Sql-loader error, help!!!!

    Recently I found the following error message in the sql-loader log file. ora-704 , I can't find corresponding explainatino in oracle documentation. I use sql-loader 7.3 to load .dat file extracted from our ERP system. This error can't be monitored by

  • Create a new user with Privileges to execute Seeded API's

    Hi, We have a requirement from our client, they want to create a new user with Privileges to execute Seeded API's, So they dont want to execute using APPS user. We want to know is it possible to have a new user for executing seeded API's and if so wh