use of org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceContext in project intellij-community by JetBrains.
the class GrIntroduceParameterHandler method showDialogOrStartInplace.
//method to hack in tests
protected void showDialogOrStartInplace(@NotNull final IntroduceParameterInfo info, @NotNull final Editor editor) {
if (isInplace(info, editor)) {
final GrIntroduceContext context = createContext(info, editor);
Map<OccurrencesChooser.ReplaceChoice, List<Object>> occurrencesMap = GrIntroduceHandlerBase.fillChoice(context);
new IntroduceOccurrencesChooser(editor).showChooser(new Pass<OccurrencesChooser.ReplaceChoice>() {
@Override
public void pass(OccurrencesChooser.ReplaceChoice choice) {
startInplace(info, context, choice);
}
}, occurrencesMap);
} else {
showDialog(info);
}
}
use of org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceContext in project intellij-community by JetBrains.
the class GroovyIntroduceParameterUtil method suggestNames.
static LinkedHashSet<String> suggestNames(GrVariable var, GrExpression expr, StringPartInfo stringPart, GrParametersOwner scope, Project project) {
if (expr != null) {
final GrIntroduceContext introduceContext = new GrIntroduceContextImpl(project, null, expr, var, stringPart, PsiElement.EMPTY_ARRAY, scope);
final GroovyFieldValidator validator = new GroovyFieldValidator(introduceContext);
return new LinkedHashSet<>(Arrays.asList(GroovyNameSuggestionUtil.suggestVariableNames(expr, validator, true)));
} else if (var != null) {
final GrIntroduceContext introduceContext = new GrIntroduceContextImpl(project, null, expr, var, stringPart, PsiElement.EMPTY_ARRAY, scope);
final GroovyFieldValidator validator = new GroovyFieldValidator(introduceContext);
LinkedHashSet<String> names = new LinkedHashSet<>();
names.add(var.getName());
ContainerUtil.addAll(names, GroovyNameSuggestionUtil.suggestVariableNameByType(var.getType(), validator));
return names;
} else {
LinkedHashSet<String> names = new LinkedHashSet<>();
names.add("closure");
return names;
}
}
use of org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceContext in project intellij-community by JetBrains.
the class GrIntroduceVariableHandler method getIntroducer.
@Override
protected GrInplaceVariableIntroducer getIntroducer(@NotNull GrIntroduceContext context, @NotNull OccurrencesChooser.ReplaceChoice choice) {
final Ref<GrIntroduceContext> contextRef = Ref.create(context);
if (context.getStringPart() != null) {
extractStringPart(contextRef);
}
context = contextRef.get();
final GrStatement anchor = findAnchor(context, choice == OccurrencesChooser.ReplaceChoice.ALL);
if (anchor.getParent() instanceof GrControlStatement) {
addBraces(anchor, contextRef);
}
return new GrInplaceVariableIntroducer(getRefactoringName(), choice, contextRef.get()) {
@Override
protected GrVariable runRefactoring(GrIntroduceContext context, GroovyIntroduceVariableSettings settings, boolean processUsages) {
return refactorInWriteAction(() -> processUsages ? processExpression(context, settings) : addVariable(context, settings));
}
@Override
protected void performPostIntroduceTasks() {
super.performPostIntroduceTasks();
moveOffsetToPositionMarker(contextRef.get().getEditor());
}
};
}
Aggregations