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

spoon.refactoring.CtRenameGenericVariableRefactoring Maven / Gradle / Ivy

Go to download

Spoon is a tool for meta-programming, analysis and transformation of Java programs.

There is a newer version: 11.1.1-beta-14
Show newest version
/*
 * SPDX-License-Identifier: (MIT OR CECILL-C)
 *
 * Copyright (C) 2006-2023 INRIA and contributors
 *
 * Spoon is available either under the terms of the MIT License (see LICENSE-MIT.txt) or the Cecill-C License (see LICENSE-CECILL-C.txt). You as the user are entitled to choose the terms under which to adopt Spoon.
 */
package spoon.refactoring;

import spoon.reflect.declaration.CtVariable;
import spoon.reflect.reference.CtReference;
import spoon.reflect.visitor.chain.CtConsumer;
import spoon.reflect.visitor.filter.VariableReferenceFunction;

/**
 * Spoon model that can refactor any type of variable (method parameters, local variables, field variables.
 * Provides no variable rename checking, so renaming variables to a name that already exists is possible, be wary
 * of creating incorrect code with this.
 * This class can be used as a tool for investigating code obfuscation. Useful for research purposes.
 * It has the same interface as the local variable rename:
 * 
 * new CtRenameGenericVariableRefactoring().setTarget(myVar).setNewName("myNewName").refactor();
 * 
*/ public class CtRenameGenericVariableRefactoring extends AbstractRenameRefactoring { public CtRenameGenericVariableRefactoring() { super(javaIdentifierRE); } @Override protected void refactorNoCheck() { getTarget().map(new VariableReferenceFunction()).forEach(new CtConsumer() { @Override public void accept(CtReference t) { t.setSimpleName(newName); } }); target.setSimpleName(newName); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy