spoon.refactoring.Refactoring Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spoon-core Show documentation
Show all versions of spoon-core Show documentation
Spoon is a tool for meta-programming, analysis and transformation of Java programs.
The newest version!
package spoon.refactoring;
import spoon.reflect.declaration.CtType;
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.visitor.Query;
import spoon.reflect.visitor.filter.AbstractReferenceFilter;
import java.util.List;
/**
* Contains all methods to refactor code elements in the AST.
*/
public final class Refactoring {
/**
* Changes name of a type element.
*
* @param type
* Type in the AST.
* @param name
* New name of the element.
*/
public static void changeTypeName(final CtType> type, String name) {
final List> references = Query.getReferences(type.getFactory(), new AbstractReferenceFilter>(CtTypeReference.class) {
@Override
public boolean matches(CtTypeReference> reference) {
return type.getQualifiedName().equals(reference.getQualifiedName());
}
});
type.setSimpleName(name);
for (CtTypeReference> reference : references) {
reference.setSimpleName(name);
}
}
}