String (String desiredName, PsiType type, String mostAbstractAllowedType, String initializer, @NotNull ResultKind kind) { if (kind != ResultKind.UNKNOWN && myChainExpression.getParent() instanceof PsiVariable var && isCompatibleType(var, type, mostAbstractAllowedType) && var.getParent() instanceof PsiDeclarationStatement declaration && (kind == ResultKind.FINAL || VariableAccessUtils.canUseAsNonFinal(ObjectUtils.tryCast(var, PsiLocalVariable.class))) && declaration.getDeclaredElements().length == 1) { myChainExpression = declaration; PsiVariable copy = (PsiVariable)var.copy(); if (kind == ResultKind.NON_FINAL) { PsiModifierList modifierList = copy.getModifierList(); if (modifierList != null) { modifierList.setModifierProperty(PsiModifier.FINAL, false); } } PsiExpression oldInitializer = copy.getInitializer(); LOG.assertTrue(oldInitializer != null); oldInitializer.replace(createExpression(initializer)); addBeforeStep(copy.getText()); return var.getName(); } String name = registerVarName(Arrays.asList(desiredName, "result")); addBeforeStep(type.getCanonicalText() + " " + name + " = " + initializer + ";"); if (myFinisher != null) { throw new IllegalStateException("Finisher is already defined"); } setFinisher(name); return name; }