gr.uom.java.xmi.diff.ReplaceAnonymousWithClassRefactoring 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.UMLAnonymousClass;
import gr.uom.java.xmi.UMLClass;
public class ReplaceAnonymousWithClassRefactoring implements Refactoring {
private UMLAnonymousClass anonymousClass;
private UMLClass addedClass;
private UMLAnonymousToClassDiff diff;
public ReplaceAnonymousWithClassRefactoring(UMLAnonymousClass anonymousClass, UMLClass addedClass, UMLAnonymousToClassDiff diff) {
this.anonymousClass = anonymousClass;
this.addedClass = addedClass;
this.diff = diff;
}
public UMLAnonymousClass getAnonymousClass() {
return anonymousClass;
}
public UMLClass getAddedClass() {
return addedClass;
}
public UMLAnonymousToClassDiff getDiff() {
return diff;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getName()).append("\t");
sb.append(anonymousClass.getCodePath());
sb.append(" with ");
sb.append(addedClass);
return sb.toString();
}
public String getName() {
return this.getRefactoringType().getDisplayName();
}
public RefactoringType getRefactoringType() {
return RefactoringType.REPLACE_ANONYMOUS_WITH_CLASS;
}
public Set> getInvolvedClassesBeforeRefactoring() {
Set> pairs = new LinkedHashSet>();
pairs.add(new ImmutablePair(getAnonymousClass().getLocationInfo().getFilePath(), getAnonymousClass().getName()));
return pairs;
}
public Set> getInvolvedClassesAfterRefactoring() {
Set> pairs = new LinkedHashSet>();
pairs.add(new ImmutablePair(getAddedClass().getLocationInfo().getFilePath(), getAddedClass().getName()));
return pairs;
}
@Override
public List leftSide() {
List ranges = new ArrayList();
ranges.add(anonymousClass.codeRange()
.setDescription("anonymous class declaration")
.setCodeElement(anonymousClass.getName()));
return ranges;
}
@Override
public List rightSide() {
List ranges = new ArrayList();
ranges.add(addedClass.codeRange()
.setDescription("added type declaration")
.setCodeElement(addedClass.getName()));
return ranges;
}
}