gr.uom.java.xmi.diff.AddClassAnnotationRefactoring Maven / Gradle / Ivy
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.UMLAbstractClass;
import gr.uom.java.xmi.UMLAnnotation;
public class AddClassAnnotationRefactoring implements Refactoring {
private UMLAnnotation annotation;
private UMLAbstractClass classBefore;
private UMLAbstractClass classAfter;
public AddClassAnnotationRefactoring(UMLAnnotation annotation, UMLAbstractClass classBefore, UMLAbstractClass classAfter) {
this.annotation = annotation;
this.classBefore = classBefore;
this.classAfter = classAfter;
}
public UMLAnnotation getAnnotation() {
return annotation;
}
public UMLAbstractClass getClassBefore() {
return classBefore;
}
public UMLAbstractClass getClassAfter() {
return classAfter;
}
@Override
public List leftSide() {
List ranges = new ArrayList();
ranges.add(classBefore.codeRange()
.setDescription("original class declaration")
.setCodeElement(classBefore.toString()));
return ranges;
}
@Override
public List rightSide() {
List ranges = new ArrayList();
ranges.add(annotation.codeRange()
.setDescription("added annotation")
.setCodeElement(annotation.toString()));
ranges.add(classAfter.codeRange()
.setDescription("class declaration with added annotation")
.setCodeElement(classAfter.toString()));
return ranges;
}
@Override
public RefactoringType getRefactoringType() {
return RefactoringType.ADD_CLASS_ANNOTATION;
}
@Override
public String getName() {
return this.getRefactoringType().getDisplayName();
}
@Override
public Set> getInvolvedClassesBeforeRefactoring() {
Set> pairs = new LinkedHashSet>();
pairs.add(new ImmutablePair(getClassBefore().getLocationInfo().getFilePath(), getClassBefore().getName()));
return pairs;
}
@Override
public Set> getInvolvedClassesAfterRefactoring() {
Set> pairs = new LinkedHashSet>();
pairs.add(new ImmutablePair(getClassAfter().getLocationInfo().getFilePath(), getClassAfter().getName()));
return pairs;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getName()).append("\t");
sb.append(annotation);
sb.append(" in class ");
sb.append(classAfter.getName());
return sb.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((annotation == null) ? 0 : annotation.hashCode());
result = prime * result + ((classAfter == null) ? 0 : classAfter.hashCode());
result = prime * result + ((classBefore == null) ? 0 : classBefore.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;
AddClassAnnotationRefactoring other = (AddClassAnnotationRefactoring) obj;
if (annotation == null) {
if (other.annotation != null)
return false;
} else if (!annotation.equals(other.annotation))
return false;
if (classAfter == null) {
if (other.classAfter != null)
return false;
} else if (!classAfter.equals(other.classAfter))
return false;
if (classBefore == null) {
if (other.classBefore != null)
return false;
} else if (!classBefore.equals(other.classBefore))
return false;
return true;
}
}