Search in sources :

Example 1 with GrIntroduceContext

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);
    }
}
Also used : GrIntroduceContext(org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceContext) IntroduceOccurrencesChooser(org.jetbrains.plugins.groovy.refactoring.introduce.IntroduceOccurrencesChooser) ArrayList(java.util.ArrayList) List(java.util.List) IntroduceOccurrencesChooser(org.jetbrains.plugins.groovy.refactoring.introduce.IntroduceOccurrencesChooser) OccurrencesChooser(com.intellij.refactoring.introduce.inplace.OccurrencesChooser)

Example 2 with GrIntroduceContext

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;
    }
}
Also used : GrIntroduceContext(org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceContext) GroovyFieldValidator(org.jetbrains.plugins.groovy.refactoring.introduce.field.GroovyFieldValidator) GrIntroduceContextImpl(org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceContextImpl)

Example 3 with GrIntroduceContext

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());
        }
    };
}
Also used : GrIntroduceContext(org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceContext) GrControlStatement(org.jetbrains.plugins.groovy.lang.psi.api.formatter.GrControlStatement) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)

Aggregations

GrIntroduceContext (org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceContext)3 OccurrencesChooser (com.intellij.refactoring.introduce.inplace.OccurrencesChooser)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GrControlStatement (org.jetbrains.plugins.groovy.lang.psi.api.formatter.GrControlStatement)1 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)1 GrIntroduceContextImpl (org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceContextImpl)1 IntroduceOccurrencesChooser (org.jetbrains.plugins.groovy.refactoring.introduce.IntroduceOccurrencesChooser)1 GroovyFieldValidator (org.jetbrains.plugins.groovy.refactoring.introduce.field.GroovyFieldValidator)1