Skip to content

Commit

Permalink
Introducing another rule 43 implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmop committed May 9, 2019
1 parent 4e5d1f9 commit 11e8d92
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 132 deletions.
32 changes: 1 addition & 31 deletions src/main/java/mujava/op/basic/AOIU.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

import mujava.op.util.ExpressionAnalyzer;
import mujava.op.util.LogReduction;
import mujava.util.drule.AOIUVariableMutation;
import mujava.util.drule.ASRSMutation;
import mujava.util.drule.DRuleUtils;
import mujava.util.drule.MutationInfo;
import openjava.mop.FileEnvironment;
import openjava.ptree.*;

Expand Down Expand Up @@ -77,7 +73,7 @@ public void visit(UnaryExpression p) throws ParseTreeException {
* Generate AOIU mutant
*/
public void visit(Variable p) throws ParseTreeException {
if (isArithmeticType(p) && !isDuplicated(p)) {
if (isArithmeticType(p)) {
outputToFile(p);
}
}
Expand Down Expand Up @@ -284,32 +280,6 @@ boolean isEquivalent(BinaryExpression exp) {
constraints = {
}"*/
private boolean isDuplicated(Variable variable) {
boolean d_aoiu_asrs43 = false;
ParseTreeObject parseTreeObject = (ParseTreeObject) variable;
while (parseTreeObject!=null && !((parseTreeObject instanceof AssignmentExpression)
|| (parseTreeObject instanceof MethodDeclaration))) {
parseTreeObject = parseTreeObject.getParent();
}
if (parseTreeObject instanceof AssignmentExpression) {
AssignmentExpression asge = (AssignmentExpression) parseTreeObject;
boolean variableIsSame = variable.equals(asge.getRight());
if (variableIsSame && (asge.getOperator() == AssignmentExpression.ADD)) {
//TODO: Check whether currentClassName returns fully qualified Class name
ASRSMutation duplicatedMutation = new ASRSMutation("+=", "-=",asge
,this.env.currentClassName());
if (DRuleUtils.access().consumeOperation(DRuleUtils.MOperator.ASRS,duplicatedMutation)) {
d_aoiu_asrs43 = LogReduction.AVOID;
logReduction("AOIU", "ASRS", "DAOIU_ASRS =>" + asge.toFlattenString());
} else {
DRuleUtils.access().insertMutation(DRuleUtils.MOperator.AOIU,
new AOIUVariableMutation(variable,this.env.currentClassName()));
}
}
}
return d_aoiu_asrs43;
}

// private boolean isDuplicated(Expression expression) {
// /*
// * "term = type v := exp; ... return v;
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/mujava/op/basic/ASRS.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
*/
package mujava.op.basic;

import mujava.op.rules.DRule;
import mujava.op.util.LogReduction;
import mujava.util.drule.AOIUVariableMutation;
import mujava.util.drule.DRuleUtils;
import openjava.mop.FileEnvironment;
import openjava.ptree.*;
Expand Down Expand Up @@ -191,13 +189,11 @@ public void outputToFile(AssignmentExpression original, AssignmentExpression mut
* */
private boolean isDuplicated(AssignmentExpression asge, AssignmentExpression mutant) {
boolean d_aoiu_asrs43 = false;
if (asge.getOperator() == AssignmentExpression.ADD && (mutant.getOperator() == AssignmentExpression.SUB)) {
AOIUVariableMutation aoiuVariableMutation = new AOIUVariableMutation((Variable) asge.getRight(),
this.env.currentClassName());
if (DRuleUtils.access().consumeOperation(DRuleUtils.MOperator.AOIU,aoiuVariableMutation)) {
d_aoiu_asrs43 = LogReduction.AVOID;
logReduction("AOIU", "ASRS", "DAOIU_ASRS43 =>" + asge.toFlattenString());
}
if (asge.getOperator() == AssignmentExpression.ADD && (mutant.getOperator() == AssignmentExpression.SUB)
&& DRuleUtils.access().isOperatorSelected("AOIU")) {
d_aoiu_asrs43 = LogReduction.AVOID;
logReduction("43AOIU","ASRS", asge.toFlattenString() +
"=>" + mutant.toFlattenString());
}
return d_aoiu_asrs43;
}
Expand Down
23 changes: 0 additions & 23 deletions src/main/java/mujava/util/drule/AOIUVariableMutation.java

This file was deleted.

29 changes: 0 additions & 29 deletions src/main/java/mujava/util/drule/ASRSMutation.java

This file was deleted.

67 changes: 29 additions & 38 deletions src/main/java/mujava/util/drule/DRuleUtils.java
Original file line number Diff line number Diff line change
@@ -1,74 +1,65 @@
package mujava.util.drule;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Semaphore;

public class DRuleUtils {
public enum MOperator {
AOIU,
AOIU,
ASRS
};
static Map<MOperator, List<MutationInfo>> selectedOperators = new HashMap<>();
}

;
static Semaphore sem = new Semaphore(1, true);
static DRuleUtils instance = new DRuleUtils();
static List<String> allOperatorsSelected = new ArrayList<>();
static List<MutationInfo> mutationInfoList = new ArrayList<>();

DRuleUtils () {
DRuleUtils() {

}

public static DRuleUtils access() {
return instance;
}
/**
* Checks whether a certain mutation was done with some operator
* and then removes it from memory
*
* @param operator enum corresponding to the operator intended to lookup
* @param operation the kind of mutation to lookup
*/
public boolean consumeOperation(MOperator operator, MutationInfo operation) {
boolean r = false;
public boolean addMutation(MutationInfo mutationInfo) {
boolean ret = false;
try {
synchronized (this) {
sem.acquire();
r = selectedOperators.containsKey(operator) && selectedOperators.get(operator).contains(operation);
if (r) {
selectedOperators.get(operator).remove(operation);
selectedOperators.remove(operator);
if (!mutationInfoList.contains(mutationInfo)) {
ret = true;
mutationInfoList.add(mutationInfo);
}
sem.release();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
return r;
return ret;
}

/**
* Inserts a certain mutation that was done with some operator
* and then removes it from memory
*
* @param operator a String corresponding the operator intended to lookup
* @param operation the kind of mutation to lookup
*/
public boolean insertMutation(MOperator operator, MutationInfo operation) {
boolean r = false;
public boolean containsMutation(MutationInfo mutationInfo) {
boolean ret = false;
try {
synchronized (this) {
sem.acquire();
if (!selectedOperators.containsKey(operator)) selectedOperators.put(operator, new ArrayList<>());
if (!selectedOperators.get(operator).contains(operation)) {
selectedOperators.get(operator).add(operation);
r = true;
}
ret = mutationInfoList.contains(mutationInfo);
sem.release();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
return r;
return ret;
}

public boolean isOperatorSelected(String op) {
return allOperatorsSelected.contains(op);
}

public void setSelectedOperators(List<String> allOperatorsSelected) {
this.allOperatorsSelected = allOperatorsSelected;
}

public static DRuleUtils access() {
return instance;
}
}
25 changes: 23 additions & 2 deletions src/main/java/mujava/util/drule/MutationInfo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
package mujava.util.drule;

public interface MutationInfo {
boolean equals(MutationInfo other);
public class MutationInfo {
public enum DRule {
RULE43,
RULE49,
RULE52,
RULE56,
RULE57,
RULE66,
RULE69,
RULE70
}

DRule rule;
DRuleUtils.MOperator operator;
String classname;

public MutationInfo(DRuleUtils.MOperator operator, DRule rule, String classname) {

}
public boolean equals(MutationInfo other) {
return this.rule.equals(other.rule) && this.operator.equals(other.operator)
&& this.classname.equals(other.classname);
}
}

0 comments on commit 11e8d92

Please sign in to comment.