| 1 | package Java; | ||
| 2 | |||
| 3 | sub inline { | ||
| 4 | # this is a placeholder, | ||
| 5 | # the "real" Java::inline is a macro defined at Perlito5/Java/Apply.pm | ||
| 6 | } | ||
| 7 | |||
| 8 | sub type ($$) { | ||
| 9 | # from Nashorn: var HashMap = Java.type("java.util.HashMap") | ||
| 10 | my ( $class, $type ) = @_; | ||
| 11 | my $array = ""; | ||
| 12 | while ( index($type, "<") != -1 ) { | ||
| 13 | # class instances always represent raw types; remove a type argument if present | ||
| 14 | $type =~ s/<[^<>]*>//; | ||
| 15 | } | ||
| 16 | while ( substr( $type, -2, 2 ) eq "[]" ) { | ||
| 17 | # int[][] => [[I | ||
| 18 | # Object[] => [Ljava.lang.Object; | ||
| 19 | $type = substr( $type, 0, -2 ); | ||
| 20 | $array .= "["; | ||
| 21 | } | ||
| 22 | if ( $type eq "boolean" ) { $type = $array . "Z"; } | ||
| 23 | elsif ( $type eq "byte" ) { $type = $array . "B"; } | ||
| 24 | elsif ( $type eq "char" ) { $type = $array . "C"; } | ||
| 25 | elsif ( $type eq "double" ) { $type = $array . "D"; } | ||
| 26 | elsif ( $type eq "float" ) { $type = $array . "F"; } | ||
| 27 | elsif ( $type eq "int" ) { $type = $array . "I"; } | ||
| 28 | elsif ( $type eq "long" ) { $type = $array . "J"; } | ||
| 29 | elsif ( $type eq "short" ) { $type = $array . "S"; } | ||
| 30 | elsif ( $array ) { $type = $array . "L" . $type . ";" } | ||
| 31 | _type($type); | ||
| 32 | } | ||
| 33 | |||
| 34 | sub _type ($) { | ||
| 35 | my $class; | ||
| 36 | eval { | ||
| 37 | $class = Java::inline q{ | ||
| 38 | Class.forName( List__.aget(0).toString() ) | ||
| 39 | } | ||
| 40 | }; | ||
| 41 | return $class; | ||
| 42 | } | ||
| 43 | |||
| 44 | 1; | ||
| 45 |