[libinline-java-perl] 82/398: *** empty log message ***
Jonas Smedegaard
dr at jones.dk
Thu Feb 26 11:42:51 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.55
in repository libinline-java-perl.
commit 0e1f0608cb60296f01691d546605375de73a0928
Author: patrick <>
Date: Wed May 9 19:37:06 2001 +0000
*** empty log message ***
---
Java/Object.pm | 13 +++++++++----
Java/Protocol.pm | 43 ++++++++++++++++++++++++++++++++++---------
MANIFEST | 3 +++
t/08_study.t | 37 +++++++++++++++++++++++++++++++++----
4 files changed, 79 insertions(+), 17 deletions(-)
diff --git a/Java/Object.pm b/Java/Object.pm
index efeb3ae..4eff993 100644
--- a/Java/Object.pm
+++ b/Java/Object.pm
@@ -37,6 +37,11 @@ sub __new {
my $knot = tie %this, $class ;
my $this = bless(\%this, $class) ;
+ my $pkg = $inline->{pkg} ;
+ if ($class ne "Inline::Java::Object"){
+ $class = Inline::Java::java2perl($pkg, $java_class) ;
+ }
+
my $priv = Inline::Java::Object::Private->new($class, $java_class, $inline) ;
$PRIVATES->{$knot} = $priv ;
@@ -162,7 +167,7 @@ sub __validate_prototype {
if ((! $chosen->{STATIC})&&(! ref($this))){
# We are trying to call an instance method without an object
# reference
- croak "Method $method of class $inline->{pkg}::$this must be called from an object reference" ;
+ croak "Method $method of class $this must be called from an object reference" ;
}
# Here we will be polite and warn the user if we had to choose a
@@ -224,7 +229,7 @@ sub __get_member {
Inline::Java::debug("fetching member variable $key") ;
my $inline = Inline::Java::get_INLINE($this->__get_private()->{module}) ;
- my $fields = $inline->get_fields($this->__get_private()->{java_class}) ;
+ my $fields = $inline->get_fields($this->__get_private()->{class}) ;
if ($fields->{$key}){
my $proto = $fields->{$key}->{TYPE} ;
@@ -251,7 +256,7 @@ sub __set_member {
}
my $inline = Inline::Java::get_INLINE($this->__get_private()->{module}) ;
- my $fields = $inline->get_fields($this->__get_private()->{java_class}) ;
+ my $fields = $inline->get_fields($this->__get_private()->{class}) ;
if ($fields->{$key}){
my $proto = $fields->{$key}->{TYPE} ;
@@ -373,7 +378,7 @@ sub EXISTS {
my $key = shift ;
my $inline = Inline::Java::get_INLINE($this->__get_private()->{module}) ;
- my $fields = $inline->get_fields($this->__get_private()->{java_class}) ;
+ my $fields = $inline->get_fields($this->__get_private()->{class}) ;
if ($fields->{$key}){
return 1 ;
diff --git a/Java/Protocol.pm b/Java/Protocol.pm
index bdd37a2..b7d2ff4 100644
--- a/Java/Protocol.pm
+++ b/Java/Protocol.pm
@@ -401,12 +401,23 @@ class InlineJavaProtocol {
Method methods[] = c.getMethods() ;
Field fields[] = c.getFields() ;
+ int pub = c.getModifiers() & Modifier.PUBLIC ;
+ if (pub != 0){
+ // If the class is public and has no constructors,
+ // we provide a default no-arg constructors.
+ if (c.getDeclaredConstructors().length == 0){
+ String noarg_sign = CreateSignature(new Class [] {}) ;
+ pw.append("constructor " + noarg_sign + "\n") ;
+ }
+ }
for (int j = 0 ; j < constructors.length ; j++){
Constructor x = constructors[j] ;
- String sign = CreateSignature(x.getParameterTypes()) ;
+ Class params[] = x.getParameterTypes() ;
+ String sign = CreateSignature(params) ;
Class decl = x.getDeclaringClass() ;
- pw.append("constructor" + " " + sign + "\n") ;
+ pw.append("constructor " + sign + "\n") ;
}
+
for (int j = 0 ; j < methods.length ; j++){
Method x = methods[j] ;
String stat = (Modifier.isStatic(x.getModifiers()) ? " static " : " instance ") ;
@@ -414,6 +425,7 @@ class InlineJavaProtocol {
Class decl = x.getDeclaringClass() ;
pw.append("method" + stat + decl.getName() + " " + x.getName() + sign + "\n") ;
}
+
for (int j = 0 ; j < fields.length ; j++){
Field x = fields[j] ;
String stat = (Modifier.isStatic(x.getModifiers()) ? " static " : " instance ") ;
@@ -455,7 +467,6 @@ class InlineJavaProtocol {
if (! ijc.ClassIsArray(c)){
ArrayList f = ValidateMethod(true, c, class_name, st) ;
- Constructor con = (Constructor)f.get(0) ;
Object p[] = (Object [])f.get(1) ;
Class clist[] = (Class [])f.get(2) ;
@@ -665,8 +676,14 @@ class InlineJavaProtocol {
String name = p.getName() ;
Object ret = null ;
try {
- Constructor con = (Constructor)p.getConstructor(proto) ;
- ret = con.newInstance(args) ;
+ // This will allow usage of the default no-arg constructor
+ if (proto.length == 0){
+ ret = p.newInstance() ;
+ }
+ else{
+ Constructor con = (Constructor)p.getConstructor(proto) ;
+ ret = con.newInstance(args) ;
+ }
}
catch (NoSuchMethodException e){
throw new InlineJavaException("Constructor for class " + name + " with signature " + ijs.CreateSignature(proto) + " not found: " + e.getMessage()) ;
@@ -738,10 +755,18 @@ class InlineJavaProtocol {
// Now we got a list of matching methods.
// We have to figure out which one we will call.
if (ml.size() == 0){
- throw new InlineJavaException(
- (constructor ? "Constructor " : "Method ") +
- name + " for class " + c.getName() + " with signature " +
- signature + " not found") ;
+ // Nothing matched. Maybe we got a default constructor
+ if ((constructor)&&(signature.equals("()"))){
+ ret.add(0, null) ;
+ ret.add(1, new Object [] {}) ;
+ ret.add(2, new Class [] {}) ;
+ }
+ else{
+ throw new InlineJavaException(
+ (constructor ? "Constructor " : "Method ") +
+ name + " for class " + c.getName() + " with signature " +
+ signature + " not found") ;
+ }
}
else if (ml.size() == 1){
// Now we need to force the arguments received to match
diff --git a/MANIFEST b/MANIFEST
index 94fc5da..4c7e691 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -24,6 +24,9 @@ t/5_arrays.t
t/6_static.t
t/7_polymorph.t
t/8_study.t
+t/types.java
t/types.class
+t/no_const.java
+t/no_const.class
diff --git a/t/08_study.t b/t/08_study.t
index fac85bd..08a3ef9 100644
--- a/t/08_study.t
+++ b/t/08_study.t
@@ -1,11 +1,14 @@
+package study ;
+
use strict ;
use Test ;
+
use Inline Config =>
DIRECTORY => './_Inline_test';
use Inline(
- Java => 'STUDY',
+ Java => 'DATA',
AUTOSTUDY => 1,
) ;
use Inline::Java qw(study_classes) ;
@@ -13,13 +16,39 @@ use Inline::Java qw(study_classes) ;
BEGIN {
- plan(tests => 2) ;
+ plan(tests => 5) ;
}
-study_classes(['t.types']) ;
+study_classes([
+ 't.types',
+ 't.no_const'
+]) ;
-my $t = new t::types() ;
+my $t = new study::t::types() ;
ok($t->func(), "study") ;
ok($t->hm()->get("key"), "value") ;
+my $nc = new study::t::no_const() ;
+ok($nc->{i}, 5) ;
+
+my $a = new study::a() ;
+ok($a->{i}, 50) ;
+ok($a->truth()) ;
+
+
+__DATA__
+
+__Java__
+
+class a {
+ public int i = 50 ;
+
+ public a(){
+ }
+
+ public boolean truth(){
+ return true ;
+ }
+}
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libinline-java-perl.git
More information about the Pkg-perl-cvs-commits
mailing list