Abstract and protected compiler metadata for Java and PHP

27 views
Skip to first unread message

Hitmark7

unread,
Mar 4, 2016, 4:49:54 AM3/4/16
to Haxe
Hi.

I'm reading the Built-in Compiler Metadata section in order to learn more about them, but I've found two metas that don't work, or I don't understand very well.

First, @:protected . It should define the tagged method as protected, for all targets that supports, it, I supose. It work for Java, but not for PHP. Bug?

Second, the @:abstract one. This is tricky. On Java and PHP a class may be defined as abstract, becoming impossible to instantiate. This meaning is very different to the Haxe abstract keyword meaning, and I think it confuses many people. What does this meta tag do? I thought at first that it will define the class as abstract on the Java source file, but It doesn't. PHP also support abstracts, and this kind of meta would be useful for that target too. I am messing the Haxe and Java/PHP meanings, or there is a bug here too?

Some little code to quick testing:

Haxe:


@:abstract
class Foo {

   
public function new():Void {}

   
@:protected
   
private function bar():Void {
        trace
("I should be protected.");
   
}

}

class Main {

   
static public function main():Void {
       
var foo:Foo = new Foo();
//         foo.bar();
   
}

}


Compiles into this PHP source code for the Foo class:

<?php

class Foo {
   
public function __construct() {}
   
public function bar() { if(!php_Boot::$skip_constructor) {
        haxe_Log
::trace("I should be protected.", _hx_anonymous(array("fileName" => "Main.hx", "lineNumber" => 9, "className" => "Foo", "methodName" => "bar")));
   
}}
   
function __toString() { return 'Foo'; }
}


And into this Java source code for the Foo class:

package haxe.root;

import haxe.root.*;

@SuppressWarnings(value={"rawtypes", "unchecked"})
public class Foo extends haxe.lang.HxObject
{
   
public Foo(haxe.lang.EmptyObject empty)
   
{
   
}
   
   
   
public Foo()
   
{
        haxe
.root.Foo.__hx_ctor__Foo(this);
   
}
   
   
   
public static void __hx_ctor__Foo(haxe.root.Foo __temp_me3)
   
{
   
}
   
   
   
public static java.lang.Object __hx_createEmpty()
   
{
       
return new haxe.root.Foo(haxe.lang.EmptyObject.EMPTY);
   
}
   
   
   
public static java.lang.Object __hx_create(haxe.root.Array arr)
   
{
       
return new haxe.root.Foo();
   
}
   
   
   
protected void bar()
   
{
        haxe
.Log.trace.__hx_invoke2_o(0.0, "I should be protected.", 0.0, new haxe.lang.DynamicObject(new java.lang.String[]{"className", "fileName", "methodName"}, new java.lang.Object[]{"Foo", "Main.hx", "bar"}, new java.lang.String[]{"lineNumber"}, new double[]{((double) (((double) (9) )) )}));
   
}
   
   
   
@Override public java.lang.Object __hx_getField(java.lang.String field, boolean throwErrors, boolean isCheck, boolean handleProperties)
   
{
       
{
           
boolean __temp_executeDef1 = true;
           
switch (field.hashCode())
           
{
               
case 97299:
               
{
                   
if (field.equals("bar"))
                   
{
                        __temp_executeDef1
= false;
                       
return ((haxe.lang.Function) (new haxe.lang.Closure(this, "bar")) );
                   
}
                   
                   
break;
               
}
               
               
           
}
           
           
if (__temp_executeDef1)
           
{
               
return super.__hx_getField(field, throwErrors, isCheck, handleProperties);
           
}
           
else
           
{
               
throw null;
           
}
           
       
}
       
   
}
   
   
   
@Override public java.lang.Object __hx_invokeField(java.lang.String field, haxe.root.Array dynargs)
   
{
       
{
           
boolean __temp_executeDef1 = true;
           
switch (field.hashCode())
           
{
               
case 97299:
               
{
                   
if (field.equals("bar"))
                   
{
                        __temp_executeDef1
= false;
                       
this.bar();
                   
}
                   
                   
break;
               
}
               
               
           
}
           
           
if (__temp_executeDef1)
           
{
               
return super.__hx_invokeField(field, dynargs);
           
}
           
       
}
       
       
return null;
   
}
   
   
}



Note the correctly protected "bar" method on Java.

I'm using the Haxe Compiler v3.2.1 on a Linux x64.

Thanks.
Reply all
Reply to author
Forward
0 new messages