Support for Scala dependency detection

This commit is contained in:
Alan Hamlett 2018-03-11 18:09:25 -07:00
parent edb046ec16
commit 165b6c0bb9
3 changed files with 65 additions and 0 deletions

View 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"
}
}

View file

@ -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',
)

View file

@ -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('.')