Search in sources :

Example 11 with GrLightMethodBuilder

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

the class ConstructorAnnotationsProcessor method applyTransformation.

@Override
public void applyTransformation(@NotNull TransformationContext context) {
    GrTypeDefinition typeDefinition = context.getCodeClass();
    if (typeDefinition.getName() == null)
        return;
    PsiModifierList modifierList = typeDefinition.getModifierList();
    if (modifierList == null)
        return;
    final PsiAnnotation tupleConstructor = modifierList.findAnnotation(GroovyCommonClassNames.GROOVY_TRANSFORM_TUPLE_CONSTRUCTOR);
    final boolean immutable = PsiImplUtil.hasImmutableAnnotation(modifierList);
    final boolean canonical = modifierList.findAnnotation(GroovyCommonClassNames.GROOVY_TRANSFORM_CANONICAL) != null;
    if (!immutable && !canonical && tupleConstructor == null) {
        return;
    }
    if (tupleConstructor != null && typeDefinition.getCodeConstructors().length > 0 && !PsiUtil.getAnnoAttributeValue(tupleConstructor, "force", false)) {
        return;
    }
    final GrLightMethodBuilder fieldsConstructor = generateFieldConstructor(typeDefinition, tupleConstructor, immutable, canonical);
    final GrLightMethodBuilder mapConstructor = generateMapConstructor(typeDefinition);
    context.addMethod(fieldsConstructor);
    context.addMethod(mapConstructor);
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)

Example 12 with GrLightMethodBuilder

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

the class InheritConstructorContributor method applyTransformation.

@Override
public void applyTransformation(@NotNull TransformationContext context) {
    GrTypeDefinition psiClass = context.getCodeClass();
    if (psiClass.isAnonymous() || psiClass.isInterface() || psiClass.isEnum()) {
        return;
    }
    if (!hasInheritConstructorsAnnotation(psiClass))
        return;
    final PsiClass superClass = context.getSuperClass();
    if (superClass == null)
        return;
    final PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, psiClass, PsiSubstitutor.EMPTY);
    for (PsiMethod constructor : superClass.getConstructors()) {
        if (constructor.hasModifierProperty(PsiModifier.PRIVATE))
            continue;
        final GrLightMethodBuilder inheritedConstructor = new GrLightMethodBuilder(context.getManager(), context.getClassName());
        inheritedConstructor.setConstructor(true);
        inheritedConstructor.setNavigationElement(psiClass);
        inheritedConstructor.addModifier(VisibilityUtil.getVisibilityModifier(constructor.getModifierList()));
        inheritedConstructor.setOriginInfo("created by @InheritConstructors");
        for (PsiParameter parameter : constructor.getParameterList().getParameters()) {
            String name = StringUtil.notNullize(parameter.getName());
            PsiType type = superClassSubstitutor.substitute(parameter.getType());
            inheritedConstructor.addParameter(name, type, false);
        }
        context.addMethod(inheritedConstructor);
    }
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)

Example 13 with GrLightMethodBuilder

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

the class TransformationContextImpl method doAddMethod.

private void doAddMethod(@NotNull PsiMethod method, boolean prepend) {
    if (method instanceof GrLightMethodBuilder) {
        ((GrLightMethodBuilder) method).setContainingClass(myCodeClass);
    } else if (method instanceof LightMethodBuilder) {
        ((LightMethodBuilder) method).setContainingClass(myCodeClass);
    }
    MethodSignature signature = method.getSignature(PsiSubstitutor.EMPTY);
    Set<MethodSignature> signatures = mySignaturesCache.get(method.getName());
    if (signatures.add(signature)) {
        if (prepend) {
            myMethods.addFirst(method);
        } else {
            myMethods.addLast(method);
        }
    }
}
Also used : MethodSignature(com.intellij.psi.util.MethodSignature) LightMethodBuilder(com.intellij.psi.impl.light.LightMethodBuilder) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)

Example 14 with GrLightMethodBuilder

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

the class StreamingJsonBuilderDelegateContributor method createMethod.

@NotNull
private static GrLightMethodBuilder createMethod(@NotNull String name, @NotNull PsiElement place, @NotNull PsiClass clazz) {
    GrLightMethodBuilder method = new GrLightMethodBuilder(place.getManager(), name);
    method.setModifiers(GrModifierFlags.PUBLIC_MASK);
    method.setReturnType(TypesUtil.getJavaLangObject(place));
    UtilsKt.setContainingClass(method, clazz);
    method.setOriginInfo(StreamingJsonBuilderContributor.ORIGIN_INFO);
    return method;
}
Also used : GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with GrLightMethodBuilder

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

the class XmlMarkupBuilderNonCodeMemberContributor method createMethod.

@NotNull
private static GrLightMethodBuilder createMethod(@NotNull String name, @NotNull PsiClass clazz, @NotNull PsiElement place) {
    GrLightMethodBuilder res = new GrLightMethodBuilder(place.getManager(), name);
    res.setReturnType(JAVA_LANG_STRING, place.getResolveScope());
    res.setOriginInfo(ORIGIN_INFO);
    UtilsKt.setContainingClass(res, clazz);
    return res;
}
Also used : GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) NotNull(org.jetbrains.annotations.NotNull)

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