PDA

View Full Version : [solved] Import static inner java class


si.ruslan
01-31-2011, 12:41 PM
Hi,

How can import static inner java class. For example java.awt.geom.Path2D.Double?

code

<?php import java.awt.geom.Path2D.Double; $d = new Double() ?>

not works

Thanks

domdorn
02-02-2011, 11:31 AM
I'll check with the team. Not sure if its possible.

si.ruslan
02-02-2011, 11:48 AM
Ok, thanks.

On Rhino Engine it's possible as


...
var count = Math.min(shape.latitude.length, shape.longitude.length);
var polygon = new java.awt.geom.Path2D.Double();
polygon.moveTo(shape.latitude[0], shape.longitude[0]);
for (var z = 1; z < count; z++) {
polygon.lineTo(shape.latitude[z], shape.longitude[z]);
}
polygon.closePath();
...


I can't reproduce the same code on Quercus :(

domdorn
02-02-2011, 06:18 PM
do it like this



$d = new java("java.awt.geom.Path2D\$Double");

si.ruslan
02-03-2011, 10:59 PM
Thanks, it's works.
But, this solution is not obvious...
I has made review of source code and found more elegant solution.
for working import as

import java.awt.geom.Path2D.Double;
$d = new Double();

need patch for com.caucho.quercus.env.Env.java
version of source code 4.0.11

add to line 4531


int ind;
if (def == null && (ind = className.lastIndexOf(".")) > -1){
def = getJavaClassDefinition(className.substring(0, ind) +
"$" + className.substring(ind+1), false);
}


after this patch import as java.awt.geom.Path2D.Double will works fine.

Also, I have other solutions, more flexible. For example

import java.awt.geom.Path2D;
$d = new Path2D.Double();

and very simple - without special "import" keyword (like as Rhino)

$d = new java.awt.geom.Path2D.Double();

but, two last solution required patching more files, such as QuercusParser.java and other class for code generation.

All solutions were tested by me.

si.ruslan
02-07-2011, 10:09 PM
1. What thinks Quercus team about proposed patch?
2. How I can commit changes into main SVN of Quercus project?