RenameFileActionPlugin extends AbstractPlugin<RenameRefactoring> { protected static String replaceNameInPath(int pathItemIndexFromEnd, final String path, final String newName) { int foldersInNewName = numberOfFolders(newName); final String normalizedSeparators = FilenameUtils.separatorsToUnix(path); int start = normalizedSeparators.length(); while (start >= 0 && pathItemIndexFromEnd >= 0) { start = normalizedSeparators.lastIndexOf('/', start - 1); pathItemIndexFromEnd--; } String result = path; if (start >= 0) { final int indexEnd = normalizedSeparators.indexOf('/', start + 1); while (start >= 0 && foldersInNewName > 0) { start = normalizedSeparators.lastIndexOf('/', start - 1); foldersInNewName--; } if (start >= 0) { if (indexEnd <= 0) { result = path.substring(0, start + 1) + newName; } else { result = path.substring(0, start + 1) + newName + path.substring(indexEnd); } } } return result; } RenameFileActionPlugin(final RenameRefactoring refactoring); @Override Problem checkParameters(); @Override Problem fastCheckParameters();  }
@Test public void testSomeMethod() { assertEquals("/hello",RenameFileActionPlugin.replaceNameInPath(0, "/", "hello")); assertEquals("/hello/world",RenameFileActionPlugin.replaceNameInPath(1, "/gala/world", "hello")); assertEquals("smart/est/hello/world",RenameFileActionPlugin.replaceNameInPath(2, "smart/homo/hello/world", "est")); assertEquals("c:\\smartest\\est\\hello\\world.txt",RenameFileActionPlugin.replaceNameInPath(2, "c:\\smartest\\lskjdflkdsjfwioeqwoieqwlkdlkd\\hello\\world.txt", "est")); assertEquals("zomby",RenameFileActionPlugin.replaceNameInPath(2, "zomby", "est")); assertEquals("",RenameFileActionPlugin.replaceNameInPath(0, "", "est")); assertEquals("/hello/world/test.txt",RenameFileActionPlugin.replaceNameInPath(1, "/hello/some/test.txt", "world")); assertEquals("/aha/world/test.txt",RenameFileActionPlugin.replaceNameInPath(1, "/hello/some/test.txt", "aha/world")); assertEquals("/hello/aha/world1/test.txt",RenameFileActionPlugin.replaceNameInPath(1, "/hello/aha/world/test.txt", "aha/world1")); }