void (final Project project, Editor editor, PsiElement psiElement) { if (!(psiElement instanceof IProperty property)) return; final String propertyValue = property.getValue(); if (propertyValue == null) return; final List<PsiElement> occurrences = Collections.synchronizedList(new ArrayList<>()); final Collection<PsiFile> containingFiles = Collections.synchronizedSet(new HashSet<>()); containingFiles.add(psiElement.getContainingFile()); boolean result = ReferencesSearch.search(psiElement).forEach( psiReference -> { PsiElement element = psiReference.getElement(); PsiElement parent = element.getParent(); if (parent instanceof PsiExpressionList && parent.getParent() instanceof PsiMethodCallExpression) { if (((PsiExpressionList)parent).getExpressionCount() == 1) { occurrences.add(parent.getParent()); containingFiles.add(element.getContainingFile()); return true; } } return false; } ); if (!result) { CommonRefactoringUtil.showErrorHint(project, editor, JavaI18nBundle.message("error.hint.property.has.non.method.usages"), getRefactoringName(), null); } if (occurrences.isEmpty()) { CommonRefactoringUtil.showErrorHint(project, editor, JavaI18nBundle.message("error.hint.property.has.no.usages"), getRefactoringName(), null); return; } if (!ApplicationManager.getApplication().isUnitTestMode()) { String occurrencesString = RefactoringBundle.message("occurrences.string", occurrences.size()); String question = JavaI18nBundle.message("inline.property.confirmation", property.getName(), propertyValue) + " " + occurrencesString; RefactoringMessageDialog dialog = new RefactoringMessageDialog(getRefactoringName(), question, HelpID.INLINE_VARIABLE, "OptionPane.questionIcon", true, project); if (!dialog.showAndGet()) { return; } } final RefactoringEventData data = new RefactoringEventData(); data.addElement(psiElement.copy()); WriteCommandAction.writeCommandAction(project, containingFiles.toArray(PsiFile.EMPTY_ARRAY)).withName(getRefactoringName()).run(() -> { project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringStarted(REFACTORING_ID, data); PsiLiteral stringLiteral = (PsiLiteral)JavaPsiFacade.getInstance(project).getElementFactory(). createExpressionFromText("\"" + StringUtil.escapeStringCharacters(propertyValue) + "\"", null); for (PsiElement occurrence : occurrences) { occurrence.replace(stringLiteral.copy()); } project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(REFACTORING_ID, null); }); }