use of org.jetbrains.plugins.groovy.refactoring.introduce.parameter.java2groovy.FieldConflictsResolver in project intellij-community by JetBrains.
the class GrIntroduceClosureParameterProcessor method changeSignature.
private static void changeSignature(GrClosableBlock block, GrIntroduceParameterSettings settings) {
final String name = settings.getName();
final FieldConflictsResolver fieldConflictsResolver = new FieldConflictsResolver(name, block);
final GrParameter[] parameters = block.getParameters();
settings.parametersToRemove().forEachDescending(new TIntProcedure() {
@Override
public boolean execute(final int paramNum) {
try {
PsiParameter param = parameters[paramNum];
param.delete();
} catch (IncorrectOperationException e) {
LOG.error(e);
}
return true;
}
});
final PsiType type = settings.getSelectedType();
final String typeText = type == null ? null : type.getCanonicalText();
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(settings.getProject());
GrParameter parameter = factory.createParameter(name, typeText, block);
parameter.getModifierList().setModifierProperty(PsiModifier.FINAL, settings.declareFinal());
final GrParameterList parameterList = block.getParameterList();
final PsiParameter anchorParameter = GroovyIntroduceParameterUtil.getAnchorParameter(parameterList, block.isVarArgs());
parameter = (GrParameter) parameterList.addAfter(parameter, anchorParameter);
if (block.getArrow() == null) {
final PsiElement arrow = block.addAfter(factory.createClosureFromText("{->}").getArrow().copy(), parameterList);
final PsiElement child = block.getFirstChild().getNextSibling();
if (PsiImplUtil.isWhiteSpaceOrNls(child)) {
final String text = child.getText();
child.delete();
block.addAfter(factory.createLineTerminator(text), arrow);
}
}
JavaCodeStyleManager.getInstance(parameter.getProject()).shortenClassReferences(parameter);
fieldConflictsResolver.fix();
}
Aggregations