boolean (PsiElement element, PsiElement context, PsiType expectedType, PsiSubstitutor substitutor) { if (element instanceof PsiMethod && isReturnTypeInferrable((PsiMethod)element, context, expectedType, substitutor)) { return true; } PsiType typeByElement = FilterUtil.getTypeByElement(element, context); if (typeByElement == null) { return false; } if (substitutor != null) { typeByElement = substitutor.substitute(typeByElement); } if (!allowBoxing(context) && (expectedType instanceof PsiPrimitiveType != typeByElement instanceof PsiPrimitiveType)) { return false; } try { return expectedType.isAssignableFrom(typeByElement); } catch (Throwable e) { if (ExceptionUtil.getRootCause(e) instanceof PsiInvalidElementAccessException) { PsiUtil.ensureValidType(expectedType); throw new RuntimeException("Invalid type of " + element.getClass(), e); } throw e; } }