gr.uom.java.xmi.diff.ExtractSuperclassRefactoring 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 gr.uom.java.xmi.UMLClass;
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;
public class ExtractSuperclassRefactoring implements Refactoring {
private UMLClass extractedClass;
private Set subclassSet;
public ExtractSuperclassRefactoring(UMLClass extractedClass, Set subclassSet) {
this.extractedClass = extractedClass;
this.subclassSet = subclassSet;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getName()).append("\t");
sb.append(extractedClass);
sb.append(" from classes ");
sb.append(subclassSet);
return sb.toString();
}
public String getName() {
return this.getRefactoringType().getDisplayName();
}
public RefactoringType getRefactoringType() {
if(extractedClass.isInterface())
return RefactoringType.EXTRACT_INTERFACE;
else
return RefactoringType.EXTRACT_SUPERCLASS;
}
public UMLClass getExtractedClass() {
return extractedClass;
}
public Set getSubclassSet() {
Set subclassSet = new LinkedHashSet();
for(UMLClass umlClass : this.subclassSet) {
subclassSet.add(umlClass.getName());
}
return subclassSet;
}
public Set getUMLSubclassSet() {
return new LinkedHashSet(subclassSet);
}
public Set> getInvolvedClassesBeforeRefactoring() {
Set> pairs = new LinkedHashSet>();
for(UMLClass umlClass : this.subclassSet) {
pairs.add(new ImmutablePair(umlClass.getLocationInfo().getFilePath(), umlClass.getName()));
}
return pairs;
}
public Set> getInvolvedClassesAfterRefactoring() {
Set> pairs = new LinkedHashSet>();
pairs.add(new ImmutablePair(getExtractedClass().getLocationInfo().getFilePath(), getExtractedClass().getName()));
return pairs;
}
@Override
public List leftSide() {
List ranges = new ArrayList();
for(UMLClass subclass : subclassSet) {
ranges.add(subclass.codeRange()
.setDescription("sub-type declaration")
.setCodeElement(subclass.getName()));
}
return ranges;
}
@Override
public List rightSide() {
List ranges = new ArrayList();
ranges.add(extractedClass.codeRange()
.setDescription("extracted super-type declaration")
.setCodeElement(extractedClass.getName()));
return ranges;
}
}