private JPanel createNamePanel() { final GridBag c = new GridBag().setDefaultAnchor(GridBagConstraints.WEST).setDefaultInsets(1, 1, 1, 1); final JPanel namePanel = new JPanel(new GridBagLayout()); final JLabel typeLabel = new JLabel(UIUtil.replaceMnemonicAmpersand("&Type:")); c.nextLine().next().weightx(0).fillCellNone(); namePanel.add(typeLabel, c); myTypeComboBox = createTypeComboBox( GroovyIntroduceParameterUtil.findVar(myInfo), GroovyIntroduceParameterUtil.findExpr(myInfo), findStringPart()); c.next().weightx(1).fillCellHorizontally(); namePanel.add(myTypeComboBox, c); typeLabel.setLabelFor(myTypeComboBox); final JLabel nameLabel = new JLabel(UIUtil.replaceMnemonicAmpersand("&Name:")); c.nextLine().next().weightx(0).fillCellNone(); namePanel.add(nameLabel, c); myNameSuggestionsField = createNameField(GroovyIntroduceParameterUtil.findVar(myInfo)); c.next().weightx(1).fillCellHorizontally(); namePanel.add(myNameSuggestionsField, c); nameLabel.setLabelFor(myNameSuggestionsField); GrTypeComboBox.registerUpDownHint(myNameSuggestionsField, myTypeComboBox); return namePanel; }
@NotNull public LinkedHashSet<String> suggestNames() { GrVariable var = GroovyIntroduceParameterUtil.findVar(myInfo); GrExpression expr = GroovyIntroduceParameterUtil.findExpr(myInfo); StringPartInfo stringPart = findStringPart(); return GroovyIntroduceParameterUtil.suggestNames( var, expr, stringPart, myInfo.getToReplaceIn(), myProject); }
@Override public void doOKAction() { saveSettings(); super.doOKAction(); final GrParametersOwner toReplaceIn = myInfo.getToReplaceIn(); final GrExpression expr = GroovyIntroduceParameterUtil.findExpr(myInfo); final GrVariable var = GroovyIntroduceParameterUtil.findVar(myInfo); final StringPartInfo stringPart = findStringPart(); if (myTypeComboBox.isClosureSelected() || expr == null && var == null && stringPart == null) { GrIntroduceParameterSettings settings = new ExtractClosureHelperImpl( myInfo, getEnteredName(), myDeclareFinalCheckBox.isSelected(), getParametersToRemove(), myDelegateViaOverloadingMethodCheckBox.isSelected(), getReplaceFieldsWithGetter(), myForceReturnCheckBox.isSelected(), false, myTypeComboBox.getSelectedType() == null); if (toReplaceIn instanceof GrMethod) { invokeRefactoring(new ExtractClosureFromMethodProcessor(settings)); } else { invokeRefactoring(new ExtractClosureFromClosureProcessor(settings)); } } else { GrIntroduceParameterSettings settings = new GrIntroduceExpressionSettingsImpl( myInfo, getEnteredName(), myDeclareFinalCheckBox.isSelected(), getParametersToRemove(), myDelegateViaOverloadingMethodCheckBox.isSelected(), getReplaceFieldsWithGetter(), expr, var, myTypeComboBox.getSelectedType(), var != null, true, myForceReturnCheckBox.isSelected()); if (toReplaceIn instanceof GrMethod) { invokeRefactoring(new GrIntroduceParameterProcessor(settings)); } else { invokeRefactoring(new GrIntroduceClosureParameterProcessor(settings)); } } }
public GrIntroduceParameterDialog(IntroduceParameterInfo info) { super(info.getProject(), true); myInfo = info; myProject = info.getProject(); myCanIntroduceSimpleParameter = GroovyIntroduceParameterUtil.findExpr(myInfo) != null || GroovyIntroduceParameterUtil.findVar(myInfo) != null || findStringPart() != null; TObjectIntHashMap<GrParameter> parametersToRemove = GroovyIntroduceParameterUtil.findParametersToRemove(info); toRemoveCBs = new TObjectIntHashMap<JCheckBox>(parametersToRemove.size()); for (Object p : parametersToRemove.keys()) { JCheckBox cb = new JCheckBox( GroovyRefactoringBundle.message( "remove.parameter.0.no.longer.used", ((GrParameter) p).getName())); toRemoveCBs.put(cb, parametersToRemove.get((GrParameter) p)); cb.setSelected(true); } init(); }