Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35866 > unrolled thread
| Started by | Philipp Kraus <philipp.kraus.flashpixx@gmail.com> |
|---|---|
| First post | 2016-10-26 14:37 -0700 |
| Last post | 2016-10-30 02:35 -0700 |
| Articles | 9 — 6 participants |
Back to article view | Back to comp.lang.java.programmer
get methods from source files Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-10-26 14:37 -0700
Re: get methods from source files Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-10-26 18:15 -0400
Re: get methods from source files Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-10-26 18:22 -0400
Re: get methods from source files Stanimir Stamenkov <s7an10@netscape.net> - 2016-10-30 12:44 +0200
Re: get methods from source files Roedy Green <inquiry@mindprod.com> - 2016-11-03 12:53 -0700
Re: get methods from source files Arne Vajhøj <arne@vajhoej.dk> - 2016-11-03 22:34 -0400
Re: get methods from source files Arne Vajhøj <arne@vajhoej.dk> - 2016-10-26 20:09 -0400
Re: get methods from source files Patrick Roemer <sangamon@netcologne.de> - 2016-10-27 13:10 +0200
Re: get methods from source files Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-10-30 02:35 -0700
| From | Philipp Kraus <philipp.kraus.flashpixx@gmail.com> |
|---|---|
| Date | 2016-10-26 14:37 -0700 |
| Subject | get methods from source files |
| Message-ID | <c9464cd7-1a1c-4cce-abe1-607c90ff4e34@googlegroups.com> |
Hello,
did you know how I can get a method signatures from a full source tree. I want to extract only methods which are implement in classes and abstract classes and put them into a CSV file.
I have a full Maven project as input, so I would like to iterate over all *.java files within the src/main/java directory but I cannot instantiate each class and use reflection.
My first idea is to use th unix commands find and grep, but I don't know how I can determine the methods. An idea is to extract the line before {} and remove the class and the method bodies first.
But did you have an idea for the correct extract command or did you know a tool, which I can use?
Thanks
Phil
[toc] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2016-10-26 18:15 -0400 |
| Message-ID | <nur9t6$niq$1@dont-email.me> |
| In reply to | #35866 |
On 10/26/2016 5:37 PM, Philipp Kraus wrote:
> Hello,
>
> did you know how I can get a method signatures from a full source tree. I want to extract only methods which are implement in classes and abstract classes and put them into a CSV file.
> I have a full Maven project as input, so I would like to iterate over all *.java files within the src/main/java directory but I cannot instantiate each class and use reflection.
>
> My first idea is to use th unix commands find and grep, but I don't know how I can determine the methods. An idea is to extract the line before {} and remove the class and the method bodies first.
>
> But did you have an idea for the correct extract command or did you know a tool, which I can use?
I don't know of a ready-made tool (but my knowledge is incomplete).
However, one way to proceed might be to use the Javadoc tool: It can
already identify methods, constructors, and so on, and all you need to
do is get it to produce a different style of output. Output generation
is handled by "doclets," and there are alternatives to the one that
generates the familiar HTML, plus an API for further customization.
Absent a ready-made tool, I'd suggest using Javadoc with a custom
"back end."
http://www.oracle.com/technetwork/java/javase/documentation/index-jsp-135444.html
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2016-10-26 18:22 -0400 |
| Message-ID | <nuraaj$ois$1@dont-email.me> |
| In reply to | #35867 |
On 10/26/2016 6:15 PM, Eric Sosman wrote:
> On 10/26/2016 5:37 PM, Philipp Kraus wrote:
>> Hello,
>>
>> did you know how I can get a method signatures from a full source
>> tree. I want to extract only methods which are implement in classes
>> and abstract classes and put them into a CSV file.
>> I have a full Maven project as input, so I would like to iterate over
>> all *.java files within the src/main/java directory but I cannot
>> instantiate each class and use reflection.
>>
>> My first idea is to use th unix commands find and grep, but I don't
>> know how I can determine the methods. An idea is to extract the line
>> before {} and remove the class and the method bodies first.
>>
>> But did you have an idea for the correct extract command or did you
>> know a tool, which I can use?
>
> I don't know of a ready-made tool (but my knowledge is incomplete).
> However, one way to proceed might be to use the Javadoc tool: It can
> already identify methods, constructors, and so on, and all you need to
> do is get it to produce a different style of output. Output generation
> is handled by "doclets," and there are alternatives to the one that
> generates the familiar HTML, plus an API for further customization.
> Absent a ready-made tool, I'd suggest using Javadoc with a custom
> "back end."
>
> http://www.oracle.com/technetwork/java/javase/documentation/index-jsp-135444.html
Another idea: You could compile all the sources, load each class
file in turn, and use reflection on the Class objects.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Stanimir Stamenkov <s7an10@netscape.net> |
|---|---|
| Date | 2016-10-30 12:44 +0200 |
| Message-ID | <nv4iuh$aeq$1@dont-email.me> |
| In reply to | #35868 |
Wed, 26 Oct 2016 18:22:33 -0400, Eric Sosman: > On 10/26/2016 6:15 PM, Eric Sosman wrote: >> On 10/26/2016 5:37 PM, Philipp Kraus wrote: >> >>> did you know how I can get a method signatures from a full >>> source tree... but I cannot instantiate each class and use >>> reflection. >> >> I don't know of a ready-made tool (but my knowledge is >> incomplete). However, one way to proceed might be to use the >> Javadoc tool: It can already identify methods, constructors, and >> so on, and all you need to do is get it to produce a different >> style of output. Output generation is handled by "doclets,"... > > Another idea: You could compile all the sources, load each > class file in turn, and use reflection on the Class objects. For preprocessing purposes I would probably go with Javadoc and Doclets, but once upon a time I've used a library like BCEL to analyze classes in similar way (looking for declared method signatures) in a run-time, without loading/initializing the target classes: https://commons.apache.org/proper/commons-bcel/ I'm not 100% sure this was the actual library I used as it was not an Apache project back then. As far as I remember it required basic knowledge of the class file structure, also. -- Stanimir
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <inquiry@mindprod.com> |
|---|---|
| Date | 2016-11-03 12:53 -0700 |
| Message-ID | <md5n1ctbma1bekksq3g0am3l4mi1p13vn5@4ax.com> |
| In reply to | #35867 |
>> did you know how I can get a method signatures from a full source tree.
I want to extract only methods which are implement in classes and
abstract classes and put them into a CSV file.
>> I have a full Maven project as input, so I would like to iterate over
all *.java files within the src/main/java directory but I cannot
instantiate each class and use reflection.
This is one of my peeves about the grammar of Java. I want a keyword
at the start and end of each method so you can extract methods with
primitive text tools, and by eye. I also want it so the compiler does
not get so befuddled at a missing or extra { or }.
I would also like a keyword to indentify variable declarations so you
can use a simple text scan to review them.
If you have only a small amount of code to process, you can manually
insert magic comments at the begin/end of each method you can easily
scan for.
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2016-11-03 22:34 -0400 |
| Message-ID | <nvgs37$12cq$1@gioia.aioe.org> |
| In reply to | #35884 |
On 11/3/2016 3:53 PM, Roedy Green wrote:
>>> did you know how I can get a method signatures from a full source tree.
> I want to extract only methods which are implement in classes and
> abstract classes and put them into a CSV file.
>>> I have a full Maven project as input, so I would like to iterate over
> all *.java files within the src/main/java directory but I cannot
> instantiate each class and use reflection.
>
> This is one of my peeves about the grammar of Java. I want a keyword
> at the start and end of each method so you can extract methods with
> primitive text tools, and by eye. I also want it so the compiler does
> not get so befuddled at a missing or extra { or }.
>
> I would also like a keyword to indentify variable declarations so you
> can use a simple text scan to review them.
>
> If you have only a small amount of code to process, you can manually
> insert magic comments at the begin/end of each method you can easily
> scan for.
Handling out commented code and code outputting code correctly
is not trivial. Not even with clear markers.
Arne
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2016-10-26 20:09 -0400 |
| Message-ID | <nurgkd$186j$1@gioia.aioe.org> |
| In reply to | #35866 |
On 10/26/2016 5:37 PM, Philipp Kraus wrote:
> did you know how I can get a method signatures from a full source
> tree. I want to extract only methods which are implement in classes
> and abstract classes and put them into a CSV file. I have a full
> Maven project as input, so I would like to iterate over all *.java
> files within the src/main/java directory but I cannot instantiate
> each class and use reflection.
>
> My first idea is to use th unix commands find and grep, but I don't
> know how I can determine the methods. An idea is to extract the line
> before {} and remove the class and the method bodies first.
>
> But did you have an idea for the correct extract command or did you
> know a tool, which I can use?
I think this would be very difficult to do correctly using
text match like regex.
Consider issues like out commented methods, Java code outputting
Java code etc..
I think the only safe approach is to find a parser generator that
code with a valid but empty Java grammar and then add the necessary
code when it encounters methods.
Arne
[toc] | [prev] | [next] | [standalone]
| From | Patrick Roemer <sangamon@netcologne.de> |
|---|---|
| Date | 2016-10-27 13:10 +0200 |
| Message-ID | <nusnaq$m59$1@newsreader4.netcologne.de> |
| In reply to | #35866 |
Responding to Philipp Kraus: > did you know how I can get a method signatures from a full source tree. I have used the predecessor of this library some time ago and it worked fine for me: http://javaparser.org/ Best regards, Patrick
[toc] | [prev] | [next] | [standalone]
| From | Philipp Kraus <philipp.kraus.flashpixx@gmail.com> |
|---|---|
| Date | 2016-10-30 02:35 -0700 |
| Message-ID | <dd47b3ef-d90a-47cb-be6d-fa12cc2b21bb@googlegroups.com> |
| In reply to | #35871 |
Am Donnerstag, 27. Oktober 2016 13:10:34 UTC+2 schrieb Patrick Roemer: > Responding to Philipp Kraus: > > did you know how I can get a method signatures from a full source tree. > > I have used the predecessor of this library some time ago and it worked > fine for me: > > http://javaparser.org/ > > Best regards, > Patrick Thanks @All, but the JavaParser which I'm using in another project was the easiest way to do this Phil
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web