Search in sources :

Example 6 with GrTupleType

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

the class GppTypeConverter method isConvertible.

@Override
public Boolean isConvertible(@NotNull PsiType lType, @NotNull PsiType rType, @NotNull GroovyPsiElement context) {
    if (context instanceof GrListOrMap && context.getReference() instanceof LiteralConstructorReference && ((LiteralConstructorReference) context.getReference()).getConstructedClassType() != null)
        return null;
    if (rType instanceof GrTupleType) {
        final GrTupleType tupleType = (GrTupleType) rType;
        final PsiType expectedComponent = PsiUtil.extractIterableTypeParameter(lType, false);
        if (expectedComponent != null && isMethodCallConversion(context)) {
            PsiType[] parameters = tupleType.getParameters();
            if (parameters.length == 1) {
                PsiType tupleComponent = parameters[0];
                if (tupleComponent != null && TypesUtil.isAssignable(expectedComponent, tupleComponent, context) && hasDefaultConstructor(lType)) {
                    return true;
                }
            }
        }
    }
    return null;
}
Also used : LiteralConstructorReference(org.jetbrains.plugins.groovy.findUsages.LiteralConstructorReference) GrListOrMap(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap) GrTupleType(org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType) PsiType(com.intellij.psi.PsiType)

Example 7 with GrTupleType

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

the class GrClosureSignatureUtil method getSignatureApplicabilities.

private static List<Trinity<GrClosureSignature, ArgInfo<PsiType>[], ApplicabilityResult>> getSignatureApplicabilities(@NotNull GrSignature signature, @NotNull final PsiType[] args, @NotNull final PsiElement context) {
    final List<Trinity<GrClosureSignature, ArgInfo<PsiType>[], ApplicabilityResult>> results = new ArrayList<>();
    signature.accept(new GrRecursiveSignatureVisitor() {

        @Override
        public void visitClosureSignature(GrClosureSignature signature) {
            ArgInfo<PsiType>[] map = mapArgTypesToParameters(signature, args, context, false);
            if (map != null) {
                results.add(new Trinity<>(signature, map, isSignatureApplicableInner(map, signature)));
                return;
            }
            // check for the case foo([1, 2, 3]) if foo(int, int, int)
            if (args.length == 1 && PsiUtil.isInMethodCallContext(context)) {
                final GrClosureParameter[] parameters = signature.getParameters();
                if (parameters.length == 1 && parameters[0].getType() instanceof PsiArrayType) {
                    return;
                }
                PsiType arg = args[0];
                if (arg instanceof GrTupleType) {
                    PsiType[] _args = ((GrTupleType) arg).getComponentTypes();
                    map = mapArgTypesToParameters(signature, _args, context, false);
                    if (map != null) {
                        results.add(new Trinity<>(signature, map, isSignatureApplicableInner(map, signature)));
                    }
                }
            }
        }
    });
    return results;
}
Also used : Trinity(com.intellij.openapi.util.Trinity) GrRecursiveSignatureVisitor(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrRecursiveSignatureVisitor) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature) GrTupleType(org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType)

Aggregations

GrTupleType (org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType)7 Nullable (org.jetbrains.annotations.Nullable)3 PsiType (com.intellij.psi.PsiType)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)2 GrListOrMap (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap)2 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)2 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)2 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)2 GrIndexProperty (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty)2 GrGdkMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod)2 ASTNode (com.intellij.lang.ASTNode)1 TextRange (com.intellij.openapi.util.TextRange)1 Trinity (com.intellij.openapi.util.Trinity)1 com.intellij.psi (com.intellij.psi)1 PsiElement (com.intellij.psi.PsiElement)1 ResolveCache (com.intellij.psi.impl.source.resolve.ResolveCache)1 InheritanceUtil (com.intellij.psi.util.InheritanceUtil)1 ArrayUtil (com.intellij.util.ArrayUtil)1 Function (com.intellij.util.Function)1