Template (PsiField f, Object expectedTypes, PsiClass targetClass, Editor editor, PsiElement context, boolean createConstantField, @NotNull PsiSubstitutor substitutor) { GrVariableDeclaration fieldDecl = (GrVariableDeclaration)f.getParent(); GrField field = (GrField)fieldDecl.getVariables()[0]; Project project = field.getProject(); fieldDecl = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(fieldDecl); TemplateBuilderImpl builder = new TemplateBuilderImpl(fieldDecl); GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project); if (expectedTypes instanceof TypeConstraint[]) { GrTypeElement typeElement = fieldDecl.getTypeElementGroovy(); assert typeElement != null; ChooseTypeExpression expr = new ChooseTypeExpression((TypeConstraint[])expectedTypes, PsiManager.getInstance(project), typeElement.getResolveScope()); builder.replaceElement(typeElement, expr); } else if (expectedTypes instanceof ExpectedTypeInfo[]) { new GuessTypeParameters(project, factory, builder, substitutor) .setupTypeElement(field.getTypeElement(), (ExpectedTypeInfo[])expectedTypes, context, targetClass); } GrExpression initializer = field.getInitializerGroovy(); if (createConstantField && initializer != null) { builder.replaceElement(initializer, new EmptyExpression()); PsiElement identifier = field.getNameIdentifierGroovy(); builder.setEndVariableAfter(identifier); } fieldDecl = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(fieldDecl); Template template = builder.buildTemplate(); TextRange range = fieldDecl.getTextRange(); editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset()); if (expectedTypes instanceof ExpectedTypeInfo[]) { if (!Registry.is("ide.create.field.enable.shortening") && ((ExpectedTypeInfo[])expectedTypes).length > 1) { template.setToShortenLongNames(false); } } return template; }