Support for Scala dependency detection
This commit is contained in:
parent
edb046ec16
commit
165b6c0bb9
3 changed files with 65 additions and 0 deletions
14
tests/samples/codefiles/scala.scala
Normal file
14
tests/samples/codefiles/scala.scala
Normal file
|
@ -0,0 +1,14 @@
|
|||
package com.wakatime.test
|
||||
|
||||
import com.alpha.SomeClass
|
||||
import com.bravo.something.{User, UserPreferences}
|
||||
import com.charlie.{Delta => Foxtrot}
|
||||
import __root__.golf._
|
||||
import com.hotel.india._
|
||||
import juliett.kilo
|
||||
|
||||
object SimpleObject {
|
||||
def method(arg: String): String = {
|
||||
return "value"
|
||||
}
|
||||
}
|
|
@ -420,3 +420,18 @@ class DependenciesTestCase(TestCase):
|
|||
expected_lines=18,
|
||||
entity='objective-c.m',
|
||||
)
|
||||
|
||||
def test_scala_dependencies_detected(self):
|
||||
self.shared(
|
||||
expected_dependencies=[
|
||||
'com.alpha.SomeClass',
|
||||
'com.bravo.something',
|
||||
'com.charlie',
|
||||
'golf',
|
||||
'com.hotel.india',
|
||||
'juliett.kilo',
|
||||
],
|
||||
expected_language='Scala',
|
||||
expected_lines=14,
|
||||
entity='scala.scala',
|
||||
)
|
||||
|
|
|
@ -94,3 +94,39 @@ class JavaParser(TokenParser):
|
|||
|
||||
def _process_other(self, token, content):
|
||||
pass
|
||||
|
||||
|
||||
class ScalaParser(TokenParser):
|
||||
state = None
|
||||
|
||||
def parse(self):
|
||||
for index, token, content in self.tokens:
|
||||
self._process_token(token, content)
|
||||
return self.dependencies
|
||||
|
||||
def _process_token(self, token, content):
|
||||
if self.partial(token) == 'Keyword':
|
||||
self._process_keyword(token, content)
|
||||
elif self.partial(token) == 'Text':
|
||||
self._process_text(token, content)
|
||||
elif self.partial(token) == 'Namespace':
|
||||
self._process_namespace(token, content)
|
||||
else:
|
||||
self._process_other(token, content)
|
||||
|
||||
def _process_keyword(self, token, content):
|
||||
self.state = content
|
||||
|
||||
def _process_text(self, token, content):
|
||||
pass
|
||||
|
||||
def _process_namespace(self, token, content):
|
||||
if self.state == 'import':
|
||||
self.append(self._format(content))
|
||||
self.state = None
|
||||
|
||||
def _process_other(self, token, content):
|
||||
self.state = None
|
||||
|
||||
def _format(self, content):
|
||||
return content.strip().lstrip('__root__').strip('_').strip('.')
|
||||
|
|
Loading…
Reference in a new issue