scala-ide/scala-ide — pull request #188 by kaptoxic (2012-08-21 16:54:49+00:00)
Title: Quick fix type mismatch

Hi all,

I should have posted this pull request while ago, but now I refactored it a bit so I guess it is ready for pull request.

This is a small pull request, and it provides an implementation of quick fixes when a type missmatch error occurs - e.g. _"type mismatch: found Type; required Option[Type]"_ -> quick fixes suggest to wrap the result in `Some()`.
The implementation is designed to be extensible in a sense that developers can add their own cases of type mismatch and transformations.

For example if one wants to add a quick fix in case of _"type mismatch: List[T] but found List[List[T]]"_ to suggest `.flatten`, `.head` or `.last` call, one could use the add an [FoundToRequiredTypeCase object](https://github.com/kaptoxic/scala-ide/blob/quickFixTypeMismatch/org.scala-ide.sdt.core/src/scala/tools/eclipse/quickfix/TypeMismatchQuickFixProcessor.scala#L71) to the [cases list](https://github.com/kaptoxic/scala-ide/blob/quickFixTypeMismatch/org.scala-ide.sdt.core/src/scala/tools/eclipse/quickfix/TypeMismatchQuickFixProcessor.scala#L16) which represents all cases of type missmatch errors that should be covered.
Explanation on how to construct such objects is given in the source documentation. The object that does the mentioned quick fix is [here](https://github.com/kaptoxic/scala-ide/blob/quickFixTypeMismatch/org.scala-ide.sdt.core/src/scala/tools/eclipse/quickfix/TypeMismatchQuickFixProcessor.scala#L20).

#### Some notes on the pull request:
* Apparently sometimes, the quick fix processor is called multiple times, thus resulting in multiple (identical) quick fixes being offered.
Test case:
```scala
def f2(l: Option[Int]) = 4
val intVal = 5
f2(intVal) // <- quick fix here
```
When two identical (valid) quick fixes are offered. That is an issue of the quick fixe facility itself - should we submit a ticket maybe?

* Encountered a potential [code duplication](https://github.com/kaptoxic/scala-ide/blob/quickFixTypeMismatch/org.scala-ide.sdt.core/src/scala/tools/eclipse/quickfix/ScalaQuickFixProcessor.scala#L85) in the quick fix code. Note that XXX is added at the end of the method name...

Cheers,
Ivan