package net.spanbroek.judith.interpreter;

import net.spanbroek.judith.runtime.Object;
import net.spanbroek.judith.runtime.Method;
import net.spanbroek.judith.runtime.MethodCall;
import net.spanbroek.judith.runtime.Scope;
import net.spanbroek.judith.runtime.World;
import net.spanbroek.judith.tree.Expression;

public class InterpretedExpression extends Method {

    private World world;
    private Expression expression;

    public InterpretedExpression(String name, String[] parameters, Expression expression, World world) {
        super(name, parameters);
        this.world = world;
        this.expression = expression;
    }

    @Override
    public Object execute(MethodCall methodCall, Scope scope) {
        methodCall.declareExplicitParameters(scope, parameterNames);
        return evaluate(scope);
    }

    private Object evaluate(Scope scope) {
        Visitor visitor = new Visitor(world, scope);
        visitor.visit(expression);
        return (Object) visitor.getStack().pop();
    }

    @Override
    protected void execute(Scope scope) {
        throw new UnsupportedOperationException("Not supported");
    }

}

@@ -788,64 +788,105 @@
     
-return evaluate(scope);%0A    %7D%0A%0A    private Object evalua
+execute(scope);%0A        return scope.get(%22result%22);%0A    %7D%0A%0A    @Override%0A    protected void execu
 te(S
@@ -995,22 +995,39 @@
         
-return
+scope.declare(%22result%22,
  (Object
@@ -1056,136 +1056,8 @@
 op()
-;%0A    %7D%0A%0A    @Override%0A    protected void execute(Scope scope) %7B%0A        throw new UnsupportedOperationException(%22Not supported%22
 );%0A 
@@ -1061,11 +1061,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

remove "refused bequest" code smell