Skip to content

Commit

Permalink
cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Alireza-Ardalani committed Oct 1, 2023
1 parent 710e1b1 commit 517e0e5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 89 deletions.
1 change: 1 addition & 0 deletions src/gr/uom/java/ast/decomposition/cfg/PDG.java
Original file line number Diff line number Diff line change
Expand Up @@ -1215,4 +1215,5 @@ boolean isCompositeVariable(AbstractVariable Variable){
}
return compositeVariable;
}

}
58 changes: 54 additions & 4 deletions src/gr/uom/java/ast/decomposition/cfg/PDGSliceUnion.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import gr.uom.java.jdeodorant.refactoring.Activator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -501,7 +502,7 @@ else if(cfgNode instanceof CFGContinueNode) {
private boolean complyWithUserThresholds() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
//int minimumSliceSize = store.getInt(PreferenceConstants.P_MINIMUM_SLICE_SIZE);
int minimumSliceSize = 2;
int minimumSliceSize = 3;
int maximumSliceSize = store.getInt(PreferenceConstants.P_MAXIMUM_SLICE_SIZE);
int maximumDuplication = store.getInt(PreferenceConstants.P_MAXIMUM_DUPLICATION);
double maximumRatioOfDuplicatedToExtracted = store.getDouble(
Expand Down Expand Up @@ -714,7 +715,56 @@ public boolean declaredVariableInSlice(AbstractVariable variable) {

return false;
}

public boolean preserveBehaviour(){
Set<PDGNode> duplicatedNodes = new LinkedHashSet<PDGNode>();
duplicatedNodes.addAll(sliceNodes);
duplicatedNodes.retainAll(indispensableNodes);

List<Integer> sliceIDs = new ArrayList<Integer>();
for(GraphNode node : sliceNodes){
sliceIDs.add(node.getId());
}
Collections.sort(sliceIDs);
int firstNode=0;
int lastNode=0;

if(!sliceIDs.isEmpty()){
firstNode = sliceIDs.get(0);
lastNode = sliceIDs.get(sliceIDs.size()-1);
}


for(GraphNode nodeInMethod : pdg.nodes){
int ID = nodeInMethod.getId();
if(firstNode < ID & ID < lastNode & !(sliceNodes.contains(nodeInMethod))){
PDGNode PDGInMethod = (PDGNode)nodeInMethod;
Iterator <AbstractVariable> usedVariableInMethod = PDGInMethod.getUsedVariableIterator();
if(!usedVariableInMethod.hasNext()){
break;
}
else{
for(GraphNode nodeInslice : sliceNodes){
boolean check =true;
if(!duplicatedNodes.isEmpty()){
check = duplicatedNodes.contains(nodeInslice);
}
if(nodeInslice.getId() < ID & check ){
PDGNode PDGInSlice= (PDGNode)nodeInslice;
while(usedVariableInMethod.hasNext()){
AbstractVariable variable = usedVariableInMethod.next();
if(PDGInSlice.definesLocalVariable(variable)){
System.out.println("==> ");
return true;
}
}
}
}
}
}
}
return false;
}
public boolean satisfiesRules() {
if(sliceEqualsMethodBody() || sliceContainsOnlyOneNodeCriterionAndDeclarationOfVariableCriterion() ||
declarationOfVariableCriterionIsDuplicated() ||
Expand All @@ -732,7 +782,7 @@ public boolean satisfiesRules() {


public boolean satisfiesRulesSRP() {
if( sliceSameAsOrginalMethod() || notInitializedParameter() || outputRule() || variableCriterionIsFainal() ||
if( preserveBehaviour() || sliceSameAsOrginalMethod() || notInitializedParameter() || outputRule() || variableCriterionIsFainal() ||
sliceContainsOnlyOneNodeCriterionAndDeclarationOfVariableCriterion() ||sliceEqualsMethodBody() ||
sliceNodes.size() <= nodeCriteria.size() ||
allNodeCriteriaAreDuplicated() ||
Expand All @@ -745,9 +795,9 @@ public boolean satisfiesRulesSRP() {
return false;
return true;
}
public boolean satisfiesRulesZZZZ() {
public boolean satisfiesRulesGlobal() {
//Niaz be eslah darad
if( sliceSameAsOrginalMethod() || variableCriterionIsFainal() ||
if( preserveBehaviour() || sliceSameAsOrginalMethod() || variableCriterionIsFainal() ||
sliceContainsOnlyOneNodeCriterionAndDeclarationOfVariableCriterion() ||sliceEqualsMethodBody() ||
sliceNodes.size() <= nodeCriteria.size() ||
allNodeCriteriaAreDuplicated() ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ else if(Mode==0){
}
for(BasicBlock basicBlock : basicBlockIntersection) {
PDGSliceUnion sliceUnion = new PDGSliceUnion(pdg, basicBlock, nodeCriteria, localVariableCriterion,First,Last);

//Checking Scope of the output after backward slicing.
//We know all the criterion are correct, so checking the Union of the bakward slices is neccesary
Set<PDGNode> sliceNodes = sliceUnion.getSliceNodes();
Set<PDGNode> sliceNodesMustRemoved = new TreeSet<PDGNode>();
for(PDGNode node: sliceNodes){
Expand Down Expand Up @@ -115,7 +113,7 @@ else if(Mode==4){
}
for(BasicBlock basicBlock : basicBlockIntersection) {
PDGSliceUnion sliceUnion = new PDGSliceUnion(pdg, basicBlock, nodeCriteria, localVariableCriterion,First,Last);
if(sliceUnion.satisfiesRulesZZZZ()){
if(sliceUnion.satisfiesRulesGlobal()){
sliceUnionMap.put(basicBlock, sliceUnion);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,7 @@ private void processMethod(final List<ASTSliceGroup> extractedSliceGroups, Class
ITypeRoot typeRoot = classObject.getITypeRoot();
CompilationUnitCache.getInstance().lock(typeRoot);
CFG cfg = new CFG(methodObject);
PDG pdg = new PDG(cfg, classObject.getIFile(), classObject.getFieldsAccessedInsideMethod(methodObject), null);

PDG pdg = new PDG(cfg, classObject.getIFile(), classObject.getFieldsAccessedInsideMethod(methodObject), null);
Set<PlainVariable> ObjectList = new LinkedHashSet<PlainVariable>();
List<PlainVariable> targetList = new ArrayList<PlainVariable>();
List<Integer> First = new ArrayList<Integer>();
Expand All @@ -790,21 +789,6 @@ private void processMethod(final List<ASTSliceGroup> extractedSliceGroups, Class
First=pdg.FirstPDGNode();
Last=pdg.LastPDGNode();
int andis=0;

if(targetList.size()>1){
System.out.println(">>>> OutPuts are More than 1.");
}

// for(VariableDeclaration x:pdg.getFieldsAccessedInMethod()){
// //System.out.println(">> "+x);
// PlainVariable variable = new PlainVariable(x);
// System.out.println(">> "+variable + ">>" + variable.getVariableType());
// if(variable.getVariableType().contains("[]")){
// System.out.print("BAAAAAA");
// }
//
// }

for(PlainVariable variable : targetList) {
Integer first =First.get(andis);
Integer last =Last.get(andis);
Expand Down Expand Up @@ -934,7 +918,7 @@ private void processMethod(final List<ASTSliceGroup> extractedSliceGroups, Class
sumOfDuplicationRatioInGroup += duplicationRatio;
if(numberOfExtractedStatements > maximumNumberOfExtractedStatementsInGroup)
maximumNumberOfExtractedStatementsInGroup = numberOfExtractedStatements;
slice.SetType("ZZZZ");
slice.SetType("globalSlicing");
sliceGroup.addCandidate(slice);
}
}
Expand Down Expand Up @@ -1062,78 +1046,14 @@ private void saveResults() {
try {
BufferedWriter out = new BufferedWriter(new FileWriter(selected));
Tree tree = treeViewer.getTree();
/*TreeColumn[] columns = tree.getColumns();
for(int i=0; i<columns.length; i++) {
if(i == columns.length-1)
out.write(columns[i].getText());
else
out.write(columns[i].getText() + "\t");
}
out.newLine();*/
int objectCounterBIG=0, completeCounterBIG=0, EnhancedCounterBIG=0, outputCounterBIG=0;
int objectCounter=0, completeCounter=0, EnhancedCounter=0, outputCounter=0;
for(int i=0; i<tree.getItemCount(); i++) {
TreeItem treeItem = tree.getItem(i);
ASTSliceGroup group = (ASTSliceGroup)treeItem.getData();
int x = -1;
for(ASTSlice candidate : group.getCandidates()) {

if(candidate.getType().equals("Object-State Slicing")){
objectCounter++;
x=0;
}
else if(candidate.getType().equals("Complete-Computation Slicing")){
completeCounter++;
x=1;
}
else if(candidate.getType().equals("Enhanced-Object Slicing")){
EnhancedCounter++;
x=2;
}
else if(candidate.getType().equals("Output-Based Slicing")){
outputCounter++;
x=3;
}
else{

}
out.write(candidate.toString());
out.newLine();
}
if(x==0){
objectCounterBIG++;
}
else if(x==1){
completeCounterBIG++;
}
else if(x==2){
EnhancedCounterBIG++;
}
else if(x==3){
outputCounterBIG++;
}
}
/*
out.write("ObjectSlices: " + objectCounter);
out.newLine();
out.write("CompleteSlices: " + completeCounter);
out.newLine();
out.write("EncancedSlices: " + EnhancedCounter);
out.newLine();
out.write("OutPutSlices: " + outputCounter);
out.newLine();
*/

System.out.println("ObjectSlices: " + objectCounter);
System.out.println("CompleteSlices: " + completeCounter);
System.out.println("EncancedSlices: " + EnhancedCounter);
System.out.println("OutPutSlices: " + outputCounter);

System.out.println("ObjectSlicesBIG: " + objectCounterBIG);
System.out.println("CompleteSlicesBIG: " + completeCounterBIG);
System.out.println("EncancedSlicesBIG: " + EnhancedCounterBIG);
System.out.println("OutPutSlicesBIG: " + outputCounterBIG);

out.close();
} catch (IOException e) {
e.printStackTrace();
Expand Down

0 comments on commit 517e0e5

Please sign in to comment.