GrLightMethodBuilder (@NotNull String name, @Nullable String returnType, @Nullable String closureTypeParameter, @NotNull PsiElement place) { PsiClassType closureType; PsiClass closureClass = JavaPsiFacade.getInstance(place.getProject()).findClass(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, place.getResolveScope()); if (closureClass == null) return null; if (closureClass.getTypeParameters().length != 1) { GradleLog.LOG.debug(String.format("Unexpected type parameters found for closureClass(%s) : (%s)", closureClass, Arrays.toString(closureClass.getTypeParameters()))); return null; } PsiElementFactory factory = JavaPsiFacade.getElementFactory(place.getManager().getProject()); if (closureTypeParameter != null) { PsiClassType closureClassTypeParameter = factory.createTypeByFQClassName(closureTypeParameter, place.getResolveScope()); closureType = factory.createType(closureClass, closureClassTypeParameter); } else { PsiClassType closureClassTypeParameter = factory.createTypeByFQClassName(CommonClassNames.JAVA_LANG_OBJECT, place.getResolveScope()); closureType = factory.createType(closureClass, closureClassTypeParameter); } GrLightMethodBuilder methodWithClosure = new GrLightMethodBuilder(place.getManager(), name); GrLightParameter closureParameter = new GrLightParameter("closure", closureType, methodWithClosure); methodWithClosure.addParameter(closureParameter); PsiClassType retType = factory.createTypeByFQClassName( returnType != null ? returnType : CommonClassNames.JAVA_LANG_OBJECT, place.getResolveScope()); methodWithClosure.setReturnType(retType); methodWithClosure.setContainingClass(retType.resolve()); return methodWithClosure; }