Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,11 @@ public boolean accept(Element e, TypeMirror type) {
String useThis = null;
String useSuper = null;

if (elementToFind!=null && elementToFind.getKind().isField()) {
if (elementToFind!=null && elementToFind.getKind().isField() && tree.getKind() == Tree.Kind.IDENTIFIER) {
Scope scope = workingCopy.getTrees().getScope(elementPath);
for (Element ele : scope.getLocalElements()) {
if ((ele.getKind() == ElementKind.LOCAL_VARIABLE || ele.getKind() == ElementKind.PARAMETER)
&& ele.getSimpleName().toString().equals(newName)) {
if (tree.getKind() == Tree.Kind.MEMBER_SELECT) {
String isThis = ((MemberSelectTree) tree).getExpression().toString();
if (isThis.equals("this") || isThis.endsWith(".this")) { // NOI18N
break;
}
}
if (elementToFind.getModifiers().contains(Modifier.STATIC)) {
useThis = elementToFind.getEnclosingElement().getSimpleName().toString() + ".";
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,75 @@ public void testRenamePropUndoRedo() throws Exception { // #220547

}

public void testRenameLocalVariable_1() throws Exception { // see NETBEANS-4274
writeFilesAndWaitForScan(src,
new File("t/X.java", "package t;\n"
+ "public class X {\n"
+ " private static int i;\n"
+ " public static void main(String[] args) {\n"
+ " X x = new X();\n"
+ " String newName = Integer.toString(x.i);\n"
+ " }\n"
+ "}"));
JavaRenameProperties props = new JavaRenameProperties();
performRename(src.getFileObject("t/X.java"), 1, -1, "newName", props, true);
verifyContent(src,
new File("t/X.java", "package t;\n"
+ "public class X {\n"
+ " private static int newName;\n"
+ " public static void main(String[] args) {\n"
+ " X x = new X();\n"
+ " String newName = Integer.toString(x.newName);\n"
+ " }\n"
+ "}"));
}

public void testRenameLocalVariable_2() throws Exception { // see NETBEANS-4274
writeFilesAndWaitForScan(src,
new File("t/X.java", "package t;\n"
+ "public class X {\n"
+ " private int i;\n"
+ " public static void main(String[] args) {\n"
+ " X x = new X();\n"
+ " String newName = Integer.toString(x.i);\n"
+ " }\n"
+ "}"));
JavaRenameProperties props = new JavaRenameProperties();
performRename(src.getFileObject("t/X.java"), 1, -1, "newName", props, true);
verifyContent(src,
new File("t/X.java", "package t;\n"
+ "public class X {\n"
+ " private int newName;\n"
+ " public static void main(String[] args) {\n"
+ " X x = new X();\n"
+ " String newName = Integer.toString(x.newName);\n"
+ " }\n"
+ "}"));
}

public void testRenameLocalVariable_3() throws Exception { // see NETBEANS-4274
writeFilesAndWaitForScan(src,
new File("t/X.java", "package t;\n"
+ "public class X {\n"
+ " private static int i;\n"
+ " public static void main(String[] args) {\n"
+ " X x = new X();\n"
+ " String newName = Integer.toString(i);\n"
+ " }\n"
+ "}"));
JavaRenameProperties props = new JavaRenameProperties();
performRename(src.getFileObject("t/X.java"), 1, -1, "newName", props, true);
verifyContent(src,
new File("t/X.java", "package t;\n"
+ "public class X {\n"
+ " private static int newName;\n"
+ " public static void main(String[] args) {\n"
+ " X x = new X();\n"
+ " String newName = Integer.toString(X.newName);\n"
+ " }\n"
+ "}"));
}

public void test253063() throws Exception {
writeFilesAndWaitForScan(src,
new File("t/A.java", "package t;\n"
Expand Down