GrVariable () { PsiElement scope = myContext.getScope(); final PsiClass targetClass = scope instanceof GroovyFileBase ? ((GroovyFileBase)scope).getScriptClass() : (PsiClass)scope; if (targetClass == null) return null; final GrVariableDeclaration declaration = insertField(targetClass); final GrVariable field = declaration.getVariables()[0]; if (mySettings.removeLocalVar()) { myLocalVariable = GrIntroduceHandlerBase.resolveLocalVar(myContext); assert myLocalVariable != null : myContext.getExpression() + ", " + myContext.getVar() + ", " + myContext.getStringPart(); } GrExpression originalInitializer = getInitializer(); myInitializer = originalInitializer == null ? null : (GrExpression)originalInitializer.copy(); List<PsiElement> replaced = processOccurrences(targetClass, field); switch (mySettings.initializeIn()) { case CUR_METHOD -> initializeInMethod(field, replaced); case FIELD_DECLARATION -> field.setInitializerGroovy(myInitializer); case CONSTRUCTOR -> initializeInConstructor(field, replaced); case SETUP_METHOD -> initializeInSetup(field, replaced); } JavaCodeStyleManager.getInstance(declaration.getProject()).shortenClassReferences(declaration); if (mySettings.removeLocalVar()) { GrIntroduceHandlerBase.deleteLocalVar(myLocalVariable); } return field; }