void (QuickFixActionRegistrar registrar, PsiExpression qualifier, PsiJavaCodeReferenceElement ref, TextRange fixRange) { String referenceName = ref.getReferenceName(); if (referenceName == null) return; if (qualifier instanceof PsiReferenceExpression) { PsiElement resolve = ((PsiReferenceExpression)qualifier).resolve(); if (resolve == null) return; if (resolve instanceof PsiParameter && ((PsiParameter)resolve).getTypeElement() == null) { PsiMethodCallExpression callExpression = PsiTreeUtil.getParentOfType(resolve, PsiMethodCallExpression.class); if (callExpression != null) { JavaResolveResult result = callExpression.resolveMethodGenerics(); if (result instanceof MethodCandidateInfo && ((MethodCandidateInfo)result).getInferenceErrorMessage() != null) { return; } } } } PsiElement gParent = ref.getParent(); List<PsiType> conjuncts = GuessManager.getInstance(qualifier.getProject()).getControlFlowExpressionTypeConjuncts(qualifier); for (PsiType conjunct : conjuncts) { PsiClass psiClass = PsiUtil.resolveClassInType(conjunct); if (psiClass == null) continue; if (gParent instanceof PsiMethodCallExpression) { if (psiClass.findMethodsByName(referenceName).length == 0) { continue; } } else if (psiClass.findFieldByName(referenceName, true) == null) { continue; } registrar.register(fixRange, new AddTypeCastFix(conjunct, qualifier, QuickFixBundle.message("fix.expression.role.qualifier")).asIntention(), null); } }