
org.snapscript.tree.operation.AssignmentOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
The newest version!
package org.snapscript.tree.operation;
import org.snapscript.core.convert.StringBuilder;
import org.snapscript.core.error.InternalStateException;
import org.snapscript.core.scope.Scope;
import org.snapscript.core.variable.Value;
import org.snapscript.parse.StringToken;
public class AssignmentOperation {
private final AssignmentOperator operator;
public AssignmentOperation(StringToken operator) {
this.operator = AssignmentOperator.resolveOperator(operator);
}
public Value operate(Scope scope, Value left, Value right) throws Exception {
if(operator != AssignmentOperator.EQUAL) {
Object leftValue = left.getValue();
if(!Number.class.isInstance(leftValue)) {
Object rightValue = right.getValue();
if(operator != AssignmentOperator.PLUS_EQUAL) {
throw new InternalStateException("Operator " + operator + " is illegal");
}
String leftText = StringBuilder.create(scope, leftValue);
String rightText = StringBuilder.create(scope, rightValue);
String text = leftText.concat(rightText);
left.setValue(text);
return left;
}
}
return operator.operate(scope, left, right);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy