本文整理汇总了Java中com.intellij.refactoring.listeners.RefactoringElementListener.elementRenamed方法的典型用法代码示例。如果您正苦于以下问题:Java RefactoringElementListener.elementRenamed方法的具体用法?Java RefactoringElementListener.elementRenamed怎么用?Java RefactoringElementListener.elementRenamed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.refactoring.listeners.RefactoringElementListener
的用法示例。
在下文中一共展示了RefactoringElementListener.elementRenamed方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doRenameXmlAttributeValue
import com.intellij.refactoring.listeners.RefactoringElementListener; //导入方法依赖的package包/类
private static void doRenameXmlAttributeValue(@NotNull XmlAttributeValue value,
String newName,
UsageInfo[] infos,
@Nullable RefactoringElementListener listener)
throws IncorrectOperationException {
LOG.assertTrue(value.isValid());
renameAll(value, infos, newName, value.getValue());
PsiManager psiManager = value.getManager();
LOG.assertTrue(psiManager != null);
XmlFile file = (XmlFile)PsiFileFactory.getInstance(psiManager.getProject()).createFileFromText("dummy.xml", XMLLanguage.INSTANCE, "<a attr=\"" + newName + "\"/>");
@SuppressWarnings("ConstantConditions")
PsiElement element = value.replace(file.getRootTag().getAttributes()[0].getValueElement());
if (listener != null) {
listener.elementRenamed(element);
}
}
示例2: doRenameXmlAttributeValue
import com.intellij.refactoring.listeners.RefactoringElementListener; //导入方法依赖的package包/类
private static void doRenameXmlAttributeValue(@NotNull XmlAttributeValue value,
String newName,
UsageInfo[] infos,
@Nullable RefactoringElementListener listener)
throws IncorrectOperationException {
LOG.assertTrue(value.isValid());
renameAll(value, infos, newName, value.getValue());
PsiManager psiManager = value.getManager();
LOG.assertTrue(psiManager != null);
XmlFile file = (XmlFile)PsiFileFactory.getInstance(psiManager.getProject()).createFileFromText("dummy.xml", "<a attr=\"" + newName + "\"/>");
final PsiElement element = value.replace(file.getDocument().getRootTag().getAttributes()[0].getValueElement());
if (listener != null) {
listener.elementRenamed(element);
}
}
示例3: getPostRenameCallback
import com.intellij.refactoring.listeners.RefactoringElementListener; //导入方法依赖的package包/类
@Nullable
public Runnable getPostRenameCallback(final PsiElement element, final String newName, final RefactoringElementListener listener) {
final Project project = element.getProject();
final PsiPackage psiPackage = (PsiPackage)element;
final String newQualifiedName = PsiUtilCore.getQualifiedNameAfterRename(psiPackage.getQualifiedName(), newName);
return new Runnable() {
public void run() {
final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(newQualifiedName);
if (aPackage == null) {
return; //rename failed e.g. when the dir is used by another app
}
listener.elementRenamed(aPackage);
}
};
}
示例4: doRenameXmlAttribute
import com.intellij.refactoring.listeners.RefactoringElementListener; //导入方法依赖的package包/类
private static void doRenameXmlAttribute(XmlAttribute attribute,
String newName,
@Nullable RefactoringElementListener listener) {
try {
final PsiElement element = attribute.setName(newName);
if (listener != null) {
listener.elementRenamed(element);
}
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
示例5: renameElement
import com.intellij.refactoring.listeners.RefactoringElementListener; //导入方法依赖的package包/类
@Override
public void renameElement(PsiElement element, String newName, UsageInfo[] usages, @Nullable RefactoringElementListener listener) throws IncorrectOperationException {
final String attributeName = ComponentUtil.getAttributeName(newName);
for (UsageInfo usage : usages) {
RenameUtil.rename(usage, attributeName);
}
((PsiNamedElement)element).setName(newName);
if (listener != null) {
listener.elementRenamed(element);
}
}
示例6: getPostRenameCallback
import com.intellij.refactoring.listeners.RefactoringElementListener; //导入方法依赖的package包/类
@Nullable
public Runnable getPostRenameCallback(final PsiElement element, final String newName, final RefactoringElementListener listener) {
final Project project = element.getProject();
final PsiJavaPackage psiPackage = (PsiJavaPackage)element;
final String newQualifiedName = PsiUtilCore.getQualifiedNameAfterRename(psiPackage.getQualifiedName(), newName);
return new Runnable() {
public void run() {
final PsiJavaPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(newQualifiedName);
if (aPackage == null) {
return; //rename failed e.g. when the dir is used by another app
}
listener.elementRenamed(aPackage);
}
};
}
示例7: execute
import com.intellij.refactoring.listeners.RefactoringElementListener; //导入方法依赖的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);
}
}