Class SourceContainer


  • public final class SourceContainer
    extends Object
    This class may be used to synthesize Python source code files. The current implementation can be used to synthesize a single Python source file which must contain one and only one class. Although this is expected in Java, Python source files may contain more than one class, amongst other things.
    • Constructor Detail

      • SourceContainer

        public SourceContainer()
        Empty default constructor.
    • Method Detail

      • initHeader

        public void initHeader​(String extraComment)
        Initialize the header of the Python source file with a simple comment.
        Parameters:
        extraComment - An extra line that will be put as a comment in the "header". This initialization should be called before any function related to the header.
      • addImportInfo

        public void addImportInfo​(List<String> importInfo)
        Put the import information into the Stub.
        Parameters:
        importInfo - A list of tuples, containing the data provided by the registrator.
      • importModule

        public void importModule​(String clsName)
        Add an import line to the header of the file.
        Parameters:
        clsName - The name of the import. The result will be simply _import clsName_.
      • initClassDef

        public void initClassDef​(String name,
                                 String parentName)
        Initialize the class definition. This initialization should be called before any function related to the class definition and body.
        Parameters:
        name - The name of the class.
        parentName - The name of the parent class.
      • addMethod

        public void addMethod​(String mthdName,
                              String[] params,
                              String[] mthdCode)
        Build a certain method definition and put it into the class.
        Parameters:
        mthdName - Name of the method.
        params - List of parameter names.
        mthdCode - A list of lines for the class --zero indentation.
      • endClass

        public void endClass()
        End the class. This may be done at any moment --not necessarily at the end. It simply puts a certain comment at the end of the class definition. Esthetic.
      • sourceToString

        public String sourceToString()
        Return the full source. Should be called at last.
        Returns:
        A very long string containing all the source code.
      • addMethod

        public void addMethod​(String[] implLines)
        Add an almost verbatim method into the body of the class.
        Parameters:
        implLines - List of code lines of the method. It should include the definition --at zero indentation-- and the body definition with correct relative indent.