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

spoon.refactoring.Refactoring Maven / Gradle / Ivy

Go to download

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);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy