_class.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import java_file
  2. from java_file import JavaFile
  3. from java_file import Line
  4. import java_modifiers
  5. import java_literals
  6. import typing
  7. from typing import List
  8. class ClassParser:
  9. def parse(self, file :JavaFile, current_line :Line) -> typing.Any:
  10. accessor = ''
  11. class_name_index = 1
  12. if java_modifiers.modifiers.get(current_line[class_name_index]):
  13. accessor = current_line[class_name_index]
  14. class_name_index += 1
  15. interface_or_abstract = ''
  16. if current_line[class_name_index] == java_literals.interface:
  17. interface_or_abstract = java_literals.interface
  18. class_name_index += 1
  19. # Note: 'interface abstract' is a valid declaration
  20. if current_line[class_name_index] == java_literals.abstract:
  21. interface_or_abstract = java_literals.abstract
  22. class_name_index += 1
  23. name = java_file.get_class_name(current_line[class_name_index])
  24. line = []
  25. if accessor != '': line.append(accessor)
  26. if interface_or_abstract != '': line.append(interface_or_abstract)
  27. line.append(java_literals._class)
  28. line.append(name)
  29. line.append('{')
  30. file.add_line(line)
  31. file.class_name = name