forked from scala-ide/scala-ide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add semantic highlighting for type Dynamic
Calls like `d.foo(1)` or `d.foo(param = 1)` are treated as method calls whereas calls like `d.foo` or `d.foo = 1` are treated as vars. It can be that a call to `d.foo` must not be a mutable field but an immutable one when no corresponding call to `updateDynamic` is done before. However, in such a case `foo` is highlighted as a var becuase it is impossible for the IDE to detect such runtime informations. Fixes #1001656
- Loading branch information
Showing
3 changed files
with
164 additions
and
4 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
....sdt.core.tests/src/scala/tools/eclipse/semantichighlighting/classifier/DynamicTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package scala.tools.eclipse.semantichighlighting.classifier | ||
|
||
import SymbolTypes._ | ||
import org.junit._ | ||
|
||
class DynamicTest extends AbstractSymbolClassifierTest { | ||
|
||
@Test | ||
def selectDynamic() { | ||
checkSymbolClassification(""" | ||
object X { | ||
(new D).field | ||
} | ||
import language.dynamics | ||
class D extends Dynamic { | ||
def selectDynamic(name: String) = name | ||
} | ||
""", """ | ||
object X { | ||
(new D).$VAR$ | ||
} | ||
import language.dynamics | ||
class D extends Dynamic { | ||
def selectDynamic(name: String) = name | ||
} | ||
""", | ||
Map("VAR" -> TemplateVar)) | ||
} | ||
|
||
@Test | ||
def updateDynamic() { | ||
checkSymbolClassification(""" | ||
object X { | ||
val d = new D | ||
d.field = 10 | ||
d.field | ||
} | ||
import language.dynamics | ||
class D extends Dynamic { | ||
var map = Map.empty[String, Any] | ||
def selectDynamic(name: String) = | ||
map(name) | ||
def updateDynamic(name: String)(value: Any) { | ||
map += name -> value | ||
} | ||
} | ||
""", """ | ||
object X { | ||
val d = new D | ||
d.$VAR$ = 10 | ||
d.$VAR$ | ||
} | ||
import language.dynamics | ||
class D extends Dynamic { | ||
var map = Map.empty[String, Any] | ||
def selectDynamic(name: String) = | ||
map(name) | ||
def updateDynamic(name: String)(value: Any) { | ||
map += name -> value | ||
} | ||
} | ||
""", | ||
Map("VAR" -> TemplateVar)) | ||
} | ||
|
||
@Test | ||
def applyDynamic() { | ||
checkSymbolClassification(""" | ||
object X { | ||
val d = new D | ||
d.method(10) | ||
d(10) | ||
} | ||
import language.dynamics | ||
class D extends Dynamic { | ||
def applyDynamic(name: String)(value: Any) = name | ||
} | ||
""", """ | ||
object X { | ||
val d = new D | ||
d.$METH$(10) | ||
d(10) | ||
} | ||
import language.dynamics | ||
class D extends Dynamic { | ||
def applyDynamic(name: String)(value: Any) = name | ||
} | ||
""", | ||
Map("METH" -> Method)) | ||
} | ||
|
||
@Test | ||
def applyDynamicNamed() { | ||
checkSymbolClassification(""" | ||
object X { | ||
val d = new D | ||
d.method(value = 10) | ||
} | ||
import language.dynamics | ||
class D extends Dynamic { | ||
def applyDynamicNamed(name: String)(value: (String, Any)) = name | ||
} | ||
""", """ | ||
object X { | ||
val d = new D | ||
d.$METH$($ARG$ = 10) | ||
} | ||
import language.dynamics | ||
class D extends Dynamic { | ||
def applyDynamicNamed(name: String)(value: (String, Any)) = name | ||
} | ||
""", | ||
Map("METH" -> Method, "ARG" -> Param)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters