Search in sources :

Example 6 with ABSValue

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

the class Product method setupMetaAPI.

/*
     * Define the methods of this class
     */
public static void setupMetaAPI() {
    thisClass.setName("Product");
    /*
         * MetaABS Product API -- cf. abslang.abs module ABS.Meta
         */
    thisClass.addMethod(/*ABSString*/
    "getName", new ABSClosure() {

        @Override
        public ABSString exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicProduct thisP = (ABSDynamicProduct) t;
            return ABSString.fromString(thisP.getName());
        }
    });
    thisClass.addMethod(/*List<ABSDynamicFeature>*/
    "getFeatures", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicProduct thisP = (ABSDynamicProduct) t;
            ArrayList<ABSDynamicFeature> features = new ArrayList<>();
            for (ABSDynamicFeature f : thisP.getFeatures()) {
                features.add(f);
            }
            return ListUtils.toABSList(features);
        }
    });
    thisClass.addMethod(/*Set<ABSDynamicProduct>*/
    "getConfigurableProducts", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicProduct thisP = (ABSDynamicProduct) t;
            return ListUtils.toABSSet(thisP.getConfigurableProducts());
        }
    });
    thisClass.addMethod(/*ABSDynamicReconfiguration*/
    "getReconfiguration", new ABSClosure() {

        @Override
        public ABSDynamicReconfiguration exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicProduct thisP = (ABSDynamicProduct) t;
            ABSDynamicProduct targetP = (ABSDynamicProduct) params[0];
            return thisP.getReconfiguration(targetP);
        }
    });
}
Also used : ABSDynamicObject(org.abs_models.backend.java.lib.runtime.ABSDynamicObject) ABSClosure(org.abs_models.backend.java.lib.runtime.ABSClosure) ABSDynamicFeature(org.abs_models.backend.java.lib.runtime.ABSDynamicFeature) ABSDynamicProduct(org.abs_models.backend.java.lib.runtime.ABSDynamicProduct) ArrayList(java.util.ArrayList) 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 7 with ABSValue

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

the class SequenceDiagramVisualization method taskCreated.

@Override
public synchronized void taskCreated(TaskView task) {
    task.registerTaskListener(this);
    if (task.getSource() == null) {
        return;
    }
    String sourceClass = getClassName(task.getSource());
    String targetClass = getClassName(task.getTarget());
    if (isObservedClass(sourceClass) && isObservedClass(targetClass)) {
        String msgAction = ":>";
        if (isEnvironmentClass(sourceClass) || isEnvironmentClass(targetClass))
            msgAction = ":";
        String source = getActorName(task.getSource());
        if (isSystemClass(sourceClass))
            source = source + "[" + "Task" + task.getSender().getID() + "]";
        if (firstMessage) {
            writeOutLn();
            if (showStartMsg)
                writeOutLn("HiddenEnv:Main_1[Task1].start()");
            firstMessage = false;
        }
        if (isObservedClass(targetClass))
            task.registerTaskListener(TASK_BLOCKING_OBSERVER);
        writeOut(source);
        writeOut(msgAction);
        /*
             * if (systemClasses.contains(task.getSource().getClassName())) {
             * writeOut(":>"); }
             */
        writeOut(getActorName(task.getTarget()));
        if (isSystemClass(targetClass)) {
            // if (task.getID() != 1) // no main task
            writeOut("[" + "Task" + task.getID() + "]");
        }
        writeOut(".");
        writeOut(task.getMethodName());
        writeOut("(");
        StringBuffer argString = new StringBuffer();
        boolean first = true;
        for (ABSValue v : task.getArgs()) {
            if (first)
                first = false;
            else
                argString.append(", ");
            argString.append("" + v);
        }
        writeOut(shorten(String.valueOf(argString.toString())));
        writeOutLn(")");
    }
}
Also used : ABSValue(org.abs_models.backend.java.lib.types.ABSValue)

Example 8 with ABSValue

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

the class Method method setupAPI.

/*
     * Define the methods of this class
     */
public static void setupAPI() {
    thisClass.setName("Method");
    // FIXME This does not work currently, because abslang.abs needs to declare
    // * the return type
    // * the number and types of arguments
    thisClass.addMethod(/*ABSValue*/
    "exec", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            ABSClosure method = (ABSClosure) t;
            // FIXME
            // params[0] is the receiver object,
            // params[1] is an ABSList with the actual arguments
            ABSValue res = method.exec((ABSDynamicObject) params[0], params[1]);
            // FIXME return the result...
            return ABSUnit.UNIT;
        }
    });
}
Also used : ABSDynamicObject(org.abs_models.backend.java.lib.runtime.ABSDynamicObject) ABSClosure(org.abs_models.backend.java.lib.runtime.ABSClosure) ABSValue(org.abs_models.backend.java.lib.types.ABSValue)

Example 9 with ABSValue

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

the class Reconfiguration method setupMetaAPI.

/*
     * Define the methods of this class
     */
public static void setupMetaAPI() {
    thisClass.setName("Reconfiguration");
    /* 
         * MetaABS Reconfiguration API -- cf. abslang.abs module ABS.Meta 
         */
    thisClass.addMethod(/*ABSString*/
    "getName", new ABSClosure() {

        @Override
        public ABSString exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            return ABSString.fromString(thisR.getName());
        }
    });
    thisClass.addMethod(/*ABSDynamicProduct*/
    "getCurrentProduct", new ABSClosure() {

        @Override
        public ABSDynamicProduct exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            return thisR.getCurrentProduct();
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "setCurrentProduct", new ABSClosure() {

        @Override
        public ABSUnit exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            ABSDynamicProduct prod = (ABSDynamicProduct) params[0];
            thisR.setCurrentProduct(prod);
            return ABSUnit.UNIT;
        }
    });
    thisClass.addMethod(/*ABSDynamicProduct*/
    "getTargetProduct", new ABSClosure() {

        @Override
        public ABSDynamicProduct exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            return thisR.getTargetProduct();
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "setTargetProduct", new ABSClosure() {

        @Override
        public ABSUnit exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            ABSDynamicProduct prod = (ABSDynamicProduct) params[0];
            thisR.setTargetProduct(prod);
            return ABSUnit.UNIT;
        }
    });
    thisClass.addMethod(/*List<ABSDynamicDelta>*/
    "getDeltas", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            List<ABSDynamicDelta> deltas = thisR.getDeltas();
            return ListUtils.toABSList(deltas);
        }
    });
    thisClass.addMethod(/*List<ABSDynamicDelta>*/
    "setDeltas", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            // TODO
            return ABSUnit.UNIT;
        }
    });
    thisClass.addMethod(/*ABSDynamicUpdate*/
    "getStateUpdate", new ABSClosure() {

        @Override
        public ABSDynamicUpdate exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            return thisR.getUpdate();
        }
    });
    thisClass.addMethod(/*List<ABSDynamicDelta>*/
    "setStateUpdate", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            ABSDynamicUpdate upd = (ABSDynamicUpdate) params[0];
            thisR.setUpdate(upd);
            return ABSUnit.UNIT;
        }
    });
}
Also used : ABSDynamicObject(org.abs_models.backend.java.lib.runtime.ABSDynamicObject) ABSClosure(org.abs_models.backend.java.lib.runtime.ABSClosure) ABSDynamicProduct(org.abs_models.backend.java.lib.runtime.ABSDynamicProduct) ABSUnit(org.abs_models.backend.java.lib.types.ABSUnit) List(java.util.List) ABSDynamicUpdate(org.abs_models.backend.java.lib.runtime.ABSDynamicUpdate) 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 ABSValue

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

the class ListUtils method toABSList.

/*
     * Transform a java.util.List into an ABS.StdLib.List
     */
public static ABSValue toABSList(java.util.List<? extends ABSValue> l) {
    if (l.isEmpty()) {
        return DynamicClassUtils.instance("ABS.StdLib.List_Nil");
    } else {
        // make sure we can use remove()
        ArrayList<ABSValue> ml = new ArrayList<>(l);
        ABSValue head = ml.remove(0);
        return DynamicClassUtils.instance("ABS.StdLib.List_Cons", head, toABSList(ml));
    }
}
Also used : ArrayList(java.util.ArrayList) ABSValue(org.abs_models.backend.java.lib.types.ABSValue)

Aggregations

ABSValue (org.abs_models.backend.java.lib.types.ABSValue)16 ABSClosure (org.abs_models.backend.java.lib.runtime.ABSClosure)10 ABSDynamicObject (org.abs_models.backend.java.lib.runtime.ABSDynamicObject)10 ABSString (org.abs_models.backend.java.lib.types.ABSString)8 ABSUnit (org.abs_models.backend.java.lib.types.ABSUnit)4 ArrayList (java.util.ArrayList)3 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 COG (org.abs_models.backend.java.lib.runtime.COG)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 DynamicException (org.abs_models.backend.java.codegeneration.dynamic.DynamicException)1 ABSDynamicDelta (org.abs_models.backend.java.lib.runtime.ABSDynamicDelta)1 ABSDynamicProductLine (org.abs_models.backend.java.lib.runtime.ABSDynamicProductLine)1 ABSBool (org.abs_models.backend.java.lib.types.ABSBool)1 ABSProcess (org.abs_models.backend.java.lib.types.ABSProcess)1