本文整理汇总了Java中com.intellij.refactoring.rename.RenameUtil.doRenameGenericNamedElement方法的典型用法代码示例。如果您正苦于以下问题:Java RenameUtil.doRenameGenericNamedElement方法的具体用法?Java RenameUtil.doRenameGenericNamedElement怎么用?Java RenameUtil.doRenameGenericNamedElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.refactoring.rename.RenameUtil
的用法示例。
在下文中一共展示了RenameUtil.doRenameGenericNamedElement方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processFunctionDeclaration
import com.intellij.refactoring.rename.RenameUtil; //导入方法依赖的package包/类
private static void processFunctionDeclaration(@NotNull PyChangeInfo changeInfo, @NotNull PyFunction function) {
if (changeInfo.isParameterNamesChanged()) {
final PyParameter[] oldParameters = function.getParameterList().getParameters();
for (PyParameterInfo paramInfo: changeInfo.getNewParameters()) {
if (paramInfo.getOldIndex() >= 0 && paramInfo.isRenamed()) {
final String newName = StringUtil.trimLeading(paramInfo.getName(), '*').trim();
final UsageInfo[] usages = RenameUtil.findUsages(oldParameters[paramInfo.getOldIndex()], newName, true, false, null);
for (UsageInfo info : usages) {
RenameUtil.rename(info, newName);
}
}
}
}
if (changeInfo.isParameterSetOrOrderChanged()) {
fixDoc(changeInfo, function);
updateParameterList(changeInfo, function);
}
if (changeInfo.isNameChanged()) {
RenameUtil.doRenameGenericNamedElement(function, changeInfo.getNewName(), UsageInfo.EMPTY_ARRAY, null);
}
}
示例2: testExecute_RenameFileNoChanges
import com.intellij.refactoring.rename.RenameUtil; //导入方法依赖的package包/类
@Test
public void testExecute_RenameFileNoChanges() {
when(mockVirtualFile.getPath()).thenReturn(CURRENT_FILE_PATH);
when(CommandUtils.getStatusForFiles(mockServerContext, ImmutableList.of(CURRENT_FILE_PATH)))
.thenReturn(Collections.EMPTY_LIST);
RenameFileDirectory.execute(mockPsiFile, NEW_FILE_NAME, usageInfos, mockListener);
verifyStatic(times(1));
CommandUtils.renameFile(eq(mockServerContext), eq(CURRENT_FILE_PATH), eq(NEW_FILE_PATH));
PersistentFS.getInstance().processEvents(any(List.class));
verify(mockListener).elementRenamed(mockPsiFile);
verifyStatic(never());
RenameUtil.doRenameGenericNamedElement(any(PsiElement.class), any(String.class), any(UsageInfo[].class), any(RefactoringElementListener.class));
}
示例3: testExecute_RenameDirectoryNoChanges
import com.intellij.refactoring.rename.RenameUtil; //导入方法依赖的package包/类
@Test
public void testExecute_RenameDirectoryNoChanges() {
String dirName = Path.combine("/path/to/the", "directory");
when(mockVirtualFile.getPath()).thenReturn(dirName);
when(CommandUtils.getStatusForFiles(mockServerContext, ImmutableList.of(dirName)))
.thenReturn(Collections.EMPTY_LIST);
RenameFileDirectory.execute(mockPsiFile, NEW_DIRECTORY_NAME, usageInfos, mockListener);
verifyStatic(times(1));
CommandUtils.renameFile(eq(mockServerContext), eq(dirName), eq(Path.combine("/path/to/the", "newDirectory")));
PersistentFS.getInstance().processEvents(any(List.class));
verify(mockListener).elementRenamed(mockPsiFile);
verifyStatic(never());
RenameUtil.doRenameGenericNamedElement(any(PsiElement.class), any(String.class), any(UsageInfo[].class), any(RefactoringElementListener.class));
}
示例4: testExecute_RenameFileEditChanges
import com.intellij.refactoring.rename.RenameUtil; //导入方法依赖的package包/类
@Test
public void testExecute_RenameFileEditChanges() {
when(mockPendingChange.getChangeTypes()).thenReturn(ImmutableList.of(ServerStatusType.EDIT));
when(mockVirtualFile.getPath()).thenReturn(CURRENT_FILE_PATH);
when(CommandUtils.getStatusForFiles(mockServerContext, ImmutableList.of(CURRENT_FILE_PATH)))
.thenReturn(ImmutableList.of(mockPendingChange));
RenameFileDirectory.execute(mockPsiFile, NEW_FILE_NAME, usageInfos, mockListener);
verifyStatic(times(1));
CommandUtils.renameFile(eq(mockServerContext), eq(CURRENT_FILE_PATH), eq(NEW_FILE_PATH));
PersistentFS.getInstance().processEvents(any(List.class));
verify(mockListener).elementRenamed(mockPsiFile);
verifyStatic(never());
RenameUtil.doRenameGenericNamedElement(any(PsiElement.class), any(String.class), any(UsageInfo[].class), any(RefactoringElementListener.class));
}
示例5: testExecute_RenameFileEditRenameChanges
import com.intellij.refactoring.rename.RenameUtil; //导入方法依赖的package包/类
@Test
public void testExecute_RenameFileEditRenameChanges() {
when(mockPendingChange.getChangeTypes()).thenReturn(ImmutableList.of(ServerStatusType.EDIT, ServerStatusType.RENAME));
when(mockVirtualFile.getPath()).thenReturn(CURRENT_FILE_PATH);
when(CommandUtils.getStatusForFiles(mockServerContext, ImmutableList.of(CURRENT_FILE_PATH)))
.thenReturn(ImmutableList.of(mockPendingChange));
RenameFileDirectory.execute(mockPsiFile, NEW_FILE_NAME, usageInfos, mockListener);
verifyStatic(times(1));
CommandUtils.renameFile(eq(mockServerContext), eq(CURRENT_FILE_PATH), eq(NEW_FILE_PATH));
PersistentFS.getInstance().processEvents(any(List.class));
verify(mockListener).elementRenamed(mockPsiFile);
verifyStatic(never());
RenameUtil.doRenameGenericNamedElement(any(PsiElement.class), any(String.class), any(UsageInfo[].class), any(RefactoringElementListener.class));
}
示例6: testExecute_RenameFileUnversionedChange
import com.intellij.refactoring.rename.RenameUtil; //导入方法依赖的package包/类
@Test
public void testExecute_RenameFileUnversionedChange() {
when(mockPendingChange.getChangeTypes()).thenReturn(ImmutableList.of(ServerStatusType.ADD));
when(mockVirtualFile.getPath()).thenReturn(CURRENT_FILE_PATH);
when(CommandUtils.getStatusForFiles(mockServerContext, ImmutableList.of(CURRENT_FILE_PATH)))
.thenReturn(ImmutableList.of(mockPendingChange));
RenameFileDirectory.execute(mockPsiFile, NEW_FILE_NAME, usageInfos, mockListener);
verifyStatic(times(1));
RenameUtil.doRenameGenericNamedElement(mockPsiFile, NEW_FILE_NAME, usageInfos, mockListener);
verify(mockListener).elementRenamed(mockPsiFile);
verifyStatic(never());
CommandUtils.renameFile(any(ServerContext.class), any(String.class), any(String.class));
PersistentFS.getInstance().processEvents(any(List.class));
}
示例7: processUsage
import com.intellij.refactoring.rename.RenameUtil; //导入方法依赖的package包/类
@Override
public boolean processUsage(final ChangeInfo changeInfo,
UsageInfo usageInfo,
boolean beforeMethodChange,
final UsageInfo[] usages) {
if (!isPythonUsage(usageInfo)) return false;
if (!(changeInfo instanceof PyChangeInfo)) return false;
if (!beforeMethodChange) return false;
PsiElement element = usageInfo.getElement();
if (changeInfo.isNameChanged()) {
final PsiElement method = changeInfo.getMethod();
RenameUtil.doRenameGenericNamedElement(method, changeInfo.getNewName(), usages, null);
}
if (element == null) return false;
if (element.getParent() instanceof PyCallExpression) {
final PyCallExpression call = (PyCallExpression)element.getParent();
final PyArgumentList argumentList = call.getArgumentList();
if (argumentList != null) {
final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(element.getProject());
StringBuilder builder = buildSignature((PyChangeInfo)changeInfo, call);
final PyExpression newCall;
if (call instanceof PyDecorator) {
newCall = elementGenerator.createDecoratorList("@" + builder.toString()).getDecorators()[0];
}
else
newCall = elementGenerator.createExpressionFromText(LanguageLevel.forElement(element), builder.toString());
call.replace(newCall);
return true;
}
}
else if (element instanceof PyFunction) {
processFunctionDeclaration((PyChangeInfo)changeInfo, (PyFunction)element);
}
return false;
}
示例8: execute
import com.intellij.refactoring.rename.RenameUtil; //导入方法依赖的package包/类
public static void execute(final PsiElement element, final String newName, final UsageInfo[] usages,
@Nullable final RefactoringElementListener listener) throws IncorrectOperationException {
try {
final VirtualFile virtualFile;
if (element instanceof PsiFile) {
logger.info("Renaming file...");
virtualFile = ((PsiFile) element).getVirtualFile();
} else if (element instanceof PsiDirectory) {
logger.info("Renaming directory...");
virtualFile = ((PsiDirectory) element).getVirtualFile();
} else {
// should never reach here since we check if file/directory before making a rename
logger.warn("RenameFile: failed to find proper object to rename: " + element.getClass());
throw new IncorrectOperationException("Can't perform rename on objects other than files and directories");
}
final String currentPath = virtualFile.getPath();
final String parentDirectory = virtualFile.getParent().getPath();
final String newPath = Path.combine(parentDirectory, newName);
final Project project = element.getProject();
// a single file may have 0, 1, or 2 pending changes to it
// 0 - file has not been touched in the local workspace
// 1 - file has versioned OR unversioned changes
// 2 - file has versioned AND unversioned changes (rare but can happen)
final List<PendingChange> pendingChanges = new ArrayList<PendingChange>(2);
pendingChanges.addAll(CommandUtils.getStatusForFiles(TFSVcs.getInstance(project).getServerContext(true),
ImmutableList.of(currentPath)));
// ** Rename logic **
// If 1 change and it's an add that means it's a new unversioned file so rename thru the file system
// Anything else can be renamed
// Deleted files should not be at this point since IDE disables rename option for them
if (pendingChanges.size() == 1 && pendingChanges.get(0).getChangeTypes().contains(ServerStatusType.ADD)) {
logger.info("Renaming unversioned file thru file system");
RenameUtil.doRenameGenericNamedElement(element, newName, usages, listener);
} else {
logger.info("Renaming file thru tf commandline");
CommandUtils.renameFile(TFSVcs.getInstance(project).getServerContext(true), currentPath, newPath);
// this alerts that a rename has taken place so any additional processing can take place
final VFileEvent event = new VFilePropertyChangeEvent(element.getManager(), virtualFile, "name", currentPath, newName, false);
PersistentFS.getInstance().processEvents(Collections.singletonList(event));
}
} catch (Throwable t) {
logger.warn("renameElement experienced a failure while trying to rename a file", t);
throw new IncorrectOperationException(t);
}
if (listener != null) {
listener.elementRenamed(element);
}
}