com.intellij.refactoring.rename.inplace.InplaceRefactoring Java Examples
The following examples show how to use
com.intellij.refactoring.rename.inplace.InplaceRefactoring.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LookupPreview.java From consulo with Apache License 2.0 | 6 votes |
void updatePreview(@Nullable LookupElement item) { if (!Registry.is("ide.lookup.preview.insertion")) return; myInlays.forEach(Disposer::dispose); myInlays.clear(); String suffix = getSuffixText(item); Editor editor = myLookup.getTopLevelEditor(); if (!suffix.isEmpty() && editor instanceof DesktopEditorImpl && !editor.getSelectionModel().hasSelection() && InplaceRefactoring.getActiveInplaceRenamer(editor) == null) { myLookup.performGuardedChange(() -> { for (Caret caret : editor.getCaretModel().getAllCarets()) { ensureCaretBeforeInlays(caret); addInlay(suffix, caret.getOffset()); } }); } }
Example #2
Source File: LSPRenameHandler.java From lsp4intellij with Apache License 2.0 | 5 votes |
private InplaceRefactoring doRename(PsiElement elementToRename, Editor editor) { if (elementToRename instanceof PsiNameIdentifierOwner) { RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(elementToRename); if (processor.isInplaceRenameSupported()) { StartMarkAction startMarkAction = StartMarkAction.canStart(elementToRename.getProject()); if (startMarkAction == null || (processor.substituteElementToRename(elementToRename, editor) == elementToRename)) { processor.substituteElementToRename(elementToRename, editor, new Pass<PsiElement>() { @Override public void pass(PsiElement element) { MemberInplaceRenamer renamer = createMemberRenamer(element, (PsiNameIdentifierOwner) elementToRename, editor); boolean startedRename = renamer.performInplaceRename(); if (!startedRename) { performDialogRename(editor); } } }); return null; } } else { InplaceRefactoring inplaceRefactoring = editor.getUserData(InplaceRefactoring.INPLACE_RENAMER); if ((inplaceRefactoring instanceof MemberInplaceRenamer)) { TemplateState templateState = TemplateManagerImpl .getTemplateState(InjectedLanguageUtil.getTopLevelEditor(editor)); if (templateState != null) { templateState.gotoEnd(true); } } } } performDialogRename(editor); return null; }
Example #3
Source File: SurroundWithHandler.java From consulo with Apache License 2.0 | 5 votes |
static void doSurround(final Project project, final Editor editor, final Surrounder surrounder, final PsiElement[] elements) { if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) { return; } try { PsiDocumentManager.getInstance(project).commitAllDocuments(); int col = editor.getCaretModel().getLogicalPosition().column; int line = editor.getCaretModel().getLogicalPosition().line; if (!editor.getCaretModel().supportsMultipleCarets()) { LogicalPosition pos = new LogicalPosition(0, 0); editor.getCaretModel().moveToLogicalPosition(pos); } TextRange range = surrounder.surroundElements(project, editor, elements); if (range != CARET_IS_OK) { if (TemplateManager.getInstance(project).getActiveTemplate(editor) == null && InplaceRefactoring.getActiveInplaceRenamer(editor) == null) { LogicalPosition pos1 = new LogicalPosition(line, col); editor.getCaretModel().moveToLogicalPosition(pos1); } if (range != null) { int offset = range.getStartOffset(); editor.getCaretModel().removeSecondaryCarets(); editor.getCaretModel().moveToOffset(offset); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset()); } } } catch (IncorrectOperationException e) { LOG.error(e); } }
Example #4
Source File: InplaceChangeSignature.java From consulo with Apache License 2.0 | 5 votes |
public InplaceChangeSignature(Project project, Editor editor, @Nonnull PsiElement element) { myDocumentManager = PsiDocumentManager.getInstance(project); myProject = project; try { myMarkAction = StartMarkAction.start(editor, project, ChangeSignatureHandler.REFACTORING_NAME); } catch (StartMarkAction.AlreadyStartedException e) { final int exitCode = Messages.showYesNoDialog(myProject, e.getMessage(), ChangeSignatureHandler.REFACTORING_NAME, "Navigate to Started", "Cancel", Messages.getErrorIcon()); if (exitCode == Messages.CANCEL) return; PsiElement method = myStableChange.getMethod(); VirtualFile virtualFile = PsiUtilCore.getVirtualFile(method); new OpenFileDescriptor(project, virtualFile, method.getTextOffset()).navigate(true); return; } myEditor = editor; myDetector = LanguageChangeSignatureDetectors.INSTANCE.forLanguage(element.getLanguage()); myStableChange = myDetector.createInitialChangeInfo(element); myInitialSignature = myDetector.extractSignature(myStableChange); myInitialName = DescriptiveNameUtil.getDescriptiveName(myStableChange.getMethod()); TextRange highlightingRange = myDetector.getHighlightingRange(myStableChange); HighlightManager highlightManager = HighlightManager.getInstance(myProject); TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.LIVE_TEMPLATE_ATTRIBUTES); highlightManager.addRangeHighlight(editor, highlightingRange.getStartOffset(), highlightingRange.getEndOffset(), attributes, false, myHighlighters); for (RangeHighlighter highlighter : myHighlighters) { highlighter.setGreedyToRight(true); highlighter.setGreedyToLeft(true); } myEditor.getDocument().addDocumentListener(this); myEditor.putUserData(INPLACE_CHANGE_SIGNATURE, this); myPreview = InplaceRefactoring.createPreviewComponent(project, myDetector.getFileType()); showBalloon(); }
Example #5
Source File: LombokElementRenameHandler.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public InplaceRefactoring doRename(@NotNull PsiElement elementToRename, @NotNull Editor editor, @Nullable DataContext dataContext) { RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(elementToRename); PsiElement actualElem = processor.substituteElementToRename(elementToRename, editor); return super.doRename(actualElem, editor, dataContext); }
Example #6
Source File: AbstractInplaceIntroducer.java From consulo with Apache License 2.0 | 4 votes |
/** * Begins the in-place refactoring operation. * * @return true if the in-place refactoring was successfully started, false if it failed to start and a dialog should be shown instead. */ public boolean startInplaceIntroduceTemplate() { final boolean replaceAllOccurrences = isReplaceAllOccurrences(); final Ref<Boolean> result = new Ref<Boolean>(); CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { @Override public void run() { final String[] names = suggestNames(replaceAllOccurrences, getLocalVariable()); final V variable = createFieldToStartTemplateOn(replaceAllOccurrences, names); boolean started = false; if (variable != null) { int caretOffset = getCaretOffset(); myEditor.getCaretModel().moveToOffset(caretOffset); myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); final LinkedHashSet<String> nameSuggestions = new LinkedHashSet<String>(); nameSuggestions.add(variable.getName()); nameSuggestions.addAll(Arrays.asList(names)); initOccurrencesMarkers(); setElementToRename(variable); updateTitle(getVariable()); started = AbstractInplaceIntroducer.super.performInplaceRefactoring(nameSuggestions); if (started) { myDocumentAdapter = new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { if (myPreview == null) return; final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); if (templateState != null) { final TextResult value = templateState.getVariableValue(InplaceRefactoring.PRIMARY_VARIABLE_NAME); if (value != null) { updateTitle(getVariable(), value.getText()); } } } }; myEditor.getDocument().addDocumentListener(myDocumentAdapter); updateTitle(getVariable()); if (TemplateManagerImpl.getTemplateState(myEditor) != null) { myEditor.putUserData(ACTIVE_INTRODUCE, AbstractInplaceIntroducer.this); } } } result.set(started); if (!started) { finish(true); } } }, getCommandName(), getCommandName()); return result.get(); }