use of org.jetbrains.plugins.groovy.refactoring.extract.ParameterInfo in project intellij-community by JetBrains.
the class GroovyExtractMethodHandler method renameParameterOccurrences.
private static void renameParameterOccurrences(GrMethod method, ExtractMethodInfoHelper helper) throws IncorrectOperationException {
GrOpenBlock block = method.getBlock();
if (block == null)
return;
GrStatement[] statements = block.getStatements();
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(helper.getProject());
for (ParameterInfo info : helper.getParameterInfos()) {
final String oldName = info.getOriginalName();
final String newName = info.getName();
final ArrayList<GrExpression> result = new ArrayList<>();
if (!oldName.equals(newName)) {
for (final GrStatement statement : statements) {
statement.accept(new PsiRecursiveElementVisitor() {
@Override
public void visitElement(final PsiElement element) {
super.visitElement(element);
if (element instanceof GrReferenceExpression) {
GrReferenceExpression expr = (GrReferenceExpression) element;
if (!expr.isQualified() && oldName.equals(expr.getReferenceName())) {
result.add(expr);
}
}
}
});
for (GrExpression expr : result) {
expr.replaceWithExpression(factory.createExpressionFromText(newName), false);
}
}
}
}
}
use of org.jetbrains.plugins.groovy.refactoring.extract.ParameterInfo in project intellij-community by JetBrains.
the class GrIntroduceParameterDialog method init.
@Override
protected void init() {
super.init();
JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance();
initReplaceFieldsWithGetters(settings);
myDeclareFinalCheckBox.setSelected(hasFinalModifier());
myDelegateViaOverloadingMethodCheckBox.setVisible(myInfo.getToSearchFor() != null);
setTitle(RefactoringBundle.message("introduce.parameter.title"));
myTable.init(myInfo);
final GrParameter[] parameters = myInfo.getToReplaceIn().getParameters();
toRemoveCBs.forEachEntry(new TObjectIntProcedure<JCheckBox>() {
@Override
public boolean execute(JCheckBox checkbox, int index) {
checkbox.setSelected(true);
final GrParameter param = parameters[index];
final ParameterInfo pinfo = findParamByOldName(param.getName());
if (pinfo != null) {
pinfo.passAsParameter = false;
}
return true;
}
});
updateSignature();
if (myCanIntroduceSimpleParameter) {
mySignaturePanel.setVisible(false);
//action to hide signature panel if we have variants to introduce simple parameter
myTypeComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
mySignaturePanel.setVisible(myTypeComboBox.isClosureSelected());
pack();
}
});
}
final PsiType closureReturnType = inferClosureReturnType();
if (PsiType.VOID.equals(closureReturnType)) {
myForceReturnCheckBox.setEnabled(false);
myForceReturnCheckBox.setSelected(false);
} else {
myForceReturnCheckBox.setSelected(isForceReturn());
}
if (myInfo.getToReplaceIn() instanceof GrClosableBlock) {
myDelegateViaOverloadingMethodCheckBox.setEnabled(false);
myDelegateViaOverloadingMethodCheckBox.setToolTipText("Delegating is not allowed in closure context");
}
pack();
}
Aggregations