@specs-feup/kadabra
Version:
A Java source-to-source compiler written in Typescript
45 lines • 1.51 kB
JavaScript
import Mutator from "@specs-feup/lara/api/lara/mutation/Mutator.js";
/**
* @param binaryExpression - A join point of type binaryExpression.
* @param newOperators - Operators that will be used to mutate the given binaryExpression.
*/
export default class BinaryExpressionMutator extends Mutator {
binaryExpression;
newOperators;
currentIndex;
previousOp;
constructor(binaryExpression, ...newOperators) {
super();
// Instance variables
this.binaryExpression = binaryExpression;
this.newOperators = newOperators;
this.currentIndex = 0;
this.previousOp = undefined;
// Checks
// TODO: Check if operators are valid
}
hasMutations() {
return this.currentIndex < this.newOperators.length;
}
getMutationPoint() {
return this.binaryExpression;
}
mutatePrivate() {
// Obtain new operator, increment index
const newOp = this.newOperators[this.currentIndex];
this.currentIndex++;
// Store current operator
this.previousOp = this.binaryExpression.operator;
// Set new operator
this.binaryExpression.operator = newOp;
}
restorePrivate() {
// Restore operator
if (this.previousOp === undefined) {
throw new Error("PreviousOp is undefined.");
}
this.binaryExpression.operator = this.previousOp;
this.previousOp = undefined;
}
}
//# sourceMappingURL=BinaryExpressionMutator.js.map