本文整理汇总了Java中com.intellij.refactoring.RefactoringFactory类的典型用法代码示例。如果您正苦于以下问题:Java RefactoringFactory类的具体用法?Java RefactoringFactory怎么用?Java RefactoringFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RefactoringFactory类属于com.intellij.refactoring包,在下文中一共展示了RefactoringFactory类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTest
import com.intellij.refactoring.RefactoringFactory; //导入依赖的package包/类
private void doTest() throws Exception {
final String filename = getTestName(true) + ".xml";
VirtualFile vfile = VirtualFileManager.getInstance().findFileByUrl("file://" + getTestDataPath() + filename);
String text = FileDocumentManager.getInstance().getDocument(vfile).getText();
final int off = text.indexOf("<ren>");
text = text.replace("<ren>", "");
configureFromFileText(filename, text);
assertNotNull(myFile);
PsiElement element = TargetElementUtil.getInstance().findTargetElement(
getEditor(),
TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtil.ELEMENT_NAME_ACCEPTED,
off);
assertNotNull(element);
assertTrue(element instanceof PsiNamedElement);
final RenameRefactoring rename =
RefactoringFactory.getInstance(getProject()).createRename(element, ((PsiNamedElement)element).getName() + "-after");
rename.setSearchInComments(false);
rename.setSearchInNonJavaFiles(false);
rename.run();
checkResultByFile(filename + "-after");
}
示例2: doFix
import com.intellij.refactoring.RefactoringFactory; //导入依赖的package包/类
@Override
public void doFix(final Project project, final ProblemDescriptor descriptor) {
final PsiElement nameIdentifier = descriptor.getPsiElement();
final PsiElement elementToRename = nameIdentifier.getParent();
if (m_targetName == null) {
final AsyncResult<DataContext> contextFromFocus = DataManager.getInstance().getDataContextFromFocus();
contextFromFocus.doWhenDone(new Consumer<DataContext>() {
@Override
public void consume(DataContext context) {
final RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(context);
if (renameHandler == null) {
return;
}
renameHandler.invoke(project, new PsiElement[]{elementToRename}, context);
}
});
}
else {
final RefactoringFactory factory = RefactoringFactory.getInstance(project);
final RenameRefactoring renameRefactoring =
factory.createRename(elementToRename, m_targetName, m_searchInStrings, m_searchInNonJavaFiles);
renameRefactoring.run();
}
}
示例3: doTest
import com.intellij.refactoring.RefactoringFactory; //导入依赖的package包/类
private void doTest() throws Exception {
final String filename = getTestName(true) + ".xml";
VirtualFile vfile = VirtualFileManager.getInstance().findFileByUrl("file://" + getTestDataPath() + filename);
String text = FileDocumentManager.getInstance().getDocument(vfile).getText();
final int off = text.indexOf("<ren>");
text = text.replace("<ren>", "");
configureFromFileText(filename, text);
assertNotNull(myFile);
PsiElement element = TargetElementUtilBase.getInstance().findTargetElement(
getEditor(),
TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtilBase.ELEMENT_NAME_ACCEPTED,
off);
assertNotNull(element);
assertTrue(element instanceof PsiNamedElement);
final RenameRefactoring rename =
RefactoringFactory.getInstance(getProject()).createRename(element, ((PsiNamedElement)element).getName() + "-after");
rename.setSearchInComments(false);
rename.setSearchInNonJavaFiles(false);
rename.run();
checkResultByFile(filename + "-after");
}
示例4: doFix
import com.intellij.refactoring.RefactoringFactory; //导入依赖的package包/类
@Override
public void doFix(final Project project, final ProblemDescriptor descriptor) {
final PsiElement nameIdentifier = descriptor.getPsiElement();
final PsiElement elementToRename = nameIdentifier.getParent();
if (m_targetName == null) {
final AsyncResult<DataContext> contextFromFocus = DataManager.getInstance().getDataContextFromFocus();
contextFromFocus.doWhenDone(new AsyncResult.Handler<DataContext>() {
@Override
public void run(DataContext context) {
final RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(context);
if (renameHandler == null) {
return;
}
renameHandler.invoke(project, new PsiElement[]{elementToRename}, context);
}
});
}
else {
final RefactoringFactory factory = RefactoringFactory.getInstance(project);
final RenameRefactoring renameRefactoring =
factory.createRename(elementToRename, m_targetName, m_searchInStrings, m_searchInNonJavaFiles);
renameRefactoring.run();
}
}
示例5: applyFix
import com.intellij.refactoring.RefactoringFactory; //导入依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
final RenameRefactoring refactoring = RefactoringFactory.getInstance(project)
.createRename(parameter, this.newParameterName, false, false);
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
refactoring.run();
}
});
}
},
"Rename parameter to match define",
"Rename parameter to match define");
}
示例6: doFix
import com.intellij.refactoring.RefactoringFactory; //导入依赖的package包/类
@Override
public void doFix(final Project project, final ProblemDescriptor descriptor)
{
final PsiElement nameIdentifier = descriptor.getPsiElement();
final PsiElement elementToRename = nameIdentifier.getParent();
if(m_targetName == null)
{
final AsyncResult<DataContext> contextFromFocus = DataManager.getInstance().getDataContextFromFocus();
contextFromFocus.doWhenDone(context -> {
final RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(context);
if(renameHandler == null)
{
return;
}
renameHandler.invoke(project, new PsiElement[]{elementToRename}, context);
});
}
else
{
final RefactoringFactory factory = RefactoringFactory.getInstance(project);
final RenameRefactoring renameRefactoring = factory.createRename(elementToRename, m_targetName, m_searchInStrings, m_searchInNonJavaFiles);
renameRefactoring.run();
}
}
示例7: renameTargets
import com.intellij.refactoring.RefactoringFactory; //导入依赖的package包/类
public static void renameTargets(AliasingPsiTarget target, @NotNull String newDelegateName) {
final PsiNamedElement namedElement = (PsiNamedElement)target.getNavigationElement();
if (!newDelegateName.equals(namedElement.getName())) {
final RenameRefactoring refactoring =
RefactoringFactory.getInstance(namedElement.getProject()).createRename(namedElement, newDelegateName);
refactoring.run();
}
}
示例8: doFix
import com.intellij.refactoring.RefactoringFactory; //导入依赖的package包/类
@Override
public void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement nameIdentifier = descriptor.getPsiElement();
final PsiElement elementToRename = nameIdentifier.getParent();
final RefactoringFactory factory =
RefactoringFactory.getInstance(project);
final RenameRefactoring renameRefactoring =
factory.createRename(elementToRename, m_targetName);
renameRefactoring.setSearchInComments(false);
renameRefactoring.setSearchInNonJavaFiles(false);
renameRefactoring.run();
}
示例9: renameTargets
import com.intellij.refactoring.RefactoringFactory; //导入依赖的package包/类
protected void renameTargets(@NotNull String newDelegateName) {
final PsiNamedElement namedElement = (PsiNamedElement)getNavigationElement();
if (!newDelegateName.equals(namedElement.getName())) {
final RenameRefactoring refactoring =
RefactoringFactory.getInstance(namedElement.getProject()).createRename(namedElement, newDelegateName);
refactoring.run();
}
}
示例10: replaceWordRefactoring
import com.intellij.refactoring.RefactoringFactory; //导入依赖的package包/类
private void replaceWordRefactoring(String selectedValue)
{
final Project project = editor.getProject();
int offset = editor.getCaretModel().getOffset();
PsiElement elementAt = psiFile.findElementAt(offset);
RefactoringFactory refactoringFactory = RefactoringFactoryImpl.getInstance(project);
RenameRefactoring rename = refactoringFactory.createRename(findNamedElement(elementAt), selectedValue);
UsageInfo[] usages = rename.findUsages();
rename.doRefactoring(usages);
}
示例11: updateModuleReference
import com.intellij.refactoring.RefactoringFactory; //导入依赖的package包/类
/**
* Updates an existing AMD module reference (define literal + the parameter)
*
* @param targetFile the file containing the reference
* @param match a MatchResult that represents the new module reference
* @param statement the define or require statement that is being updated
* @param replacementExpression an expression that will replace the define literal expression
* @param updateReferences if true, will update references to the parameter if it is renamed
*/
public void updateModuleReference(final PsiFile targetFile, final MatchResult match, final DefineStatement statement, final PsiElement replacementExpression, final boolean updateReferences)
{
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
PsiElement defineLiteral = statement.getArguments().getExpressions()[match.getIndex()];
defineLiteral.replace(replacementExpression);
if(!updateReferences)
{
return;
}
// sometimes the lengths of the imports don't match up due to plugins etc.
if(!(match.getIndex() >= statement.getFunction().getParameters().length))
{
// for performance reasons we should only rename a parameter if the name has actually changed
String parameterText = statement.getFunction().getParameters()[match.getIndex()].getText();
String newParameterName = NameResolver.defineToParameter(match.getPath(), moduleNamingExceptionMap);
if(parameterText.equals(newParameterName))
{
return;
}
RenameRefactoring refactoring = RefactoringFactory.getInstance(targetFile.getProject())
.createRename(statement.getFunction().getParameters()[match.getIndex()], newParameterName, false, false);
refactoring.doRefactoring(refactoring.findUsages());
}
}
});
}
示例12: renameTargets
import com.intellij.refactoring.RefactoringFactory; //导入依赖的package包/类
protected void renameTargets(@Nonnull String newDelegateName) {
final PsiNamedElement namedElement = (PsiNamedElement)getNavigationElement();
if (!newDelegateName.equals(namedElement.getName())) {
final RenameRefactoring refactoring =
RefactoringFactory.getInstance(namedElement.getProject()).createRename(namedElement, newDelegateName);
refactoring.run();
}
}
示例13: doFix
import com.intellij.refactoring.RefactoringFactory; //导入依赖的package包/类
public void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement nameIdentifier = descriptor.getPsiElement();
final PsiElement elementToRename = nameIdentifier.getParent();
final RefactoringFactory factory =
RefactoringFactory.getInstance(project);
final RenameRefactoring renameRefactoring =
factory.createRename(elementToRename, m_targetName);
renameRefactoring.setSearchInComments(false);
renameRefactoring.setSearchInNonJavaFiles(false);
renameRefactoring.run();
}
示例14: invoke
import com.intellij.refactoring.RefactoringFactory; //导入依赖的package包/类
/**
* Called when user invokes intention.
*/
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
RefactoringFactory.getInstance(project).createRename(myPsiNode, myTargetName).doRefactoring(UsageInfo.EMPTY_ARRAY);
}