gr.uom.java.xmi.diff.ExtractClassRefactoring 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.UMLAttribute;
import gr.uom.java.xmi.UMLClass;
import gr.uom.java.xmi.UMLOperation;
public class ExtractClassRefactoring implements Refactoring {
private UMLClass extractedClass;
private UMLClassBaseDiff classDiff;
private Set extractedOperations;
private Set extractedAttributes;
private UMLAttribute attributeOfExtractedClassTypeInOriginalClass;
public ExtractClassRefactoring(UMLClass extractedClass, UMLClassBaseDiff classDiff,
Set extractedOperations, Set extractedAttributes, UMLAttribute attributeOfExtractedClassType) {
this.extractedClass = extractedClass;
this.classDiff = classDiff;
this.extractedOperations = extractedOperations;
this.extractedAttributes = extractedAttributes;
this.attributeOfExtractedClassTypeInOriginalClass = attributeOfExtractedClassType;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getName()).append("\t");
sb.append(extractedClass);
sb.append(" from class ");
sb.append(classDiff.getOriginalClass());
return sb.toString();
}
public RefactoringType getRefactoringType() {
if(extractedClass.isSubTypeOf(classDiff.getOriginalClass()) || extractedClass.isSubTypeOf(classDiff.getNextClass()))
return RefactoringType.EXTRACT_SUBCLASS;
return RefactoringType.EXTRACT_CLASS;
}
public String getName() {
return this.getRefactoringType().getDisplayName();
}
public UMLClass getExtractedClass() {
return extractedClass;
}
public UMLClass getOriginalClass() {
return classDiff.getOriginalClass();
}
public Set getExtractedOperations() {
return extractedOperations;
}
public Set getExtractedAttributes() {
return extractedAttributes;
}
public UMLAttribute getAttributeOfExtractedClassTypeInOriginalClass() {
return attributeOfExtractedClassTypeInOriginalClass;
}
public Set> getInvolvedClassesBeforeRefactoring() {
Set> pairs = new LinkedHashSet>();
pairs.add(new ImmutablePair(getOriginalClass().getLocationInfo().getFilePath(), getOriginalClass().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();
ranges.add(classDiff.getOriginalClass().codeRange()
.setDescription("original type declaration")
.setCodeElement(classDiff.getOriginalClass().getName()));
return ranges;
}
@Override
public List rightSide() {
List ranges = new ArrayList();
ranges.add(extractedClass.codeRange()
.setDescription("extracted type declaration")
.setCodeElement(extractedClass.getName()));
return ranges;
}
}