| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
package org.jphp.mysuperext;
import static php.runtime.annotation.Reflection.*;
import php.runtime.env.Environment;
import php.runtime.lang.BaseObject;
import php.runtime.reflection.ClassEntity;
@Name("Some\\NamespaceName\\ClassName")
public class Olala extends BaseObject {
public Olala(Environment env) {
super(env);
}
public Olala(Environment env, ClassEntity clazz) {
super(env, clazz);
}
}This class will be converted to:
<?php
namespace Some\NamespaceName;
class ClassName
{
}You can add more class-annotations for customize your result:
...
import php.runtime.reflection.ClassEntity;
@Abstract // if you want abstract class
@Final // if you want final class
@Name("Some\\NamespaceName\\ClassName")
public class Olala extends BaseObject {
public Olala(Environment env) {
...You can not write @Abstract or @Final. Add final keyword inside your class for creating final class or abstract keyword for creating abstract class. Without target annotations.
...
@Signature
public Memory __construct(Environment env, Memory... args) {
// do something
return Memory.NULL;
}
...Note: Each method should return Memory object. See: https://github.com/jphp-compiler/jphp/wiki/For-Contributors for more info about Memory objects.
This is __construct method. It will look like this:
<?php
namespace Some\NamespaceName;
class ClassName
{
public function __construct()
{
}
}Then we can customize own method:
...
@Signature({
@Arg(value = "fieldOne"),
@Arg(value = "fieldTwo"),
})
public Memory __construct(Environment env, Memory... args) {
// do something
return Memory.NULL;
}
...<?php
namespace Some\NamespaceName;
class ClassName
{
public function __construct($fieldOne, $fieldTwo)
{
}
}@Arg anotation have target options:
Note: For create a static method add static keyword inside java method declaration
Java code:
...
@Property
public String value = 23;
...Will be convert to:
...
public $value = 23;
...You can create getters and setters:
private String field = "fieldValue";
@Getter("fieldName")
public Memory getFieldName(Environment env, Memory... args) {
return StringMemory.valueOf(this.field);
}
@Setter("fieldName")
public Memory setFieldName(Environment env, Memory... args) {
this.field = StringMemory.valueOf(args[0].toString() + "abc");
return Memory.NULL;
}Will be convert to:
...
public $fieldName;
// will return "fieldValue" when taking value of this field
// and add "abc" at end when sets a new value
... ...
final public static String MY_CONSTANT_1 = "deadbeef";
final public static int MY_CONSTANT_2 = 42;
...<?php
namespace Some\NamespaceName;
class ClassName
{
const MY_CONSTANT_1 = "deadbeef";
const MY_CONSTANT_2 = 42;
}JPHP Group 2015
| Back | FazBrowse Home | New Git URL |