Support Kotlin dependencies
This commit is contained in:
parent
8fcfcb49d7
commit
8f62162c2a
3 changed files with 93 additions and 0 deletions
|
@ -96,6 +96,65 @@ class JavaParser(TokenParser):
|
|||
pass
|
||||
|
||||
|
||||
class KotlinParser(TokenParser):
|
||||
state = None
|
||||
exclude = [
|
||||
r'^java\.',
|
||||
]
|
||||
|
||||
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):
|
||||
content = content.split(u('.'))
|
||||
|
||||
if len(content) == 0:
|
||||
return None
|
||||
|
||||
if len(content) == 1:
|
||||
return content[0]
|
||||
|
||||
if len(content[0]) == 3:
|
||||
content = content[1:]
|
||||
if content[-1] == u('*'):
|
||||
content = content[:len(content) - 1]
|
||||
|
||||
if len(content) == 0:
|
||||
return None
|
||||
elif len(content) == 1:
|
||||
content = content[0]
|
||||
elif len(content) > 1:
|
||||
content = u('.').join(content[:2])
|
||||
|
||||
return content
|
||||
|
||||
|
||||
class ScalaParser(TokenParser):
|
||||
state = None
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue