Search in sources :

Example 11 with StringPartInfo

use of org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo in project intellij-community by JetBrains.

the class GrIntroduceConstantDialog method createUIComponents.

private void createUIComponents() {
    myJavaVisibilityPanel = new JavaVisibilityPanel(false, true);
    final GrVariable var = myContext.getVar();
    final GrExpression expression = myContext.getExpression();
    final StringPartInfo stringPart = myContext.getStringPart();
    if (expression != null) {
        myTypeCombo = GrTypeComboBox.createTypeComboBoxFromExpression(expression);
    } else if (stringPart != null) {
        myTypeCombo = GrTypeComboBox.createTypeComboBoxFromExpression(stringPart.getLiteral());
    } else {
        assert var != null;
        myTypeCombo = GrTypeComboBox.createTypeComboBoxWithDefType(var.getDeclaredType(), var);
    }
    List<String> names = new ArrayList<>();
    if (var != null) {
        names.add(var.getName());
    }
    if (expression != null) {
        ContainerUtil.addAll(names, suggestNames());
    }
    myNameField = new NameSuggestionsField(ArrayUtil.toStringArray(names), myContext.getProject(), GroovyFileType.GROOVY_FILE_TYPE);
    GrTypeComboBox.registerUpDownHint(myNameField, myTypeCombo);
}
Also used : GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) JavaVisibilityPanel(com.intellij.refactoring.ui.JavaVisibilityPanel) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) NameSuggestionsField(com.intellij.refactoring.ui.NameSuggestionsField) StringPartInfo(org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo)

Example 12 with StringPartInfo

use of org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo in project intellij-community by JetBrains.

the class GrIntroduceParameterDialog method suggestNames.

@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);
}
Also used : GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) StringPartInfo(org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with StringPartInfo

use of org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo in project intellij-community by JetBrains.

the class GrIntroduceParameterProcessor method processStringPart.

private void processStringPart() {
    final StringPartInfo stringPartInfo = mySettings.getStringPartInfo();
    if (stringPartInfo != null) {
        final GrExpression expr = mySettings.getStringPartInfo().replaceLiteralWithConcatenation(mySettings.getName());
        final Editor editor = PsiUtilBase.findEditor(expr);
        if (editor != null) {
            editor.getSelectionModel().removeSelection();
            editor.getCaretModel().moveToOffset(expr.getTextRange().getEndOffset());
        }
    }
}
Also used : GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) Editor(com.intellij.openapi.editor.Editor) StringPartInfo(org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo)

Example 14 with StringPartInfo

use of org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo in project intellij-community by JetBrains.

the class GrIntroduceFieldProcessor method getInitializer.

@Nullable
protected GrExpression getInitializer() {
    if (mySettings.removeLocalVar()) {
        return extractVarInitializer();
    }
    GrExpression expression = myContext.getExpression();
    StringPartInfo stringPart = myContext.getStringPart();
    if (expression != null) {
        return expression;
    } else if (stringPart != null) {
        return stringPart.createLiteralFromSelected();
    }
    throw new IncorrectOperationException("cannot be here!");
}
Also used : GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) IncorrectOperationException(com.intellij.util.IncorrectOperationException) StringPartInfo(org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with StringPartInfo

use of org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo in project intellij-community by JetBrains.

the class GrIntroduceFieldDialog method createUIComponents.

private void createUIComponents() {
    final GrExpression expression = myContext.getExpression();
    final GrVariable var = myContext.getVar();
    final StringPartInfo stringPart = myContext.getStringPart();
    List<String> list = new ArrayList<>();
    if (var != null) {
        list.add(var.getName());
    }
    ContainerUtil.addAll(list, suggestNames());
    myNameField = new NameSuggestionsField(ArrayUtil.toStringArray(list), myContext.getProject(), GroovyFileType.GROOVY_FILE_TYPE);
    if (expression != null) {
        myTypeComboBox = GrTypeComboBox.createTypeComboBoxFromExpression(expression);
    } else if (stringPart != null) {
        myTypeComboBox = GrTypeComboBox.createTypeComboBoxFromExpression(stringPart.getLiteral());
    } else {
        myTypeComboBox = GrTypeComboBox.createTypeComboBoxWithDefType(var.getDeclaredType(), var);
    }
    GrTypeComboBox.registerUpDownHint(myNameField, myTypeComboBox);
}
Also used : GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) ArrayList(java.util.ArrayList) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) NameSuggestionsField(com.intellij.refactoring.ui.NameSuggestionsField) StringPartInfo(org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo)

Aggregations

StringPartInfo (org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo)16 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)14 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)11 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 Editor (com.intellij.openapi.editor.Editor)2 TextRange (com.intellij.openapi.util.TextRange)2 PsiType (com.intellij.psi.PsiType)2 NameSuggestionsField (com.intellij.refactoring.ui.NameSuggestionsField)2 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)2 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)2 SelectionModel (com.intellij.openapi.editor.SelectionModel)1 PsiElement (com.intellij.psi.PsiElement)1 ChangedMethodCallInfo (com.intellij.refactoring.introduceParameter.ChangedMethodCallInfo)1 ExternalUsageInfo (com.intellij.refactoring.introduceParameter.ExternalUsageInfo)1 InternalUsageInfo (com.intellij.refactoring.introduceParameter.InternalUsageInfo)1 JavaVisibilityPanel (com.intellij.refactoring.ui.JavaVisibilityPanel)1 UsageInfo (com.intellij.usageView.UsageInfo)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 ArrayList (java.util.ArrayList)1