1 use strict; 2 use warnings; 3 4 use File::Spec; 5 use Java::JVM::Classfile; 6 7 use Test::More tests => 29; 8 9 sub class_name_to_java { 10 my ($name) = @_; 11 12 my $tmp = $name; 13 $tmp =~ s/ANTLR::Runtime/org.antlr.runtime/; 14 $tmp =~ s/::/./g; 15 16 return $tmp; 17 } 18 19 sub java_class_name_to_perl { 20 my ($name) = @_; 21 22 my $tmp = $name; 23 $tmp =~ s/org\.antlr\.runtime/ANTLR::Runtime/; 24 $tmp =~ s/\./::/g; 25 26 return $tmp; 27 } 28 29 sub resolve_java_class_file { 30 my ($name, $basedir) = @_; 31 32 my $tmp = $name; 33 $tmp =~ s!\.!/!g; 34 $tmp .= '.class'; 35 36 return File::Spec->catfile($basedir, $tmp); 37 } 38 39 sub java_constant_name_to_perl { 40 } 41 42 sub java_method_name_to_perl { 43 my ($name) = @_; 44 45 if ($name eq '<init>') { 46 return 'new'; 47 } 48 # add special cases here 49 else { 50 my $tmp = $name; 51 $tmp =~ s/([a-z])([A-Z])/$1_\L$2\E/g; 52 53 return $tmp; 54 } 55 } 56 57 my @java_class_names = qw( 58 org.antlr.runtime.BitSet 59 ); 60 61 foreach my $java_class_name (@java_class_names) { 62 my $java_class_file = resolve_java_class_file($java_class_name, 63 '../../build/rtclasses'); 64 65 my $java_class; 66 { 67 local $SIG{'__WARN__'} = sub {}; 68 $java_class = Java::JVM::Classfile->new($java_class_file); 69 } 70 71 my $class_name = java_class_name_to_perl($java_class_name); 72 use_ok($class_name); 73 print map { "$_\n" } ANTLR::Runtime::BitSet->can(); 74 print "---\n"; 75 76 eval { $class_name->new() }; 77 print join "\n", ANTLR::Runtime::BitSet->can(); 78 print "\n"; 79 80 my $java_fields = $java_class->fields; 81 foreach my $java_field (@$java_fields) { 82 next if grep { $_ eq 'private' } @{$java_field->access_flags}; 83 84 my $field_name = $java_field->name; 85 ok($class_name->can($field_name), $field_name); 86 } 87 88 my $java_methods = $java_class->methods; 89 foreach my $java_method (@$java_methods) { 90 next if grep { $_ eq 'private' } @{$java_method->access_flags}; 91 92 my $method_name = java_method_name_to_perl($java_method->name); 93 ok($class_name->can($method_name), $method_name); 94 } 95 } 96