-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpoonVariableRenamer.java
More file actions
47 lines (43 loc) · 1.62 KB
/
SpoonVariableRenamer.java
File metadata and controls
47 lines (43 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SpoonVariableRenamer.java - Processor for renaming variables with Spoon
*
* Author: Vaibhav-api-code
* Co-Author: Claude Code (https://claude.ai/code)
* Created: 2025-07-08
* Updated: 2025-07-23
* License: Mozilla Public License 2.0 (MPL-2.0)
*/
import spoon.processing.AbstractProcessor;
import spoon.reflect.code.CtLocalVariable;
import spoon.reflect.code.CtVariableRead;
import spoon.reflect.code.CtVariableWrite;
import spoon.reflect.declaration.CtVariable;
import spoon.reflect.reference.CtVariableReference;
import spoon.reflect.declaration.CtParameter;
import spoon.reflect.declaration.CtField;
public class SpoonVariableRenamer extends AbstractProcessor<CtVariableReference<?>> {
private final CtVariable<?> targetVariable;
private final String newName;
private int renameCount = 0;
public SpoonVariableRenamer(CtVariable<?> targetVariable, String newName) {
this.targetVariable = targetVariable;
this.newName = newName;
}
@Override
public void process(CtVariableReference<?> variableRef) {
// Check if this reference points to our target variable
if (variableRef.getDeclaration() != null &&
variableRef.getDeclaration().equals(targetVariable)) {
// Rename the reference
variableRef.setSimpleName(newName);
renameCount++;
}
}
public int getRenameCount() {
return renameCount;
}
}