Search in sources :

Example 1 with ParameterCastFix

use of org.jetbrains.plugins.groovy.codeInspection.assignment.ParameterCastFix in project intellij-community by JetBrains.

the class GroovyTypeCheckVisitorHelper method genCastFixes.

@NotNull
public static LocalQuickFix[] genCastFixes(@NotNull GrSignature signature, @NotNull PsiType[] argumentTypes, @Nullable GrArgumentList argumentList) {
    if (argumentList == null)
        return LocalQuickFix.EMPTY_ARRAY;
    final List<GrExpression> args = getExpressionArgumentsOfCall(argumentList);
    if (args == null)
        return LocalQuickFix.EMPTY_ARRAY;
    final List<Pair<Integer, PsiType>> allErrors = new ArrayList<>();
    final List<GrClosureSignature> signatures = GrClosureSignatureUtil.generateSimpleSignatures(signature);
    for (GrClosureSignature closureSignature : signatures) {
        final GrClosureSignatureUtil.MapResultWithError<PsiType> map = GrClosureSignatureUtil.mapSimpleSignatureWithErrors(closureSignature, argumentTypes, id, argumentList, 1);
        if (map != null) {
            final List<Pair<Integer, PsiType>> errors = map.getErrors();
            for (Pair<Integer, PsiType> error : errors) {
                if (!(error.first == 0 && PsiImplUtil.hasNamedArguments(argumentList))) {
                    allErrors.add(error);
                }
            }
        }
    }
    final ArrayList<LocalQuickFix> fixes = new ArrayList<>();
    for (Pair<Integer, PsiType> error : allErrors) {
        if (args.size() > error.first && error.second != null) {
            fixes.add(new ParameterCastFix(error.first, error.second, args.get(error.first)));
        }
    }
    return fixes.toArray(new LocalQuickFix[fixes.size()]);
}
Also used : ArrayList(java.util.ArrayList) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrClosureSignatureUtil(org.jetbrains.plugins.groovy.lang.psi.impl.signatures.GrClosureSignatureUtil) ParameterCastFix(org.jetbrains.plugins.groovy.codeInspection.assignment.ParameterCastFix) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 Pair (com.intellij.openapi.util.Pair)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 ParameterCastFix (org.jetbrains.plugins.groovy.codeInspection.assignment.ParameterCastFix)1 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)1 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)1 GrClosureSignatureUtil (org.jetbrains.plugins.groovy.lang.psi.impl.signatures.GrClosureSignatureUtil)1