Class ParsingUtils


  • public class ParsingUtils
    extends Object
    This class contains utilities for parsing user input. It also contains mmm logic to parse user's input file in order to find needed information
    • Constructor Detail

      • ParsingUtils

        public ParsingUtils()
    • Method Detail

      • getJavaContext

        public static net.sf.mmm.code.impl.java.JavaContext getJavaContext​(File inputFile,
                                                                           File inputProject)
        Tries to get the Java context by creating a new class loader of the input project that is able to load the input file. We need this in order to perform reflection on the templates.
        Parameters:
        inputFile - input file the user wants to generate code from
        inputProject - input project where the input file is located. We need this in order to build the classpath of the input file
        Returns:
        the Java context created from the input project
      • getQualifiedName

        public static String getQualifiedName​(File inputFile,
                                              net.sf.mmm.code.impl.java.JavaContext context)
        Gets the full qualified name of the input file
        Parameters:
        inputFile - Java file we want to get its qualified name
        context - current java project context
        Returns:
        The full qualified name of the input file
      • parseRelativePath

        public static Boolean parseRelativePath​(ArrayList<File> inputFiles,
                                                File inputFile,
                                                int index)
        Tries to parse a relative path with the current working directory
        Parameters:
        inputFiles - list of all input files from the user
        inputFile - input file which we are going to parse to find out whether it is a valid file
        index - location of the input file in the ArrayList of inputs
        Returns:
        true only if the parsed file exists, false otherwise
      • getProjectRoot

        public static File getProjectRoot​(File inputFile)
        Tries to find the root folder of the project in order to build the classpath. This method is trying to find the first pom.xml file and then getting the folder where is located
        Parameters:
        inputFile - passed by the user
        Returns:
        the project folder
      • formatJavaSources

        public static void formatJavaSources​(Set<Path> generatedFiles)
                                      throws com.google.googlejavaformat.java.FormatterException
        This method format the runtime generated code with the help of google API
        Parameters:
        generatedFiles - List of generation report files
        Throws:
        com.google.googlejavaformat.java.FormatterException - if any error occurred while formatting the Java code