This repository has been archived by the owner on Jun 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add class loading for Jar files and API for arrays
- Loading branch information
Showing
8 changed files
with
146 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: java-reflection-ext | ||
version: 1.1.1 | ||
version: 1.2.0 | ||
description: Java Reflection API | ||
|
||
plugins: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
|
||
namespace java\reflection; | ||
|
||
|
||
use php\io\File; | ||
|
||
class JarClassLoader | ||
{ | ||
/** | ||
* @param File $jarFile | ||
*/ | ||
public function __construct(File $jarFile) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
|
||
namespace java\reflection; | ||
|
||
|
||
class ReflectionArray | ||
{ | ||
/** | ||
* @param ReflectionClass $class | ||
* @param int $length | ||
* @return ReflectionObject | ||
*/ | ||
public static function newInstance(ReflectionClass $class, int $length): ReflectionObject {} | ||
|
||
/** | ||
* @param ReflectionObject $object | ||
* @return int | ||
*/ | ||
public static function getLength(ReflectionObject $object): int {} | ||
|
||
/** | ||
* @param ReflectionObject $object | ||
* @param int $id | ||
* @return ReflectionObject | ||
*/ | ||
public static function get(ReflectionObject $object, int $id): ReflectionObject {} | ||
|
||
/** | ||
* @param ReflectionObject $object | ||
* @param int $id | ||
* @param ReflectionObject $data | ||
*/ | ||
public static function set(ReflectionObject $object, int $id, ReflectionObject $data) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src-jvm/main/java/org/venity/javareflection/classes/JarClassLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.venity.javareflection.classes; | ||
|
||
import org.venity.javareflection.JavaReflectionExtension; | ||
import php.runtime.annotation.Reflection; | ||
import php.runtime.env.Environment; | ||
import php.runtime.lang.BaseObject; | ||
import php.runtime.reflection.ClassEntity; | ||
|
||
import java.io.File; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
|
||
@Reflection.Name("JarClassLoader") | ||
@Reflection.Namespace(JavaReflectionExtension.NS) | ||
public class JarClassLoader extends BaseObject { | ||
|
||
public JarClassLoader(Environment env) { | ||
super(env); | ||
} | ||
|
||
protected JarClassLoader(ClassEntity entity) { | ||
super(entity); | ||
} | ||
|
||
public JarClassLoader(Environment env, ClassEntity clazz) { | ||
super(env, clazz); | ||
} | ||
|
||
private URLClassLoader classLoader; | ||
|
||
@Reflection.Signature | ||
public void __construct(File jar) throws MalformedURLException { | ||
classLoader = new URLClassLoader( | ||
new URL[] {jar.toURI().toURL()}, | ||
this.getClass().getClassLoader() | ||
); | ||
} | ||
|
||
public URLClassLoader getClassLoader() { | ||
return classLoader; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src-jvm/main/java/org/venity/javareflection/classes/ReflectionArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.venity.javareflection.classes; | ||
|
||
import org.venity.javareflection.JavaReflectionExtension; | ||
import php.runtime.annotation.Reflection; | ||
import php.runtime.env.Environment; | ||
import php.runtime.lang.BaseWrapper; | ||
import php.runtime.reflection.ClassEntity; | ||
|
||
import java.lang.reflect.Array; | ||
|
||
@Reflection.Name("ReflectionArray") | ||
@Reflection.Namespace(JavaReflectionExtension.NS) | ||
public class ReflectionArray extends BaseWrapper<Array> { | ||
public ReflectionArray(Environment env, Array wrappedObject) { | ||
super(env, wrappedObject); | ||
} | ||
|
||
public ReflectionArray(Environment env, ClassEntity clazz) { | ||
super(env, clazz); | ||
} | ||
|
||
@Reflection.Signature | ||
public static ReflectionObject newInstance(Environment environment, Class<?> componentType, int length) { | ||
return new ReflectionObject(environment, Array.newInstance(componentType, length)); | ||
} | ||
|
||
@Reflection.Signature | ||
public static int getLength(ReflectionObject object) { | ||
return Array.getLength(object.getWrappedObject()); | ||
} | ||
|
||
@Reflection.Signature | ||
public static ReflectionObject get(Environment environment, ReflectionObject object, int id) { | ||
return new ReflectionObject(environment, Array.get(object.getWrappedObject(), id)); | ||
} | ||
|
||
@Reflection.Signature | ||
public static void set(Environment environment, ReflectionObject object, int id, ReflectionObject reflectionObject) { | ||
Array.set(object.getWrappedObject(), id, reflectionObject.getWrappedObject()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters