Skip to content

Commit

Permalink
Cleaning2
Browse files Browse the repository at this point in the history
  • Loading branch information
Alireza-Ardalani committed Jul 10, 2022
1 parent 391ada2 commit 2c29d31
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 234 deletions.
190 changes: 1 addition & 189 deletions src/gr/uom/java/ast/decomposition/MethodBodyObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -627,195 +627,7 @@ else if(statement instanceof EmptyStatement) {
parent.addStatement(child);
}
}
/*
private void processExpression(AbstractMethodFragment parent, Expression expression) {
if(expression instanceof MethodInvocation) {
MethodInvocation methodInvocation = (MethodInvocation)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.METHOD_INVOCATION, parent);
parent.addExpression(parentExpression);
if(methodInvocation.getExpression() != null)
processExpression(parentExpression, methodInvocation.getExpression());
List<Expression> arguments = methodInvocation.arguments();
for(Expression argument : arguments)
processExpression(parentExpression, argument);
}
else if(expression instanceof Assignment) {
Assignment assignment = (Assignment)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.ASSIGNMENT, parent);
parent.addExpression(parentExpression);
processExpression(parentExpression, assignment.getLeftHandSide());
processExpression(parentExpression, assignment.getRightHandSide());
}
else if(expression instanceof CastExpression) {
CastExpression castExpression = (CastExpression)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.CAST, parent);
parent.addExpression(parentExpression);
processExpression(parentExpression, castExpression.getExpression());
}
else if(expression instanceof ClassInstanceCreation) {
ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.CLASS_INSTANCE_CREATION, parent);
parent.addExpression(parentExpression);
if(classInstanceCreation.getExpression() != null)
processExpression(parentExpression, classInstanceCreation.getExpression());
List<Expression> arguments = classInstanceCreation.arguments();
for(Expression argument : arguments)
processExpression(parentExpression, argument);
AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
if(anonymousClassDeclaration != null) {
processExpression(parentExpression, anonymousClassDeclaration);
}
}
else if(expression instanceof ConditionalExpression) {
ConditionalExpression conditionalExpression = (ConditionalExpression)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.CONDITIONAL, parent);
parent.addExpression(parentExpression);
processExpression(parentExpression, conditionalExpression.getExpression());
processExpression(parentExpression, conditionalExpression.getThenExpression());
processExpression(parentExpression, conditionalExpression.getElseExpression());
}
else if(expression instanceof FieldAccess) {
FieldAccess fieldAccess = (FieldAccess)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.FIELD_ACCESS, parent);
parent.addExpression(parentExpression);
processExpression(parentExpression, fieldAccess.getExpression());
processExpression(parentExpression, fieldAccess.getName());
}
else if(expression instanceof InfixExpression) {
InfixExpression infixExpression = (InfixExpression)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.INFIX, parent);
parent.addExpression(parentExpression);
processExpression(parentExpression, infixExpression.getLeftOperand());
processExpression(parentExpression, infixExpression.getRightOperand());
List<Expression> extendedOperands = infixExpression.extendedOperands();
for(Expression operand : extendedOperands)
processExpression(parentExpression, operand);
}
else if(expression instanceof InstanceofExpression) {
InstanceofExpression instanceofExpression = (InstanceofExpression)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.INSTANCE_OF, parent);
parent.addExpression(parentExpression);
processExpression(parentExpression, instanceofExpression.getLeftOperand());
}
else if(expression instanceof ParenthesizedExpression) {
ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.PARENTHESIZED, parent);
parent.addExpression(parentExpression);
processExpression(parentExpression, parenthesizedExpression.getExpression());
}
else if(expression instanceof PostfixExpression) {
PostfixExpression postfixExpression = (PostfixExpression)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.POSTFIX, parent);
parent.addExpression(parentExpression);
processExpression(parentExpression, postfixExpression.getOperand());
}
else if(expression instanceof PrefixExpression) {
PrefixExpression prefixExpression = (PrefixExpression)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.PREFIX, parent);
parent.addExpression(parentExpression);
processExpression(parentExpression, prefixExpression.getOperand());
}
else if(expression instanceof SuperMethodInvocation) {
SuperMethodInvocation superMethodInvocation = (SuperMethodInvocation)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.SUPER_METHOD_INVOCATION, parent);
parent.addExpression(parentExpression);
List<Expression> arguments = superMethodInvocation.arguments();
for(Expression argument : arguments)
processExpression(parentExpression, argument);
}
else if(expression instanceof VariableDeclarationExpression) {
VariableDeclarationExpression variableDeclarationExpression = (VariableDeclarationExpression)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.VARIABLE_DECLARATION, parent);
parent.addExpression(parentExpression);
List<VariableDeclarationFragment> fragments = variableDeclarationExpression.fragments();
for(VariableDeclarationFragment fragment : fragments) {
Expression nameExpression = fragment.getName();
processExpression(parentExpression, nameExpression);
Expression initializerExpression = fragment.getInitializer();
processExpression(parentExpression, initializerExpression);
}
}
else if(expression instanceof ArrayAccess) {
ArrayAccess arrayAccess = (ArrayAccess)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.ARRAY_ACCESS, parent);
parent.addExpression(parentExpression);
processExpression(parentExpression, arrayAccess.getArray());
processExpression(parentExpression, arrayAccess.getIndex());
}
else if(expression instanceof ArrayCreation) {
ArrayCreation arrayCreation = (ArrayCreation)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.ARRAY_CREATION, parent);
parent.addExpression(parentExpression);
List<Expression> dimensions = arrayCreation.dimensions();
for(Expression dimension : dimensions)
processExpression(parentExpression, dimension);
processExpression(parentExpression, arrayCreation.getInitializer());
}
else if(expression instanceof ArrayInitializer) {
ArrayInitializer arrayInitializer = (ArrayInitializer)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.ARRAY_INITIALIZER, parent);
parent.addExpression(parentExpression);
List<Expression> expressions = arrayInitializer.expressions();
for(Expression arrayInitializerExpression : expressions)
processExpression(parentExpression, arrayInitializerExpression);
}
else if(expression instanceof SimpleName) {
SimpleName simpleName = (SimpleName)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.SIMPLE_NAME, parent);
parent.addExpression(parentExpression);
}
else if(expression instanceof QualifiedName) {
QualifiedName qualifiedName = (QualifiedName)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.QUALIFIED_NAME, parent);
parent.addExpression(parentExpression);
processExpression(parentExpression, qualifiedName.getQualifier());
processExpression(parentExpression, qualifiedName.getName());
}
else if(expression instanceof SuperFieldAccess) {
SuperFieldAccess superFieldAccess = (SuperFieldAccess)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.SUPER_FIELD_ACCESS, parent);
parent.addExpression(parentExpression);
processExpression(parentExpression, superFieldAccess.getName());
}
else if(expression instanceof ThisExpression) {
ThisExpression thisExpression = (ThisExpression)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.THIS, parent);
parent.addExpression(parentExpression);
if(thisExpression.getQualifier() != null)
processExpression(parentExpression, thisExpression.getQualifier());
}
else if(expression instanceof TypeLiteral) {
//TypeLiteral typeLiteral = (TypeLiteral)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.TYPE_LITERAL, parent);
parent.addExpression(parentExpression);
}
else if(expression instanceof StringLiteral) {
//StringLiteral stringLiteral = (StringLiteral)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.STRING_LITERAL, parent);
parent.addExpression(parentExpression);
}
else if(expression instanceof NullLiteral) {
//NullLiteral nullLiteral = (NullLiteral)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.NULL_LITERAL, parent);
parent.addExpression(parentExpression);
}
else if(expression instanceof NumberLiteral) {
//NumberLiteral numberLiteral = (NumberLiteral)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.NUMBER_LITERAL, parent);
parent.addExpression(parentExpression);
}
else if(expression instanceof BooleanLiteral) {
//BooleanLiteral booleanLiteral = (BooleanLiteral)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.BOOLEAN_LITERAL, parent);
parent.addExpression(parentExpression);
}
else if(expression instanceof CharacterLiteral) {
//CharacterLiteral characterLiteral = (CharacterLiteral)expression;
AbstractExpression parentExpression = new AbstractExpression(expression, ExpressionType.CHARACTER_LITERAL, parent);
parent.addExpression(parentExpression);
}
}
*/


public List<TryStatementObject> getTryStatements() {
return compositeStatement.getTryStatements();
Expand Down
104 changes: 98 additions & 6 deletions src/gr/uom/java/ast/decomposition/cfg/PDGSliceUnion.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package gr.uom.java.ast.decomposition.cfg;

import gr.uom.java.ast.AbstractMethodDeclaration;
import gr.uom.java.ast.VariableDeclarationObject;
import gr.uom.java.jdeodorant.preferences.PreferenceConstants;
import gr.uom.java.jdeodorant.refactoring.Activator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.core.dom.Assignment;
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.ExpressionStatement;
import org.eclipse.jdt.core.dom.Statement;
import org.eclipse.jdt.core.dom.VariableDeclaration;
import org.eclipse.jface.preference.IPreferenceStore;

Expand Down Expand Up @@ -613,9 +619,96 @@ public boolean variableCriterionIsFainal(){
}
return false;
}

public List<AbstractVariable> getVariablesInSlice(){
List<AbstractVariable> usedAndDefVariableInSlice = new ArrayList<AbstractVariable>();
for(GraphNode node : sliceNodes){
PDGNode pdgNode = (PDGNode)node;
Iterator<AbstractVariable> usedVariableIterator = pdgNode.getUsedVariableIterator();
while(usedVariableIterator.hasNext()){
AbstractVariable variable = usedVariableIterator.next();
if(usedAndDefVariableInSlice.isEmpty()){
usedAndDefVariableInSlice.add(variable);
}
else{
boolean existVariable = false;
for(AbstractVariable variableInList : usedAndDefVariableInSlice ){
if(variableInList.equals(variable)){
existVariable = true;
break;
}
}
if(!existVariable){
usedAndDefVariableInSlice.add(variable);
}
}
}
Iterator<AbstractVariable> defVariableIterator = pdgNode.getDefinedVariableIterator();

while(defVariableIterator.hasNext()){
AbstractVariable variable = defVariableIterator.next();
if(usedAndDefVariableInSlice.isEmpty()){
usedAndDefVariableInSlice.add(variable);
}
else{
boolean existVariable = false;
for(AbstractVariable variableInList : usedAndDefVariableInSlice ){
if(variableInList.equals(variable)){
existVariable = true;
break;
}
}
if(!existVariable){
usedAndDefVariableInSlice.add(variable);
}
}
}

}
return usedAndDefVariableInSlice;
}

public boolean notInitializedParameter(){
List<AbstractVariable> VariablesInSlice = new ArrayList<AbstractVariable>();
List<AbstractVariable> notInitializeVariables = new ArrayList<AbstractVariable>();
VariablesInSlice = getVariablesInSlice();
for(AbstractVariable variable : VariablesInSlice){
if(!variable.isParameter()){
if(!declaredVariableInSlice(variable)){
notInitializeVariables.add(variable);
}
}
}
if(notInitializeVariables.isEmpty()){
return false;
}
else{
for(AbstractVariable variable : notInitializeVariables){
for(GraphNode node : pdg.nodes){
PDGNode pdgNode = (PDGNode)node;
if(pdgNode.declaresLocalVariable(variable)){
if(pdgNode.getStatement().getLiterals().isEmpty()){
return true;
}
}
}

}
}
return false;
}
public boolean declaredVariableInSlice(AbstractVariable variable) {
for(GraphNode node : sliceNodes){
PDGNode pdgNode = (PDGNode)node;
if(pdgNode.declaresLocalVariable(variable)){
return true;
}
}

return false;
}

public boolean satisfiesRules() {

if(sliceEqualsMethodBody() || sliceContainsOnlyOneNodeCriterionAndDeclarationOfVariableCriterion() ||
declarationOfVariableCriterionIsDuplicated() ||
variableCriterionIsReturnedVariableInOriginalMethod() || (sliceNodes.size() <= nodeCriteria.size()) ||
Expand All @@ -632,14 +725,13 @@ public boolean satisfiesRules() {


public boolean satisfiesRulesSRP() {
if(sliceEqualsMethodBody() || sliceSameAsOrginalMethod() || outputRule() ||
sliceContainsOnlyOneNodeCriterionAndDeclarationOfVariableCriterion() ||
sliceNodes.size() <= nodeCriteria.size() ||
allNodeCriteriaAreDuplicated() || variableCriterionIsFainal() ||
if( sliceSameAsOrginalMethod() || notInitializedParameter() || outputRule() || variableCriterionIsFainal() ||
sliceContainsOnlyOneNodeCriterionAndDeclarationOfVariableCriterion() ||sliceEqualsMethodBody() ||
sliceNodes.size() <= nodeCriteria.size() || notInitializedParameter() ||
allNodeCriteriaAreDuplicated() ||
nonDuplicatedSliceNodeAntiDependsOnNonRemovableNode() ||
nonDuplicatedSliceNodeOutputDependsOnNonRemovableNode() ||
containsDuplicateNodeWithStateChangingMethodInvocation() ||
nonDuplicatedSliceNodeOutputDependsOnNonRemovableNode() ||
duplicatedSliceNodeWithClassInstantiationHasDependenceOnRemovableNode() ||
!complyWithUserThresholds() || sliceContainsReturnStatement() ||
sliceContainsBranchStatementWithoutInnermostLoop())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,45 +511,7 @@ public void run() {
saveResultsAction.setToolTipText("Save Results");
saveResultsAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
getImageDescriptor(ISharedImages.IMG_ETOOL_SAVE_EDIT));
saveResultsAction.setEnabled(false);

/*evolutionAnalysisAction = new Action() {
public void run() {
methodEvolution = null;
IStructuredSelection selection = (IStructuredSelection)treeViewer.getSelection();
if(selection.getFirstElement() instanceof ASTSlice) {
final ASTSlice slice = (ASTSlice)selection.getFirstElement();
try {
IWorkbench wb = PlatformUI.getWorkbench();
IProgressService ps = wb.getProgressService();
ps.busyCursorWhile(new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
ProjectEvolution projectEvolution = new ProjectEvolution(selectedProject);
if(projectEvolution.getProjectEntries().size() > 1) {
methodEvolution = new MethodEvolution(projectEvolution, (IMethod)slice.getSourceMethodDeclaration().resolveBinding().getJavaElement(), monitor);
}
}
});
if(methodEvolution != null) {
EvolutionDialog dialog = new EvolutionDialog(getSite().getWorkbenchWindow(), methodEvolution, "Method Evolution", false);
dialog.open();
}
else
MessageDialog.openInformation(getSite().getShell(), "Method Evolution",
"Method evolution analysis cannot be performed, since only a single version of the examined project is loaded in the workspace.");
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
evolutionAnalysisAction.setToolTipText("Evolution Analysis");
evolutionAnalysisAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
getImageDescriptor(ISharedImages.IMG_OBJ_ELEMENT));
evolutionAnalysisAction.setEnabled(false);*/

saveResultsAction.setEnabled(false);
applyRefactoringAction = new Action() {
public void run() {
IStructuredSelection selection = (IStructuredSelection)treeViewer.getSelection();
Expand Down

0 comments on commit 2c29d31

Please sign in to comment.