void (@NotNull PsiElement refElement, @NotNull String name, PsiType @NotNull [] argTypes, @NotNull GrTypeDefinition targetClass, @NotNull Project project) { WriteAction.run(() -> { ChooseTypeExpression[] paramTypesExpressions = new ChooseTypeExpression[argTypes.length]; String[] paramTypes = new String[argTypes.length]; String[] paramNames = new String[argTypes.length]; for (int i = 0; i < argTypes.length; i++) { PsiType argType = argTypes[i]; if (argType == null) argType = TypesUtil.getJavaLangObject(refElement); paramTypes[i] = "Object"; paramNames[i] = "o" + i; TypeConstraint[] constraints = {SupertypeConstraint.create(argType)}; paramTypesExpressions[i] = new ChooseTypeExpression(constraints, refElement.getManager(), targetClass.getResolveScope()); } GrMethod method = GroovyPsiElementFactory.getInstance(project).createConstructorFromText(name, paramTypes, paramNames, "{\n}"); method = (GrMethod)targetClass.addBefore(method, null); final PsiElement context = PsiTreeUtil.getParentOfType(refElement, PsiMethod.class, PsiClass.class, PsiFile.class); createTemplateForMethod(paramTypesExpressions, method, targetClass, TypeConstraint.EMPTY_ARRAY, true, context); }); }