How to copy methods signatures from one class to a file?












0














I have a Java class that contains all my methods that are reusable in other parts of a framework. There are lots of them. I cannot do much about it because of company policy.



I would like to copy all lines from that class that starts with "public" to a file or another class. Just to have methods signatures for easier search for specific functionality. These methods are being added, removed overtime so maybe a method to copy all of them which can be manually started when I need it? Maybe regular expressions can help but I don't know how to deal with it.










share|improve this question




















  • 3




    Document the methods directly inside the class and extract the signatures with javadoc?
    – Federico klez Culloca
    Nov 9 at 11:23










  • java or reflection will give you a way to generate this you want to generate this file when you want?
    – Arnault Le Prévost-Corvellec
    Nov 9 at 11:25










  • @FedericoklezCulloca has provided the best approach for this. In fact, I hope he can expand that into an answer. As to the answer / comment regarding reflection. While this might seem to answer the question, it is overkill. See Is “Don't do it” a valid answer? (spoiler: yes it is, if there is a better approach altogether).
    – Andrew Thompson
    Nov 10 at 5:06






  • 1




    @AndrewThompson done as requested
    – Federico klez Culloca
    Nov 12 at 10:54
















0














I have a Java class that contains all my methods that are reusable in other parts of a framework. There are lots of them. I cannot do much about it because of company policy.



I would like to copy all lines from that class that starts with "public" to a file or another class. Just to have methods signatures for easier search for specific functionality. These methods are being added, removed overtime so maybe a method to copy all of them which can be manually started when I need it? Maybe regular expressions can help but I don't know how to deal with it.










share|improve this question




















  • 3




    Document the methods directly inside the class and extract the signatures with javadoc?
    – Federico klez Culloca
    Nov 9 at 11:23










  • java or reflection will give you a way to generate this you want to generate this file when you want?
    – Arnault Le Prévost-Corvellec
    Nov 9 at 11:25










  • @FedericoklezCulloca has provided the best approach for this. In fact, I hope he can expand that into an answer. As to the answer / comment regarding reflection. While this might seem to answer the question, it is overkill. See Is “Don't do it” a valid answer? (spoiler: yes it is, if there is a better approach altogether).
    – Andrew Thompson
    Nov 10 at 5:06






  • 1




    @AndrewThompson done as requested
    – Federico klez Culloca
    Nov 12 at 10:54














0












0








0







I have a Java class that contains all my methods that are reusable in other parts of a framework. There are lots of them. I cannot do much about it because of company policy.



I would like to copy all lines from that class that starts with "public" to a file or another class. Just to have methods signatures for easier search for specific functionality. These methods are being added, removed overtime so maybe a method to copy all of them which can be manually started when I need it? Maybe regular expressions can help but I don't know how to deal with it.










share|improve this question















I have a Java class that contains all my methods that are reusable in other parts of a framework. There are lots of them. I cannot do much about it because of company policy.



I would like to copy all lines from that class that starts with "public" to a file or another class. Just to have methods signatures for easier search for specific functionality. These methods are being added, removed overtime so maybe a method to copy all of them which can be manually started when I need it? Maybe regular expressions can help but I don't know how to deal with it.







java class methods copy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 5:02









Andrew Thompson

153k27163338




153k27163338










asked Nov 9 at 11:20









emukiss

11




11








  • 3




    Document the methods directly inside the class and extract the signatures with javadoc?
    – Federico klez Culloca
    Nov 9 at 11:23










  • java or reflection will give you a way to generate this you want to generate this file when you want?
    – Arnault Le Prévost-Corvellec
    Nov 9 at 11:25










  • @FedericoklezCulloca has provided the best approach for this. In fact, I hope he can expand that into an answer. As to the answer / comment regarding reflection. While this might seem to answer the question, it is overkill. See Is “Don't do it” a valid answer? (spoiler: yes it is, if there is a better approach altogether).
    – Andrew Thompson
    Nov 10 at 5:06






  • 1




    @AndrewThompson done as requested
    – Federico klez Culloca
    Nov 12 at 10:54














  • 3




    Document the methods directly inside the class and extract the signatures with javadoc?
    – Federico klez Culloca
    Nov 9 at 11:23










  • java or reflection will give you a way to generate this you want to generate this file when you want?
    – Arnault Le Prévost-Corvellec
    Nov 9 at 11:25










  • @FedericoklezCulloca has provided the best approach for this. In fact, I hope he can expand that into an answer. As to the answer / comment regarding reflection. While this might seem to answer the question, it is overkill. See Is “Don't do it” a valid answer? (spoiler: yes it is, if there is a better approach altogether).
    – Andrew Thompson
    Nov 10 at 5:06






  • 1




    @AndrewThompson done as requested
    – Federico klez Culloca
    Nov 12 at 10:54








3




3




Document the methods directly inside the class and extract the signatures with javadoc?
– Federico klez Culloca
Nov 9 at 11:23




Document the methods directly inside the class and extract the signatures with javadoc?
– Federico klez Culloca
Nov 9 at 11:23












java or reflection will give you a way to generate this you want to generate this file when you want?
– Arnault Le Prévost-Corvellec
Nov 9 at 11:25




java or reflection will give you a way to generate this you want to generate this file when you want?
– Arnault Le Prévost-Corvellec
Nov 9 at 11:25












@FedericoklezCulloca has provided the best approach for this. In fact, I hope he can expand that into an answer. As to the answer / comment regarding reflection. While this might seem to answer the question, it is overkill. See Is “Don't do it” a valid answer? (spoiler: yes it is, if there is a better approach altogether).
– Andrew Thompson
Nov 10 at 5:06




@FedericoklezCulloca has provided the best approach for this. In fact, I hope he can expand that into an answer. As to the answer / comment regarding reflection. While this might seem to answer the question, it is overkill. See Is “Don't do it” a valid answer? (spoiler: yes it is, if there is a better approach altogether).
– Andrew Thompson
Nov 10 at 5:06




1




1




@AndrewThompson done as requested
– Federico klez Culloca
Nov 12 at 10:54




@AndrewThompson done as requested
– Federico klez Culloca
Nov 12 at 10:54












2 Answers
2






active

oldest

votes


















1














You can use javadoc to generate the documentation for you, provided that you add javadoc comments to your method.



So for example, suppose your class has a User getUser(int id) method. Also suppose your class is in package com.example.myproject. Just before the method definition you should put something like this



/**
* Returns a user given an id
*
* @param id the id the User has on database
* @return An instance of <code>User</code> corresponding to the given id
*/
public User getUser(int userId) {


Notice that the comment starts with /** and not with /*.



Once you've done that you can invoke javadoc to generate the documentation html for your package.



javadoc com.example.yourproject


Here is the manual for javadoc with further instructions if you need to do anything fancier. And here are some suggestions on how to best write your documentation (dated, but still good).






share|improve this answer





























    0














    By reflection you can do something like :



    import java.lang.reflect.Method;
    import java.lang.reflect.Parameter;
    import java.util.Arrays;
    import java.util.stream.Collectors;

    public class ReflectionCode {
    public static String reflect(Class<?> classToRead) {
    StringBuilder sb = new StringBuilder();
    for (Method clas : classToRead.getMethods()) {
    System.out.println(clas.getReturnType().getSimpleName() + " " +
    clas.getName() + "(" + String.join(",", //
    Arrays.stream(clas.getParameters())//
    .map(ReflectionCode::parameterToString)//
    .collect(Collectors.toList()))
    + ")");
    }
    return sb.toString();
    }

    public static String parameterToString(Parameter p) {
    return p.getType().getSimpleName() + " " + p.getName();
    }

    public static void main(String args) {
    System.out.println(reflect(ReflectionCode.class));
    }
    }





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224764%2fhow-to-copy-methods-signatures-from-one-class-to-a-file%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      You can use javadoc to generate the documentation for you, provided that you add javadoc comments to your method.



      So for example, suppose your class has a User getUser(int id) method. Also suppose your class is in package com.example.myproject. Just before the method definition you should put something like this



      /**
      * Returns a user given an id
      *
      * @param id the id the User has on database
      * @return An instance of <code>User</code> corresponding to the given id
      */
      public User getUser(int userId) {


      Notice that the comment starts with /** and not with /*.



      Once you've done that you can invoke javadoc to generate the documentation html for your package.



      javadoc com.example.yourproject


      Here is the manual for javadoc with further instructions if you need to do anything fancier. And here are some suggestions on how to best write your documentation (dated, but still good).






      share|improve this answer


























        1














        You can use javadoc to generate the documentation for you, provided that you add javadoc comments to your method.



        So for example, suppose your class has a User getUser(int id) method. Also suppose your class is in package com.example.myproject. Just before the method definition you should put something like this



        /**
        * Returns a user given an id
        *
        * @param id the id the User has on database
        * @return An instance of <code>User</code> corresponding to the given id
        */
        public User getUser(int userId) {


        Notice that the comment starts with /** and not with /*.



        Once you've done that you can invoke javadoc to generate the documentation html for your package.



        javadoc com.example.yourproject


        Here is the manual for javadoc with further instructions if you need to do anything fancier. And here are some suggestions on how to best write your documentation (dated, but still good).






        share|improve this answer
























          1












          1








          1






          You can use javadoc to generate the documentation for you, provided that you add javadoc comments to your method.



          So for example, suppose your class has a User getUser(int id) method. Also suppose your class is in package com.example.myproject. Just before the method definition you should put something like this



          /**
          * Returns a user given an id
          *
          * @param id the id the User has on database
          * @return An instance of <code>User</code> corresponding to the given id
          */
          public User getUser(int userId) {


          Notice that the comment starts with /** and not with /*.



          Once you've done that you can invoke javadoc to generate the documentation html for your package.



          javadoc com.example.yourproject


          Here is the manual for javadoc with further instructions if you need to do anything fancier. And here are some suggestions on how to best write your documentation (dated, but still good).






          share|improve this answer












          You can use javadoc to generate the documentation for you, provided that you add javadoc comments to your method.



          So for example, suppose your class has a User getUser(int id) method. Also suppose your class is in package com.example.myproject. Just before the method definition you should put something like this



          /**
          * Returns a user given an id
          *
          * @param id the id the User has on database
          * @return An instance of <code>User</code> corresponding to the given id
          */
          public User getUser(int userId) {


          Notice that the comment starts with /** and not with /*.



          Once you've done that you can invoke javadoc to generate the documentation html for your package.



          javadoc com.example.yourproject


          Here is the manual for javadoc with further instructions if you need to do anything fancier. And here are some suggestions on how to best write your documentation (dated, but still good).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 at 10:53









          Federico klez Culloca

          15.6k134275




          15.6k134275

























              0














              By reflection you can do something like :



              import java.lang.reflect.Method;
              import java.lang.reflect.Parameter;
              import java.util.Arrays;
              import java.util.stream.Collectors;

              public class ReflectionCode {
              public static String reflect(Class<?> classToRead) {
              StringBuilder sb = new StringBuilder();
              for (Method clas : classToRead.getMethods()) {
              System.out.println(clas.getReturnType().getSimpleName() + " " +
              clas.getName() + "(" + String.join(",", //
              Arrays.stream(clas.getParameters())//
              .map(ReflectionCode::parameterToString)//
              .collect(Collectors.toList()))
              + ")");
              }
              return sb.toString();
              }

              public static String parameterToString(Parameter p) {
              return p.getType().getSimpleName() + " " + p.getName();
              }

              public static void main(String args) {
              System.out.println(reflect(ReflectionCode.class));
              }
              }





              share|improve this answer




























                0














                By reflection you can do something like :



                import java.lang.reflect.Method;
                import java.lang.reflect.Parameter;
                import java.util.Arrays;
                import java.util.stream.Collectors;

                public class ReflectionCode {
                public static String reflect(Class<?> classToRead) {
                StringBuilder sb = new StringBuilder();
                for (Method clas : classToRead.getMethods()) {
                System.out.println(clas.getReturnType().getSimpleName() + " " +
                clas.getName() + "(" + String.join(",", //
                Arrays.stream(clas.getParameters())//
                .map(ReflectionCode::parameterToString)//
                .collect(Collectors.toList()))
                + ")");
                }
                return sb.toString();
                }

                public static String parameterToString(Parameter p) {
                return p.getType().getSimpleName() + " " + p.getName();
                }

                public static void main(String args) {
                System.out.println(reflect(ReflectionCode.class));
                }
                }





                share|improve this answer


























                  0












                  0








                  0






                  By reflection you can do something like :



                  import java.lang.reflect.Method;
                  import java.lang.reflect.Parameter;
                  import java.util.Arrays;
                  import java.util.stream.Collectors;

                  public class ReflectionCode {
                  public static String reflect(Class<?> classToRead) {
                  StringBuilder sb = new StringBuilder();
                  for (Method clas : classToRead.getMethods()) {
                  System.out.println(clas.getReturnType().getSimpleName() + " " +
                  clas.getName() + "(" + String.join(",", //
                  Arrays.stream(clas.getParameters())//
                  .map(ReflectionCode::parameterToString)//
                  .collect(Collectors.toList()))
                  + ")");
                  }
                  return sb.toString();
                  }

                  public static String parameterToString(Parameter p) {
                  return p.getType().getSimpleName() + " " + p.getName();
                  }

                  public static void main(String args) {
                  System.out.println(reflect(ReflectionCode.class));
                  }
                  }





                  share|improve this answer














                  By reflection you can do something like :



                  import java.lang.reflect.Method;
                  import java.lang.reflect.Parameter;
                  import java.util.Arrays;
                  import java.util.stream.Collectors;

                  public class ReflectionCode {
                  public static String reflect(Class<?> classToRead) {
                  StringBuilder sb = new StringBuilder();
                  for (Method clas : classToRead.getMethods()) {
                  System.out.println(clas.getReturnType().getSimpleName() + " " +
                  clas.getName() + "(" + String.join(",", //
                  Arrays.stream(clas.getParameters())//
                  .map(ReflectionCode::parameterToString)//
                  .collect(Collectors.toList()))
                  + ")");
                  }
                  return sb.toString();
                  }

                  public static String parameterToString(Parameter p) {
                  return p.getType().getSimpleName() + " " + p.getName();
                  }

                  public static void main(String args) {
                  System.out.println(reflect(ReflectionCode.class));
                  }
                  }






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 9 at 11:41









                  Federico klez Culloca

                  15.6k134275




                  15.6k134275










                  answered Nov 9 at 11:40









                  Arnault Le Prévost-Corvellec

                  3978




                  3978






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224764%2fhow-to-copy-methods-signatures-from-one-class-to-a-file%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Florida Star v. B. J. F.

                      Danny Elfman

                      Lugert, Oklahoma