GrExpression (@Nullable String varName) { String prefix = preparePrefix(); String suffix = prepareSuffix(); StringBuilder buffer = new StringBuilder(); boolean prefixExists = !GrStringUtil.removeQuotes(prefix).isEmpty(); if (prefixExists) { buffer.append(prefix).append('+'); } buffer.append(varName != null ? varName : prepareSelected()); boolean suffixExists = !GrStringUtil.removeQuotes(suffix).isEmpty(); if (suffixExists) { buffer.append('+').append(suffix); } final GrExpression concatenation = GroovyPsiElementFactory.getInstance(myLiteral.getProject()).createExpressionFromText(buffer); final GrExpression replaced = getLiteral().replaceWithExpression(concatenation, false); try { if (prefixExists && suffixExists) { return Objects.requireNonNull(((GrBinaryExpression)((GrBinaryExpression)replaced).getLeftOperand()).getRightOperand()); } if (!prefixExists && suffixExists) { return ((GrBinaryExpression)replaced).getLeftOperand(); } if (prefixExists) { return Objects.requireNonNull(((GrBinaryExpression)replaced).getRightOperand()); } return replaced; } catch (ClassCastException c) { throw new IncorrectOperationException(buffer.toString()); } }