use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class GradleResolverUtil method createMethodWithClosure.
@Nullable
public static GrLightMethodBuilder createMethodWithClosure(@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;
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class StreamingJsonBuilderDelegateContributor method processDynamicMethods.
@Override
boolean processDynamicMethods(@NotNull PsiType qualifierType, @NotNull PsiClass clazz, @NotNull String name, @NotNull PsiElement place, @NotNull Processor<PsiElement> processor) {
GrLightMethodBuilder method;
// (Object...)
method = createMethod(name, place, clazz);
method.addParameter("values", new PsiEllipsisType(TypeUtils.getObjectType(place)));
if (!processor.process(method))
return false;
// (Closure)
method = createMethod(name, place, clazz);
addClosureParameter(method);
if (!processor.process(method))
return false;
// (Iterable, Closure)
method = createMethod(name, place, clazz);
method.addParameter("values", TypesUtil.createIterableType(place, null));
addClosureParameter(method);
if (!processor.process(method))
return false;
// (Object[], Closure)
method = createMethod(name, place, clazz);
method.addParameter("values", TypesUtil.getJavaLangObject(place).createArrayType());
addClosureParameter(method);
if (!processor.process(method))
return false;
// (Object, Closure)
method = createMethod(name, place, clazz);
method.addParameter("value", TypesUtil.getJavaLangObject(place));
addClosureParameter(method);
return processor.process(method);
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class XmlMarkupBuilderNonCodeMemberContributor method processDynamicMethods.
@Override
boolean processDynamicMethods(@NotNull PsiType qualifierType, @NotNull PsiClass clazz, @NotNull String name, @NotNull PsiElement place, @NotNull Processor<PsiElement> processor) {
GrLightMethodBuilder res;
// ()
res = createMethod(name, clazz, place);
if (!processor.process(res))
return false;
// (Closure)
res = createMethod(name, clazz, place);
res.addAndGetParameter("body", GROOVY_LANG_CLOSURE, false).putUserData(DELEGATES_TO_KEY, FQN);
if (!processor.process(res))
return false;
// (Object, Closure)
res = createMethod(name, clazz, place);
res.addParameter("value", JAVA_LANG_OBJECT, false);
res.addAndGetParameter("body", GROOVY_LANG_CLOSURE, false).putUserData(DELEGATES_TO_KEY, FQN);
if (!processor.process(res))
return false;
// (Map, Closure)
res = createMethod(name, clazz, place);
res.addParameter("attributes", JAVA_UTIL_MAP, false);
res.addAndGetParameter("body", GROOVY_LANG_CLOSURE, false).putUserData(DELEGATES_TO_KEY, FQN);
if (!processor.process(res))
return false;
// (Map)
// (Map, Object)
// (Map, Object, Closure)
res = createMethod(name, clazz, place);
res.addParameter("attributes", JAVA_UTIL_MAP, false);
res.addParameter("value", JAVA_LANG_OBJECT, true);
res.addAndGetParameter("body", GROOVY_LANG_CLOSURE, true).putUserData(DELEGATES_TO_KEY, FQN);
for (GrReflectedMethod method : res.getReflectedMethods()) {
if (!processor.process(method))
return false;
}
// (Object)
// (Object, Map)
// (Object, Map, Closure)
res = createMethod(name, clazz, place);
res.addParameter("value", JAVA_LANG_OBJECT, false);
res.addParameter("attributes", JAVA_UTIL_MAP, true);
res.addAndGetParameter("body", GROOVY_LANG_CLOSURE, true).putUserData(DELEGATES_TO_KEY, FQN);
for (GrReflectedMethod method : res.getReflectedMethods()) {
if (!processor.process(method))
return false;
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class JsonBuilderContributor method processDynamicMethods.
@Override
boolean processDynamicMethods(@NotNull PsiType qualifierType, @NotNull PsiClass clazz, @NotNull String name, @NotNull PsiElement place, @NotNull Processor<PsiElement> processor) {
GrLightMethodBuilder method;
// ()
method = createMethod(name, clazz, place);
if (!processor.process(method))
return false;
// (Closure)
method = createMethod(name, clazz, place);
method.addAndGetParameter("c", GROOVY_LANG_CLOSURE, false).putUserData(DELEGATES_TO_KEY, DELEGATE_FQN);
if (!processor.process(method))
return false;
// (Map)
method = createMethod(name, clazz, place);
method.addParameter("map", JAVA_UTIL_MAP, false);
if (!processor.process(method))
return false;
// (Map, Closure)
method = createMethod(name, clazz, place);
method.addParameter("map", JAVA_UTIL_MAP, false);
method.addAndGetParameter("c", GROOVY_LANG_CLOSURE, false).putUserData(DELEGATES_TO_KEY, DELEGATE_FQN);
if (!processor.process(method))
return false;
// (Iterable, Closure)
method = createMethod(name, clazz, place);
method.addParameter("value", TypesUtil.createIterableType(place, null), false);
method.addAndGetParameter("c", GROOVY_LANG_CLOSURE, false).putUserData(DELEGATES_TO_KEY, DELEGATE_FQN);
if (!processor.process(method))
return false;
// (Object[], Closure)
method = createMethod(name, clazz, place);
method.addParameter("value", TypesUtil.getJavaLangObject(place).createArrayType(), false);
method.addAndGetParameter("c", GROOVY_LANG_CLOSURE, false).putUserData(DELEGATES_TO_KEY, DELEGATE_FQN);
return processor.process(method);
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.
the class JsonDelegateContributor method createMethod.
private static GrLightMethodBuilder createMethod(@NotNull String name, @NotNull PsiClass clazz, @NotNull PsiElement context) {
GrLightMethodBuilder method = new GrLightMethodBuilder(context.getManager(), name);
method.setOriginInfo(JsonBuilderContributor.ORIGIN_INFO);
method.addModifier(PsiModifier.PUBLIC);
UtilsKt.setContainingClass(method, clazz);
return method;
}
Aggregations