line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Java::Javap; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
382642
|
use strict; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
258
|
|
4
|
7
|
|
|
7
|
|
38
|
use warnings; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
200
|
|
5
|
7
|
|
|
7
|
|
33
|
use Carp; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
684
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
8
|
|
|
|
|
|
|
our $JAVAP_EXECUTABLE = 'javap'; |
9
|
|
|
|
|
|
|
|
10
|
7
|
|
|
7
|
|
3101
|
use Java::Javap::TypeCast; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
3623
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub get_referenced_typenames { |
13
|
0
|
|
|
0
|
0
|
0
|
shift; # invoked through this class, discard our name |
14
|
0
|
|
|
|
|
0
|
my $tree = shift; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
0
|
my %answers; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
0
|
for my $type_name ( $tree->{ parent }, @{ $tree->{implements} } ) { |
|
0
|
|
|
|
|
0
|
|
19
|
0
|
0
|
|
|
|
0
|
$answers{ $type_name }++ if $type_name; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
0
|
foreach my $element ( @{ $tree->{contents} } ) { |
|
0
|
|
|
|
|
0
|
|
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
0
|
$answers{ $element->{type}->{name} }++ if $element->{type}; |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
0
|
if (my $args = $element->{args}) { |
27
|
0
|
|
|
|
|
0
|
$answers{ $_->{name} }++ for @$args; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# remove own class |
32
|
0
|
|
|
|
|
0
|
delete $answers{ $tree->{java_qualified_name} }; |
33
|
0
|
|
|
|
|
0
|
delete $answers{void}; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
return keys %answers; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get_included_types { # XXX change name |
39
|
0
|
|
|
0
|
1
|
0
|
my ($class, $tree, $caster) = @_; |
40
|
0
|
|
|
|
|
0
|
my @types = $class->get_referenced_typenames($tree); |
41
|
0
|
|
|
|
|
0
|
return [ grep { not $caster->defined_cast($_) } @types ]; |
|
0
|
|
|
|
|
0
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub javap { |
46
|
6
|
|
|
6
|
1
|
18
|
my ($self, $classes, $options) = @_; |
47
|
6
|
|
50
|
|
|
48
|
$options ||= []; |
48
|
|
|
|
|
|
|
|
49
|
6
|
50
|
|
|
|
21
|
croak "No classes to be parsed" if not $classes; |
50
|
6
|
50
|
|
|
|
40
|
$classes = [ $classes ] if not ref $classes; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Open the real javap executable and read output from it |
53
|
6
|
|
|
|
|
26
|
my @cmd = ($JAVAP_EXECUTABLE, @$options, @$classes); |
54
|
|
|
|
|
|
|
|
55
|
6
|
50
|
|
|
|
30506
|
open(my $javap_fh, '-|', @cmd) |
56
|
|
|
|
|
|
|
or croak "@cmd failed: $!"; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
0
|
my $javap_output = q{}; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
local $_; |
61
|
0
|
|
|
|
|
0
|
while (<$javap_fh>) { |
62
|
0
|
|
|
|
|
0
|
$javap_output .= $_; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# When dealing with a pipe, we also want to get errors from close |
66
|
0
|
0
|
|
|
|
0
|
close $javap_fh |
67
|
|
|
|
|
|
|
or croak "@cmd failed on close: $!"; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
return $javap_output; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Shortcut for the test suite |
73
|
|
|
|
|
|
|
sub javap_test { |
74
|
6
|
|
|
6
|
0
|
78
|
my ($self) = @_; |
75
|
6
|
|
|
|
|
22
|
my $output; |
76
|
6
|
|
|
|
|
15
|
eval { $output = $self->javap(['java.lang.String']) }; |
|
6
|
|
|
|
|
40
|
|
77
|
6
|
50
|
|
|
|
2039
|
return $output ? 1 : 0; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 NAME |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Java::Javap - Java to Perl 6 API translator |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SYNOPSIS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
java2perl6api java.somepackage.Module |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
See C for instructions and advice on use of this module. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This particular module is only a place holder for the version number |
95
|
|
|
|
|
|
|
of this project (see below). |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 METHODS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 get_included_types |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Call this as a class method. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Parameters: an abstract syntax tree you got from calling comp_unit |
104
|
|
|
|
|
|
|
an a C object. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Returns: an array reference of the types in arguments to methods, or |
107
|
|
|
|
|
|
|
return values (thrown types are not reported). |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 javap |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Invokes the C process and return the output. |
112
|
|
|
|
|
|
|
Throws an exception if something goes wrong, like C is |
113
|
|
|
|
|
|
|
not found. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head3 Parameters |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=over |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item \@classes |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
List of classes to be decompiled. It can also be supplied as a string, |
122
|
|
|
|
|
|
|
if a single class should be decompiled. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item \@options |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Options to be passed to the C process. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=back |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head3 Example |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my @classes = ('java.lang.String'); |
133
|
|
|
|
|
|
|
my @options = (); |
134
|
|
|
|
|
|
|
my $output = Java::Javap->javap(\@classes, \@options); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# or ... |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $output = Java::Javap->javap('java.lang.String'); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 SEE ALSO |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item C |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item C |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item C |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item C |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=back |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 AUTHORS |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Philip Crow, Ecrow.phil@gmail.comE |
157
|
|
|
|
|
|
|
Cosimo Streppone, Ecosimo@cpan.orgE |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Copyright (C) 2007 by Philip Crow |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
164
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
165
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |