gr.uom.java.xmi.diff.ModifyVariableAnnotationRefactoring Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of refactoring-miner Show documentation
Show all versions of refactoring-miner Show documentation
RefactoringMiner is a library/API written in Java that can detect refactorings applied in the history of a Java project.
package gr.uom.java.xmi.diff;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.refactoringminer.api.Refactoring;
import org.refactoringminer.api.RefactoringType;
import gr.uom.java.xmi.UMLAnnotation;
import gr.uom.java.xmi.UMLOperation;
import gr.uom.java.xmi.decomposition.VariableDeclaration;
public class ModifyVariableAnnotationRefactoring implements Refactoring {
private UMLAnnotation annotationBefore;
private UMLAnnotation annotationAfter;
private VariableDeclaration variableBefore;
private VariableDeclaration variableAfter;
private UMLOperation operationBefore;
private UMLOperation operationAfter;
public ModifyVariableAnnotationRefactoring(UMLAnnotation annotationBefore, UMLAnnotation annotationAfter,
VariableDeclaration variableBefore, VariableDeclaration variableAfter, UMLOperation operationBefore,
UMLOperation operationAfter) {
this.annotationBefore = annotationBefore;
this.annotationAfter = annotationAfter;
this.variableBefore = variableBefore;
this.variableAfter = variableAfter;
this.operationBefore = operationBefore;
this.operationAfter = operationAfter;
}
public UMLAnnotation getAnnotationBefore() {
return annotationBefore;
}
public UMLAnnotation getAnnotationAfter() {
return annotationAfter;
}
public VariableDeclaration getVariableBefore() {
return variableBefore;
}
public VariableDeclaration getVariableAfter() {
return variableAfter;
}
public UMLOperation getOperationBefore() {
return operationBefore;
}
public UMLOperation getOperationAfter() {
return operationAfter;
}
@Override
public List leftSide() {
List ranges = new ArrayList();
ranges.add(annotationBefore.codeRange()
.setDescription("original annotation")
.setCodeElement(annotationBefore.toString()));
ranges.add(variableBefore.codeRange()
.setDescription("original variable declaration")
.setCodeElement(variableBefore.toString()));
return ranges;
}
@Override
public List rightSide() {
List ranges = new ArrayList();
ranges.add(annotationAfter.codeRange()
.setDescription("modified annotation")
.setCodeElement(annotationAfter.toString()));
ranges.add(variableAfter.codeRange()
.setDescription("variable declaration with modified annotation")
.setCodeElement(variableAfter.toString()));
return ranges;
}
@Override
public RefactoringType getRefactoringType() {
if(variableBefore.isParameter() && variableAfter.isParameter())
return RefactoringType.MODIFY_PARAMETER_ANNOTATION;
return null;
}
@Override
public String getName() {
return this.getRefactoringType().getDisplayName();
}
@Override
public Set> getInvolvedClassesBeforeRefactoring() {
Set> pairs = new LinkedHashSet>();
pairs.add(new ImmutablePair(getOperationBefore().getLocationInfo().getFilePath(), getOperationBefore().getClassName()));
return pairs;
}
@Override
public Set> getInvolvedClassesAfterRefactoring() {
Set> pairs = new LinkedHashSet>();
pairs.add(new ImmutablePair(getOperationAfter().getLocationInfo().getFilePath(), getOperationAfter().getClassName()));
return pairs;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getName()).append("\t");
sb.append(annotationBefore);
sb.append(" to ");
sb.append(annotationAfter);
if(variableAfter.isParameter())
sb.append(" in parameter ");
sb.append(variableAfter);
sb.append(" in method ");
sb.append(operationAfter);
sb.append(" from class ");
sb.append(operationAfter.getClassName());
return sb.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((annotationAfter == null) ? 0 : annotationAfter.hashCode());
result = prime * result + ((annotationBefore == null) ? 0 : annotationBefore.hashCode());
result = prime * result + ((operationAfter == null) ? 0 : operationAfter.hashCode());
result = prime * result + ((operationBefore == null) ? 0 : operationBefore.hashCode());
result = prime * result + ((variableAfter == null) ? 0 : variableAfter.hashCode());
result = prime * result + ((variableBefore == null) ? 0 : variableBefore.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ModifyVariableAnnotationRefactoring other = (ModifyVariableAnnotationRefactoring) obj;
if (annotationAfter == null) {
if (other.annotationAfter != null)
return false;
} else if (!annotationAfter.equals(other.annotationAfter))
return false;
if (annotationBefore == null) {
if (other.annotationBefore != null)
return false;
} else if (!annotationBefore.equals(other.annotationBefore))
return false;
if (operationAfter == null) {
if (other.operationAfter != null)
return false;
} else if (!operationAfter.equals(other.operationAfter))
return false;
if (operationBefore == null) {
if (other.operationBefore != null)
return false;
} else if (!operationBefore.equals(other.operationBefore))
return false;
if (variableAfter == null) {
if (other.variableAfter != null)
return false;
} else if (!variableAfter.equals(other.variableAfter))
return false;
if (variableBefore == null) {
if (other.variableBefore != null)
return false;
} else if (!variableBefore.equals(other.variableBefore))
return false;
return true;
}
}