@Override protected void updateTitle(@Nullable final PsiVariable variable, final String value) { final PsiElement declarationScope = variable != null ? ((PsiParameter) variable).getDeclarationScope() : null; if (declarationScope instanceof PsiMethod) { final PsiMethod psiMethod = (PsiMethod) declarationScope; final StringBuilder buf = new StringBuilder(); buf.append(psiMethod.getName()).append(" ("); boolean frst = true; final List<TextRange> ranges2Remove = new ArrayList<>(); TextRange addedRange = null; for (PsiParameter parameter : psiMethod.getParameterList().getParameters()) { if (frst) { frst = false; } else { buf.append(", "); } int startOffset = buf.length(); if (myMustBeFinal || myPanel.isGenerateFinal()) { buf.append("final "); } buf.append(parameter.getType().getPresentableText()) .append(" ") .append(variable == parameter ? value : parameter.getName()); int endOffset = buf.length(); if (variable == parameter) { addedRange = new TextRange(startOffset, endOffset); } else if (myPanel.isParamToRemove(parameter)) { ranges2Remove.add(new TextRange(startOffset, endOffset)); } } buf.append(")"); setPreviewText(buf.toString()); final MarkupModel markupModel = DocumentMarkupModel.forDocument(getPreviewEditor().getDocument(), myProject, true); markupModel.removeAllHighlighters(); for (TextRange textRange : ranges2Remove) { markupModel.addRangeHighlighter( textRange.getStartOffset(), textRange.getEndOffset(), 0, getTestAttributesForRemoval(), HighlighterTargetArea.EXACT_RANGE); } markupModel.addRangeHighlighter( addedRange.getStartOffset(), addedRange.getEndOffset(), 0, getTextAttributesForAdd(), HighlighterTargetArea.EXACT_RANGE); revalidate(); } }
protected void performIntroduce() { boolean isDeleteLocalVariable = false; PsiExpression parameterInitializer = myExpr; if (getLocalVariable() != null) { if (myPanel.isUseInitializer()) { parameterInitializer = getLocalVariable().getInitializer(); } isDeleteLocalVariable = myPanel.isDeleteLocalVariable(); } final TIntArrayList parametersToRemove = myPanel.getParametersToRemove(); final IntroduceParameterProcessor processor = new IntroduceParameterProcessor( myProject, myMethod, myMethodToSearchFor, parameterInitializer, myExpr, (PsiLocalVariable) getLocalVariable(), isDeleteLocalVariable, getInputName(), myPanel.isReplaceAllOccurences(), myPanel.getReplaceFieldsWithGetters(), myMustBeFinal || myPanel.isGenerateFinal(), isGenerateDelegate(), getType(), parametersToRemove); final Runnable runnable = new Runnable() { public void run() { final Runnable performRefactoring = new Runnable() { public void run() { processor.setPrepareSuccessfulSwingThreadCallback( new Runnable() { @Override public void run() {} }); processor.run(); normalizeParameterIdxAccordingToRemovedParams(parametersToRemove); final PsiParameter parameter = getParameter(); if (parameter != null) { InplaceIntroduceParameterPopup.super.saveSettings(parameter); } } }; if (ApplicationManager.getApplication().isUnitTestMode()) { performRefactoring.run(); } else { ApplicationManager.getApplication().invokeLater(performRefactoring); } } }; CommandProcessor.getInstance().executeCommand(myProject, runnable, getCommandName(), null); }