Search in sources :

Example 16 with GrLightMethodBuilder

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.

the class JsonBuilderContributor method createMethod.

private static GrLightMethodBuilder createMethod(@NotNull String name, @NotNull PsiClass clazz, @NotNull PsiElement context) {
    GrLightMethodBuilder method = new GrLightMethodBuilder(context.getManager(), name);
    method.setOriginInfo(ORIGIN_INFO);
    method.addModifier(PsiModifier.PUBLIC);
    method.setReturnType(JAVA_UTIL_MAP, context.getResolveScope());
    UtilsKt.setContainingClass(method, clazz);
    return method;
}
Also used : GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)

Example 17 with GrLightMethodBuilder

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.

the class StreamingJsonBuilderContributor 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, place, qualifierType, clazz);
    if (!processor.process(method))
        return false;
    // (Closure)
    method = createMethod(name, place, qualifierType, clazz);
    addClosureParameter(method);
    if (!processor.process(method))
        return false;
    // (Map)
    method = createMethod(name, place, qualifierType, clazz);
    method.addParameter("args", JAVA_UTIL_MAP);
    if (!processor.process(method))
        return false;
    // (Map, Closure)
    method = createMethod(name, place, qualifierType, clazz);
    method.addParameter("args", JAVA_UTIL_MAP);
    addClosureParameter(method);
    if (!processor.process(method))
        return false;
    // (Iterable, Closure)
    method = createMethod(name, place, qualifierType, clazz);
    method.addParameter("values", TypesUtil.createIterableType(place, null), false);
    addClosureParameter(method);
    if (!processor.process(method))
        return false;
    // (Object[], Closure)
    method = createMethod(name, place, qualifierType, clazz);
    method.addParameter("values", TypesUtil.getJavaLangObject(place).createArrayType());
    addClosureParameter(method);
    return processor.process(method);
}
Also used : GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)

Example 18 with GrLightMethodBuilder

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.

the class ConstructorAnnotationsProcessor method generateFieldConstructor.

@NotNull
private static GrLightMethodBuilder generateFieldConstructor(@NotNull GrTypeDefinition typeDefinition, @Nullable PsiAnnotation tupleConstructor, boolean immutable, boolean canonical) {
    final GrLightMethodBuilder fieldsConstructor = new GrLightMethodBuilder(typeDefinition.getManager(), typeDefinition.getName());
    fieldsConstructor.setConstructor(true);
    fieldsConstructor.setNavigationElement(typeDefinition);
    fieldsConstructor.setContainingClass(typeDefinition);
    Set<String> excludes = new HashSet<>();
    if (tupleConstructor != null) {
        for (String s : PsiUtil.getAnnoAttributeValue(tupleConstructor, "excludes", "").split(",")) {
            final String name = s.trim();
            if (StringUtil.isNotEmpty(name)) {
                excludes.add(name);
            }
        }
    }
    if (tupleConstructor != null) {
        final boolean superFields = PsiUtil.getAnnoAttributeValue(tupleConstructor, "includeSuperFields", false);
        final boolean superProperties = PsiUtil.getAnnoAttributeValue(tupleConstructor, "includeSuperProperties", false);
        if (superFields || superProperties) {
            addParametersForSuper(typeDefinition, fieldsConstructor, superFields, superProperties, new HashSet<>(), excludes);
        }
    }
    addParameters(typeDefinition, fieldsConstructor, tupleConstructor == null || PsiUtil.getAnnoAttributeValue(tupleConstructor, "includeProperties", true), tupleConstructor != null ? PsiUtil.getAnnoAttributeValue(tupleConstructor, "includeFields", false) : !canonical, !immutable, excludes);
    if (immutable) {
        fieldsConstructor.setOriginInfo("created by @Immutable");
    } else if (tupleConstructor != null) {
        fieldsConstructor.setOriginInfo("created by @TupleConstructor");
    } else /*if (canonical != null)*/
    {
        fieldsConstructor.setOriginInfo("created by @Canonical");
    }
    return fieldsConstructor;
}
Also used : GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with GrLightMethodBuilder

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.

the class ConstructorAnnotationsProcessor method generateMapConstructor.

@NotNull
private static GrLightMethodBuilder generateMapConstructor(@NotNull GrTypeDefinition typeDefinition) {
    final GrLightMethodBuilder mapConstructor = new GrLightMethodBuilder(typeDefinition.getManager(), typeDefinition.getName());
    mapConstructor.addParameter("args", CommonClassNames.JAVA_UTIL_HASH_MAP, false);
    mapConstructor.setConstructor(true);
    mapConstructor.setContainingClass(typeDefinition);
    return mapConstructor;
}
Also used : GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with GrLightMethodBuilder

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.

the class NonCodeMembersHolder method createMethod.

private static GrLightMethodBuilder createMethod(Map prop, PsiElement place, PsiManager manager) {
    String name = String.valueOf(prop.get("name"));
    final GrLightMethodBuilder method = new GrLightMethodBuilder(manager, name).addModifier(PsiModifier.PUBLIC);
    if (Boolean.TRUE.equals(prop.get("constructor"))) {
        method.setConstructor(true);
    } else {
        method.setReturnType(convertToPsiType(String.valueOf(prop.get("type")), place));
    }
    final Object params = prop.get("params");
    if (params instanceof Map) {
        boolean first = true;
        for (Object paramName : ((Map) params).keySet()) {
            Object value = ((Map) params).get(paramName);
            boolean isNamed = first && value instanceof List;
            first = false;
            String typeName = isNamed ? CommonClassNames.JAVA_UTIL_MAP : String.valueOf(value);
            method.addParameter(String.valueOf(paramName), convertToPsiType(typeName, place), false);
            if (isNamed) {
                Map<String, NamedArgumentDescriptor> namedParams = ContainerUtil.newHashMap();
                for (Object o : (List) value) {
                    if (o instanceof CustomMembersGenerator.ParameterDescriptor) {
                        namedParams.put(((CustomMembersGenerator.ParameterDescriptor) o).name, ((CustomMembersGenerator.ParameterDescriptor) o).descriptor);
                    }
                }
                method.setNamedParameters(namedParams);
            }
        }
    }
    if (Boolean.TRUE.equals(prop.get("isStatic"))) {
        method.addModifier(PsiModifier.STATIC);
    }
    final Object bindsTo = prop.get("bindsTo");
    if (bindsTo instanceof PsiElement) {
        method.setNavigationElement((PsiElement) bindsTo);
    }
    final Object toThrow = prop.get(CustomMembersGenerator.THROWS);
    if (toThrow instanceof List) {
        for (Object o : ((List) toThrow)) {
            final PsiType psiType = convertToPsiType(String.valueOf(o), place);
            if (psiType instanceof PsiClassType) {
                method.addException((PsiClassType) psiType);
            }
        }
    }
    Object doc = prop.get("doc");
    if (doc instanceof String) {
        method.putUserData(DOCUMENTATION, (String) doc);
    }
    Object docUrl = prop.get("docUrl");
    if (docUrl instanceof String) {
        method.putUserData(DOCUMENTATION_URL, (String) docUrl);
    }
    Object qName = prop.get("containingClass");
    if (qName instanceof String) {
        PsiClass foundClass = JavaPsiFacade.getInstance(manager.getProject()).findClass(((String) qName), place.getResolveScope());
        if (foundClass != null) {
            method.setContainingClass(foundClass);
        }
    }
    return method;
}
Also used : NamedArgumentDescriptor(org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) CustomMembersGenerator(org.jetbrains.plugins.groovy.dsl.CustomMembersGenerator) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

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