Fix main function detector

So here's another attempt to fix the `main` function detector. It's a follow-up to my previous pull request, JetBrains/kotlin#338. (I hoped to have this ready much sooner, but... oh well...).

I refactored my original code from the previous pull request so that it gets already resolved descriptors from `BindingContext` when possible and uses `ResolveSession` when needed. I also tried to add few tests, but I'm not sure they are at the correct place.