scala-ide/scala-refactoring — pull request #49 by VladimirNik (2014-04-21 20:06:36+00:00)
Title: Added: AddField refactoring, type params to AddMethod

This pull request is intended to improve abstract members implementation [feature](https://github.com/scala-ide/scala-ide/pull/672) for Scala IDE.
In that feature [AddMethod](https://github.com/scala-ide/scala-refactoring/blob/master/org.scala-refactoring.library/src/main/scala/scala/tools/refactoring/implementations/AddMethod.scala) is used to generate stubs for abstract members.

In context of abstract members implementation there are 2 main limitations related to AddMethod:
1) there is no similar refactoring for val/var generation
2) In current AddMethod implementation type parameters for defs can't be passed.

Changes in this pull request:
1) Added type parameters processing inside AddMethod.
2) Added AddField refactoring (for val/var generation).

Implementation limitations in pull request:
1) Type parameters processing in AddMethod:
there is an issue if pass several type params to mkDefDef inside [addMethod](https://github.com/VladimirNik/scala-refactoring/blob/69d1075e7a7fba432d203d845523f8d14fe178f8/org.scala-refactoring.library/src/main/scala/scala/tools/refactoring/implementations/AddMethod.scala#L31).
To overcome this issue in pull request all required type parameters names are grouped in one passed typeDef:

```scala
val typeDef =
new TypeDef(NoMods, newTypeName(typeParameters.mkString(", ")), Nil, EmptyTree)
```
this typeDef is used while constructing result newDef in mkDefDef.

2) AddField:
var printing is implemented with direct var [addition](https://github.com/VladimirNik/scala-refactoring/blob/69d1075e7a7fba432d203d845523f8d14fe178f8/org.scala-refactoring.library/src/main/scala/scala/tools/refactoring/implementations/AddField.scala#L18) (otherwise var is not printed):

```scala
NoSymbol.newVariable(newTermName(s"${nme.VARkw} " + valName))
```