All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gr.uom.java.xmi.diff.ReplaceAttributeRefactoring 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.refactoringminer.api.RefactoringType;

import gr.uom.java.xmi.UMLAttribute;
import gr.uom.java.xmi.decomposition.AbstractCodeMapping;

public class ReplaceAttributeRefactoring extends MoveAttributeRefactoring implements ReferenceBasedRefactoring {
	private Set attributeRenames;
	
	public ReplaceAttributeRefactoring(UMLAttribute originalAttribute, UMLAttribute movedAttribute,
			Set attributeRenames) {
		super(originalAttribute, movedAttribute);
		this.attributeRenames = attributeRenames;
	}

	public Set getReferences() {
		Set references = new LinkedHashSet();
		for(CandidateAttributeRefactoring candidate : attributeRenames) {
			references.addAll(candidate.getReferences());
		}
		return references;
	}

	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(getName()).append("\t");
		sb.append(originalAttribute.toQualifiedString());
		sb.append(" from class ");
		sb.append(getSourceClassName());
		sb.append(" with ");
		sb.append(movedAttribute.toQualifiedString());
		sb.append(" from class ");
		sb.append(getTargetClassName());
		return sb.toString();
	}

	public String getName() {
		return this.getRefactoringType().getDisplayName();
	}

	public RefactoringType getRefactoringType() {
		return RefactoringType.REPLACE_ATTRIBUTE;
	}

	@Override
	public List rightSide() {
		List ranges = new ArrayList();
		ranges.add(movedAttribute.codeRange()
				.setDescription("replaced attribute declaration")
				.setCodeElement(movedAttribute.toString()));
		return ranges;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy