Search in sources :

Example 6 with ABSString

use of org.abs_models.backend.java.lib.types.ABSString in project abstools by abstools.

the class Clazz method setupMetaAPI.

/*
     * Define the methods of this class
     */
public static void setupMetaAPI() {
    thisClass.setName("Class");
    thisClass.addMethod(/*ABSString*/
    "getName", new ABSClosure() {

        @Override
        public ABSString exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicClass cls = (ABSDynamicClass) t.getFieldValue_Internal("class");
            return ABSString.fromString(cls.getName());
        }
    });
    thisClass.addMethod(/*ABSClosure*/
    "getMethod", new ABSClosure() {

        @Override
        public ABSDynamicObject exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicClass cls = (ABSDynamicClass) t.getFieldValue_Internal("class");
            ABSString name = (ABSString) params[0];
            ABSClosure method = cls.getMethod(name.getString());
            return method;
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "addMethod", new ABSClosure() {

        @Override
        public ABSUnit exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicClass cls = (ABSDynamicClass) t.getFieldValue_Internal("class");
            ABSString name = (ABSString) params[0];
            ABSClosure method = (ABSClosure) ((ABSDynamicObject) params[1]).getFieldValue_Internal("method");
            cls.addMethod(name.getString(), method);
            return ABSUnit.UNIT;
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "removeMethod", new ABSClosure() {

        @Override
        public ABSUnit exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicClass cls = (ABSDynamicClass) t.getFieldValue_Internal("class");
            ABSString name = (ABSString) params[0];
            cls.removeMethod(name.getString());
            return ABSUnit.UNIT;
        }
    });
}
Also used : ABSDynamicObject(org.abs_models.backend.java.lib.runtime.ABSDynamicObject) ABSClosure(org.abs_models.backend.java.lib.runtime.ABSClosure) ABSUnit(org.abs_models.backend.java.lib.types.ABSUnit) ABSValue(org.abs_models.backend.java.lib.types.ABSValue) ABSString(org.abs_models.backend.java.lib.types.ABSString) ABSDynamicClass(org.abs_models.backend.java.lib.runtime.ABSDynamicClass)

Example 7 with ABSString

use of org.abs_models.backend.java.lib.types.ABSString in project abstools by abstools.

the class Delta method setupMetaAPI.

/*
     * Define the methods of this class
     */
public static void setupMetaAPI() {
    thisClass.setName("Delta");
    thisClass.addMethod(/*ABSString*/
    "getName", new ABSClosure() {

        @Override
        public ABSString exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicDelta delta = (ABSDynamicDelta) t;
            return ABSString.fromString(delta.getName());
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "apply", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicDelta delta = (ABSDynamicDelta) t;
            delta.apply();
            return ABSUnit.UNIT;
        }
    });
}
Also used : ABSDynamicObject(org.abs_models.backend.java.lib.runtime.ABSDynamicObject) ABSClosure(org.abs_models.backend.java.lib.runtime.ABSClosure) ABSDynamicDelta(org.abs_models.backend.java.lib.runtime.ABSDynamicDelta) ABSValue(org.abs_models.backend.java.lib.types.ABSValue) ABSString(org.abs_models.backend.java.lib.types.ABSString)

Example 8 with ABSString

use of org.abs_models.backend.java.lib.types.ABSString in project abstools by abstools.

the class ObjectMirror method setupAPI.

public static void setupAPI() {
    thisClass.setName("ObjectMirror");
    /*
         * getClassName: get name of object's class
         */
    thisClass.addMethod(/*ABSString*/
    "getClassName", new ABSClosure() {

        @Override
        public ABSString exec(ABSDynamicObject t, ABSValue... params) {
            ABSString name;
            name = ABSString.fromString(((ABSDynamicObject) t.dispatch("getObject")).getClassName());
            return name;
        }
    });
    /*
         * getClass: get class of object
         */
    thisClass.addMethod(/*ABSDynamicObject<Clazz>*/
    "getClass", new ABSClosure() {

        @Override
        public ABSDynamicObject exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicClass cls = ((ABSDynamicObject) t.dispatch("getObject")).getClazz();
            ABSDynamicObject o = new ABSDynamicObject(Clazz.singleton());
            o.setFieldValue("class", cls);
            return o;
        }
    });
    /*
         * setClass: set new class for object
         */
    thisClass.addMethod(/*Unit*/
    "setClass", new ABSClosure() {

        @Override
        public ABSUnit exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicClass cls = (ABSDynamicClass) ((ABSDynamicObject) params[0]).getFieldValue_Internal("class");
            ((ABSDynamicObject) t.dispatch("getObject")).setClazz(cls);
            return ABSUnit.UNIT;
        }
    });
    /*
         * respondsTo: find out whether object responds to given method
         */
    thisClass.addMethod(/*ABSBool*/
    "respondsTo", new ABSClosure() {

        @Override
        public ABSBool exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicClass cls = (ABSDynamicClass) ((ABSDynamicObject) t.dispatch("getObject")).getClazz();
            return ABSBool.fromBoolean(cls.hasMethod(((ABSString) params[0]).getString()));
        }
    });
    // TODO: getFieldValue(), setFieldValue()
    thisClass.addMethod(/*ABSDynamicObject<COG>*/
    "getCog", new ABSClosure() {

        @Override
        public ABSDynamicObject exec(ABSDynamicObject t, ABSValue... params) {
            COG cog = ((ABSDynamicObject) t.dispatch("getObject")).getCOG();
            ABSDynamicObject o = new ABSDynamicObject(Cog.singleton());
            o.setFieldValue("cog", cog);
            return o;
        }
    });
    thisClass.addMethod(/*Unit*/
    "setCog", new ABSClosure() {

        @Override
        public ABSUnit exec(ABSDynamicObject t, ABSValue... params) {
            ((ABSDynamicObject) t.dispatch("getObject")).setCOG((COG) params[0]);
            return ABSUnit.UNIT;
        }
    });
    /*
         * getObject: obtain the mirrored object
         */
    thisClass.addMethod(/*ABSDynamicObject*/
    "getObject", new ABSClosure() {

        @Override
        public ABSDynamicObject exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicObject object;
            object = (ABSDynamicObject) t.getFieldValue_Internal("object");
            return object;
        }
    });
}
Also used : ABSDynamicObject(org.abs_models.backend.java.lib.runtime.ABSDynamicObject) ABSClosure(org.abs_models.backend.java.lib.runtime.ABSClosure) ABSUnit(org.abs_models.backend.java.lib.types.ABSUnit) ABSBool(org.abs_models.backend.java.lib.types.ABSBool) COG(org.abs_models.backend.java.lib.runtime.COG) ABSValue(org.abs_models.backend.java.lib.types.ABSValue) ABSString(org.abs_models.backend.java.lib.types.ABSString) ABSDynamicClass(org.abs_models.backend.java.lib.runtime.ABSDynamicClass)

Example 9 with ABSString

use of org.abs_models.backend.java.lib.types.ABSString in project abstools by abstools.

the class ProductLine method setupAPI.

private static void setupAPI() {
    thisClass.setName("ProductLine");
    /* 
         * MetaABS ProductLine API -- cf. abslang.abs module ABS.Meta 
         */
    thisClass.addMethod(/*ABSDynamicProduct*/
    "getCurrentProduct", new ABSClosure() {

        @Override
        public ABSDynamicProduct exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicProduct currentProd = t.__ABS_getRuntime().getDSPL().getCurrentProduct();
            return currentProd;
        }
    });
    thisClass.addMethod(/*ABSDynamicProduct*/
    "getProduct", new ABSClosure() {

        @Override
        public ABSDynamicProduct exec(ABSDynamicObject t, ABSValue... params) {
            ABSString name = (ABSString) params[0];
            ABSDynamicProduct product = t.__ABS_getRuntime().getDSPL().getProduct(name.getString());
            return product;
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "reconfigure", new ABSClosure() {

        @Override
        public ABSUnit exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicProduct targetProd = (ABSDynamicProduct) params[0];
            ABSDynamicProductLine pl = t.__ABS_getRuntime().getDSPL();
            pl.reconfigure(targetProd);
            return ABSUnit.UNIT;
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "addProduct", new ABSClosure() {

        @Override
        public ABSUnit exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicProduct product = (ABSDynamicProduct) params[0];
            t.__ABS_getRuntime().getDSPL().addProduct(product);
            return ABSUnit.UNIT;
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "removeProduct", new ABSClosure() {

        @Override
        public ABSUnit exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicProduct product = (ABSDynamicProduct) params[0];
            t.__ABS_getRuntime().getDSPL().removeProduct(product);
            return ABSUnit.UNIT;
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "addReconfiguration", new ABSClosure() {

        @Override
        public ABSUnit exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration recf = (ABSDynamicReconfiguration) params[0];
            t.__ABS_getRuntime().getDSPL().addReconfiguration(recf);
            return ABSUnit.UNIT;
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "removeReconfiguration", new ABSClosure() {

        @Override
        public ABSUnit exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration recf = (ABSDynamicReconfiguration) params[0];
            t.__ABS_getRuntime().getDSPL().removeReconfiguration(recf);
            return ABSUnit.UNIT;
        }
    });
}
Also used : ABSDynamicObject(org.abs_models.backend.java.lib.runtime.ABSDynamicObject) ABSClosure(org.abs_models.backend.java.lib.runtime.ABSClosure) ABSDynamicProductLine(org.abs_models.backend.java.lib.runtime.ABSDynamicProductLine) ABSDynamicProduct(org.abs_models.backend.java.lib.runtime.ABSDynamicProduct) ABSUnit(org.abs_models.backend.java.lib.types.ABSUnit) ABSValue(org.abs_models.backend.java.lib.types.ABSValue) ABSString(org.abs_models.backend.java.lib.types.ABSString) ABSDynamicReconfiguration(org.abs_models.backend.java.lib.runtime.ABSDynamicReconfiguration)

Example 10 with ABSString

use of org.abs_models.backend.java.lib.types.ABSString in project abstools by abstools.

the class TestSystemObserver method objectInitialized.

@Override
public void objectInitialized(ObjectView o) {
    if (o.getClassName().equals("FieldClass")) {
        try {
            ABSString s = (ABSString) o.getFieldValue("field");
            System.out.println("FIELD VALUE=" + s.getString());
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }
}
Also used : ABSString(org.abs_models.backend.java.lib.types.ABSString)

Aggregations

ABSString (org.abs_models.backend.java.lib.types.ABSString)10 ABSClosure (org.abs_models.backend.java.lib.runtime.ABSClosure)8 ABSDynamicObject (org.abs_models.backend.java.lib.runtime.ABSDynamicObject)8 ABSValue (org.abs_models.backend.java.lib.types.ABSValue)8 ABSUnit (org.abs_models.backend.java.lib.types.ABSUnit)4 ABSDynamicProduct (org.abs_models.backend.java.lib.runtime.ABSDynamicProduct)3 ABSDynamicReconfiguration (org.abs_models.backend.java.lib.runtime.ABSDynamicReconfiguration)3 ABSDynamicClass (org.abs_models.backend.java.lib.runtime.ABSDynamicClass)2 ABSDynamicFeature (org.abs_models.backend.java.lib.runtime.ABSDynamicFeature)2 ABSDynamicUpdate (org.abs_models.backend.java.lib.runtime.ABSDynamicUpdate)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Scanner (java.util.Scanner)1 ABSDynamicDelta (org.abs_models.backend.java.lib.runtime.ABSDynamicDelta)1 ABSDynamicProductLine (org.abs_models.backend.java.lib.runtime.ABSDynamicProductLine)1 COG (org.abs_models.backend.java.lib.runtime.COG)1 ABSBool (org.abs_models.backend.java.lib.types.ABSBool)1