Skip to content

Commit

Permalink
Cleaning1
Browse files Browse the repository at this point in the history
  • Loading branch information
Alireza-Ardalani committed Jul 9, 2022
1 parent 68691f4 commit 391ada2
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 92 deletions.
12 changes: 10 additions & 2 deletions src/gr/uom/java/ast/decomposition/cfg/AbstractVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public abstract class AbstractVariable {
protected boolean isField;
protected boolean isParameter;
protected boolean isStatic;
//SBSRE => add new
protected boolean isFainal;

public AbstractVariable(VariableDeclaration name) {
IVariableBinding variableBinding = name.resolveBinding();
Expand All @@ -21,20 +23,23 @@ public AbstractVariable(VariableDeclaration name) {
this.isField = variableBinding.isField();
this.isParameter = variableBinding.isParameter();
this.isStatic = (variableBinding.getModifiers() & Modifier.STATIC) != 0;
this.isFainal = (variableBinding.getModifiers() & Modifier.FINAL) != 0;

}

public AbstractVariable(IVariableBinding variableBinding) {
this(variableBinding.getKey(), variableBinding.getName(), variableBinding.getType().getQualifiedName(),
variableBinding.isField(), variableBinding.isParameter(), (variableBinding.getModifiers() & Modifier.STATIC) != 0);
variableBinding.isField(), variableBinding.isParameter(), (variableBinding.getModifiers() & Modifier.STATIC) != 0, (variableBinding.getModifiers() & Modifier.FINAL) != 0);
}

public AbstractVariable(String variableBindingKey, String variableName, String variableType, boolean isField, boolean isParameter, boolean isStatic) {
public AbstractVariable(String variableBindingKey, String variableName, String variableType, boolean isField, boolean isParameter, boolean isStatic, boolean isFainal) {
this.variableBindingKey = variableBindingKey;
this.variableName = variableName;
this.variableType = variableType;
this.isField = isField;
this.isParameter = isParameter;
this.isStatic = isStatic;
this.isFainal =isFainal;
}

public String getVariableBindingKey() {
Expand All @@ -60,6 +65,9 @@ public boolean isParameter() {
public boolean isStatic() {
return isStatic;
}
public boolean isFainal(){
return isFainal;
}

public abstract boolean containsPlainVariable(PlainVariable variable);
public abstract boolean startsWithVariable(AbstractVariable variable);
Expand Down
12 changes: 6 additions & 6 deletions src/gr/uom/java/ast/decomposition/cfg/CompositeVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public CompositeVariable(IVariableBinding referenceBinding, AbstractVariable rig

public CompositeVariable(AbstractVariable argument, AbstractVariable rightPart) {
this(argument.getVariableBindingKey(), argument.getVariableName(),
argument.getVariableType(), argument.isField(), argument.isParameter(), argument.isStatic(), rightPart);
argument.getVariableType(), argument.isField(), argument.isParameter(), argument.isStatic(),argument.isFainal(), rightPart);
}

private CompositeVariable(String variableBindingKey, String variableName, String variableType, boolean isField, boolean isParameter, boolean isStatic, AbstractVariable rightPart) {
super(variableBindingKey, variableName, variableType, isField, isParameter, isStatic);
private CompositeVariable(String variableBindingKey, String variableName, String variableType, boolean isField, boolean isParameter, boolean isStatic,boolean isFainal, AbstractVariable rightPart) {
super(variableBindingKey, variableName, variableType, isField, isParameter, isStatic,isFainal);
this.rightPart = rightPart;
}

Expand All @@ -35,11 +35,11 @@ public AbstractVariable getRightPart() {
//if composite variable is "one.two.three" then left part is "one.two"
public AbstractVariable getLeftPart() {
if(rightPart instanceof PlainVariable) {
return new PlainVariable(variableBindingKey, variableName, variableType, isField, isParameter, isStatic);
return new PlainVariable(variableBindingKey, variableName, variableType, isField, isParameter, isStatic,isFainal);
}
else {
CompositeVariable compositeVariable = (CompositeVariable)rightPart;
return new CompositeVariable(variableBindingKey, variableName, variableType, isField, isParameter, isStatic, compositeVariable.getLeftPart());
return new CompositeVariable(variableBindingKey, variableName, variableType, isField, isParameter, isStatic,isFainal, compositeVariable.getLeftPart());
}
}

Expand All @@ -55,7 +55,7 @@ public PlainVariable getFinalVariable() {

//if composite variable is "one.two.three" then initial variable is "one"
public PlainVariable getInitialVariable() {
return new PlainVariable(variableBindingKey, variableName, variableType, isField, isParameter, isStatic);
return new PlainVariable(variableBindingKey, variableName, variableType, isField, isParameter, isStatic,isFainal);
}

public boolean containsPlainVariable(PlainVariable variable) {
Expand Down
34 changes: 27 additions & 7 deletions src/gr/uom/java/ast/decomposition/cfg/PDGSliceUnion.java
Original file line number Diff line number Diff line change
Expand Up @@ -583,23 +583,41 @@ else if(pdgNode.usesLocalVariable(variable)){
//SBSRE: add outputRule() Method =>

public boolean outputRule(){
boolean temp=false;
boolean outOfRegion=false;
for(GraphNode node : sliceNodes) {
PDGNode pdgNode = (PDGNode)node;
if(pdgNode.getId() > First && pdgNode.getId() <=Last){
temp = false;
outOfRegion = false;
}
else{
temp = true;
outOfRegion = true;
}
}
return temp;
return outOfRegion;
}

//SBSRE : add variableCriterionIsFainal
public boolean variableCriterionIsFainal(){
int counter = 0;
if(localVariableCriterion.isFainal()){
for(GraphNode node : pdg.nodes){
PDGNode pdgNode = (PDGNode)node;
if(pdgNode.definesLocalVariable(localVariableCriterion) &&
!pdgNode.declaresLocalVariable(localVariableCriterion)){
counter++;
}
}
}
if(counter > 1){
return true;
}
return false;
}

public boolean satisfiesRules() {

if(sliceEqualsMethodBody() || sliceContainsOnlyOneNodeCriterionAndDeclarationOfVariableCriterion() ||
declarationOfVariableCriterionIsDuplicated() ||
declarationOfVariableCriterionIsDuplicated() ||
variableCriterionIsReturnedVariableInOriginalMethod() || (sliceNodes.size() <= nodeCriteria.size()) ||
allNodeCriteriaAreDuplicated() || returnStatementIsControlDependentOnSliceNode() || sliceContainsReturnStatement() ||
containsDuplicateNodeWithStateChangingMethodInvocation() ||
Expand All @@ -614,11 +632,12 @@ public boolean satisfiesRules() {


public boolean satisfiesRulesSRP() {
if(sliceEqualsMethodBody() || sliceSameAsOrginalMethod() || outputRule() ||
if(sliceEqualsMethodBody() || sliceSameAsOrginalMethod() || outputRule() ||
sliceContainsOnlyOneNodeCriterionAndDeclarationOfVariableCriterion() ||
sliceNodes.size() <= nodeCriteria.size() ||
allNodeCriteriaAreDuplicated() ||
allNodeCriteriaAreDuplicated() || variableCriterionIsFainal() ||
nonDuplicatedSliceNodeAntiDependsOnNonRemovableNode() ||
nonDuplicatedSliceNodeOutputDependsOnNonRemovableNode() ||
containsDuplicateNodeWithStateChangingMethodInvocation() ||
nonDuplicatedSliceNodeOutputDependsOnNonRemovableNode() ||
duplicatedSliceNodeWithClassInstantiationHasDependenceOnRemovableNode() ||
Expand All @@ -627,4 +646,5 @@ public boolean satisfiesRulesSRP() {
return false;
return true;
}

}
4 changes: 2 additions & 2 deletions src/gr/uom/java/ast/decomposition/cfg/PlainVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public PlainVariable(IVariableBinding variableBinding) {
super(variableBinding);
}

public PlainVariable(String variableBindingKey, String variableName, String variableType, boolean isField, boolean isParameter, boolean isStatic) {
super(variableBindingKey, variableName, variableType, isField, isParameter, isStatic);
public PlainVariable(String variableBindingKey, String variableName, String variableType, boolean isField, boolean isParameter, boolean isStatic, boolean isFainal) {
super(variableBindingKey, variableName, variableType, isField, isParameter, isStatic,isFainal);
}

public boolean containsPlainVariable(PlainVariable variable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2328,7 +2328,7 @@ private void addVariable(IVariableBinding variableBinding, Set<PlainVariable> ad
}

private void addThisVariable(Set<PlainVariable> additionalArgumentsAddedToMovedMethod) {
PlainVariable variable = new PlainVariable("this", "this", "this", false, false, false);
PlainVariable variable = new PlainVariable("this", "this", "this", false, false, false,false);
additionalArgumentsAddedToMovedMethod.add(variable);
}

Expand Down
Loading

0 comments on commit 391ada2

Please sign in to comment.