Search in sources :

Example 1 with ObjectView

use of abs.backend.java.observing.ObjectView in project abstools by abstools.

the class JavaBackendTest method assertValidJavaExecution.

void assertValidJavaExecution(boolean withStdLib, String... codeLines) throws Exception {
    StringBuilder absCode = new StringBuilder();
    for (String line : codeLines) {
        absCode.append(line);
        absCode.append("\n");
    }
    JavaCode javaCode = getJavaCode(absCode.toString(), withStdLib ? Config.WITH_STD_LIB : null);
    try {
        String genDir = javaCode.getSrcDir().getAbsolutePath() + "/gen/test";
        javaCode.compile("-classpath", "bin", "-d", genDir);
        final ABSRuntime r = makeAbsRuntime();
        r.enableDebugging(true);
        final boolean[] finished = new boolean[] { false };
        final List<ABSException> exceptions = Collections.synchronizedList(new ArrayList<ABSException>());
        r.addSystemObserver(new SystemObserver() {

            @Override
            public void systemStarted() {
            }

            @Override
            public void systemFinished() {
                synchronized (finished) {
                    finished[0] = true;
                    finished.notifyAll();
                }
            }

            @Override
            public void systemError(ABSException e) {
                exceptions.add(e);
            }

            @Override
            public void newCOGCreated(COGView cog, ObjectView initialObject) {
            }
        });
        r.start(new File(genDir), "Test.Main");
        while (!finished[0]) {
            synchronized (finished) {
                finished.wait(100);
            }
        }
        r.shutdown();
        for (ABSException e : exceptions) {
            throw e;
        }
    } catch (Exception e) {
        System.out.println(javaCode);
        throw e;
    } finally {
        javaCode.deleteCode();
    }
}
Also used : COGView(abs.backend.java.observing.COGView) SystemObserver(abs.backend.java.observing.SystemObserver) JavaCode(abs.backend.java.codegeneration.JavaCode) ObjectView(abs.backend.java.observing.ObjectView) JavaCodeGenerationException(abs.backend.java.codegeneration.JavaCodeGenerationException) ABSException(abs.backend.java.lib.runtime.ABSException) ABSRuntime(abs.backend.java.lib.runtime.ABSRuntime) ABSException(abs.backend.java.lib.runtime.ABSException)

Example 2 with ObjectView

use of abs.backend.java.observing.ObjectView in project abstools by abstools.

the class DebugTreeStyledLabelProvider method getLabel.

private StyledString getLabel(Object element) {
    if (element instanceof TaskView) {
        String s = "Task " + ((TaskView) element).getID() + " (" + ((TaskView) element).getMethodName() + ")";
        List<TaskView> schedulableTasks = getSchedulerRef().getSchedulableTasks();
        if (schedulableTasks != null) {
            for (TaskView taskView : schedulableTasks) {
                if (taskView.getID() == ((TaskView) element).getID()) {
                    return new StyledString(s, STYLER_BLACK);
                }
            }
        }
        return new StyledString(s, STYLER_GREY);
    } else if (element instanceof COGView) {
        COGView cog = (COGView) element;
        String s = "COG " + cog.getID() + " (" + getInitialObject(cog).getClassName() + " " + getInitialObject(cog).getID() + ")";
        // for color of the string, check if there is a task that can be stepped
        if (cog.getScheduler().getSchedulableTasks().size() > 0) {
            return new StyledString(s, STYLER_BLACK);
        } else {
            return new StyledString(s, STYLER_GREY);
        }
    } else if (element instanceof Tasks) {
        String s = "Tasks (" + getCOGInfo(((Tasks) element).getCOG()).getTasks().size() + ")";
        // for color of the string, check if there is a task that can be stepped
        if (((Tasks) element).getCOG().getScheduler().getSchedulableTasks().size() > 0) {
            return new StyledString(s, STYLER_BLACK);
        } else {
            return new StyledString(s, STYLER_GREY);
        }
    } else if (element instanceof Objects) {
        return new StyledString("Objects (" + ((Objects) element).getObjects().size() + ")", STYLER_BLACK);
    } else if (element instanceof TaskStackFrameView) {
        TaskStackFrameView tsv = ((TaskStackFrameView) element);
        MethodView mv = tsv.getMethod();
        return new StyledString("StackFrame (" + mv.toString() + ")", STYLER_BLACK);
    } else if (element instanceof ObjectView) {
        ObjectView obj = (ObjectView) element;
        return new StyledString(obj.getClassName() + " " + obj.getID(), STYLER_BLACK);
    } else if (element instanceof DebugModel) {
        return new StyledString(getDebugger().getProjectName(), STYLER_BLACK);
    } else {
        return new StyledString("UnknownObject", STYLER_GREY);
    }
}
Also used : COGView(abs.backend.java.observing.COGView) TaskView(abs.backend.java.observing.TaskView) Tasks(org.absmodels.abs.plugin.debug.model.Tasks) DebugModel(abs.backend.java.debugging.DebugModel) Objects(org.absmodels.abs.plugin.debug.model.Objects) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) TaskStackFrameView(abs.backend.java.observing.TaskStackFrameView) MethodView(abs.backend.java.observing.MethodView) ObjectView(abs.backend.java.observing.ObjectView)

Example 3 with ObjectView

use of abs.backend.java.observing.ObjectView in project abstools by abstools.

the class DebugView method createViewer.

@Override
protected Viewer createViewer(Composite parent) {
    final TreeViewer viewer = new TreeViewer(parent);
    viewer.setContentProvider(new DebugTreeContentProvider());
    viewer.setLabelProvider(new DebugTreeStyledLabelProvider());
    viewer.setInput(debugger.getModel());
    viewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            refreshButtonEnablement();
            Object selection = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (selection instanceof TaskView || selection instanceof ObjectView || selection instanceof TaskStackFrameView) {
                refreshVariableView();
                if (selection instanceof TaskView) {
                    TaskView tv = (TaskView) selection;
                    TaskInfo taskInfo = getDebugger().getModel().getTaskInfo(tv);
                    highlightLine(taskInfo);
                }
            }
            getSchedulerRef().taskSelectionChanged(selection);
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            Object selection = ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (selection instanceof ObjectView || selection instanceof TaskStackFrameView) {
                openVariableView();
                refreshVariableView();
            } else {
                viewer.setExpandedState(selection, !viewer.getExpandedState(selection));
            }
        }
    });
    viewer.expandAll();
    return viewer;
}
Also used : TaskView(abs.backend.java.observing.TaskView) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) ObjectView(abs.backend.java.observing.ObjectView) TaskStackFrameView(abs.backend.java.observing.TaskStackFrameView) TaskInfo(abs.backend.java.debugging.TaskInfo) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener)

Example 4 with ObjectView

use of abs.backend.java.observing.ObjectView in project abstools by abstools.

the class VariableContentProvider method getChildren.

@Override
public Object[] getChildren(Object parentElement) {
    if (parentElement != null) {
        if (parentElement instanceof TaskStackFrameView) {
            TaskStackFrameView stackFrame = (TaskStackFrameView) parentElement;
            ArrayList<VariableValuePair> children = new ArrayList<VariableValuePair>();
            for (String variableName : stackFrame.getVariableNames()) {
                children.add(new VariableValuePair(variableName, stackFrame.getValue(variableName)));
            }
            return children.toArray();
        } else if (parentElement instanceof ObjectView) {
            ObjectView obj = (ObjectView) parentElement;
            ArrayList<VariableValuePair> children = new ArrayList<VariableValuePair>();
            for (String fieldName : obj.getFieldNames()) {
                try {
                    children.add(new VariableValuePair(fieldName, obj.getFieldValue(fieldName)));
                } catch (NoSuchFieldException e) {
                // can never happen. Since we iterate over the field names, the field is guaranteed
                // to exist as long as the objectView is implemented correctly.
                }
            }
            return children.toArray();
        } else if (parentElement instanceof VariableValuePair) {
            return getChildren(((VariableValuePair) parentElement).getValue());
        } else if (parentElement instanceof ABSObject) {
            return getChildren(((ABSObject) parentElement).getView());
        }
    }
    // single (or unknown) value - no children
    return new Object[0];
}
Also used : VariableValuePair(org.absmodels.abs.plugin.debug.model.VariableValuePair) ArrayList(java.util.ArrayList) ABSObject(abs.backend.java.lib.runtime.ABSObject) ABSObject(abs.backend.java.lib.runtime.ABSObject) TaskStackFrameView(abs.backend.java.observing.TaskStackFrameView) ObjectView(abs.backend.java.observing.ObjectView)

Aggregations

ObjectView (abs.backend.java.observing.ObjectView)4 TaskStackFrameView (abs.backend.java.observing.TaskStackFrameView)3 COGView (abs.backend.java.observing.COGView)2 TaskView (abs.backend.java.observing.TaskView)2 JavaCode (abs.backend.java.codegeneration.JavaCode)1 JavaCodeGenerationException (abs.backend.java.codegeneration.JavaCodeGenerationException)1 DebugModel (abs.backend.java.debugging.DebugModel)1 TaskInfo (abs.backend.java.debugging.TaskInfo)1 ABSException (abs.backend.java.lib.runtime.ABSException)1 ABSObject (abs.backend.java.lib.runtime.ABSObject)1 ABSRuntime (abs.backend.java.lib.runtime.ABSRuntime)1 MethodView (abs.backend.java.observing.MethodView)1 SystemObserver (abs.backend.java.observing.SystemObserver)1 ArrayList (java.util.ArrayList)1 Objects (org.absmodels.abs.plugin.debug.model.Objects)1 Tasks (org.absmodels.abs.plugin.debug.model.Tasks)1 VariableValuePair (org.absmodels.abs.plugin.debug.model.VariableValuePair)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1