Search in sources :

Example 1 with GrLightMethodBuilder

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;
}
Also used : GrLightParameter(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightParameter) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GrLightMethodBuilder

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);
}
Also used : PsiEllipsisType(com.intellij.psi.PsiEllipsisType) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)

Example 3 with GrLightMethodBuilder

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;
}
Also used : GrReflectedMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrReflectedMethod) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)

Example 4 with GrLightMethodBuilder

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);
}
Also used : GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)

Example 5 with GrLightMethodBuilder

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;
}
Also used : GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)

Aggregations

GrLightMethodBuilder (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)22 NotNull (org.jetbrains.annotations.NotNull)6 ElementClassHint (com.intellij.psi.scope.ElementClassHint)2 Nullable (org.jetbrains.annotations.Nullable)2 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)2 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)2 GrLightParameter (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightParameter)2 PsiEllipsisType (com.intellij.psi.PsiEllipsisType)1 LightMethodBuilder (com.intellij.psi.impl.light.LightMethodBuilder)1 MethodSignature (com.intellij.psi.util.MethodSignature)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 CustomMembersGenerator (org.jetbrains.plugins.groovy.dsl.CustomMembersGenerator)1 NamedArgumentDescriptor (org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor)1 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)1 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)1 GrReflectedMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrReflectedMethod)1 GrClosureParameter (org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter)1