manucapo / Gardener

A project to automatically generate plantUML sequence diagrams from java methods.
MIT License
3 stars 2 forks source link

Find a Better way for the user to pass information to the program #7

Open manucapo opened 2 years ago

manucapo commented 2 years ago

Currently Information is passed by the user to the program piece by piece.

For example

   String pathToSequenceDiagram = "Diagrams\\sequenceDiagram.txt";        
   String fileName = "TestMethod.java";
   String path = "src";                       
   String packageName = "com.EiriniManu";
   String className = "TestMethod";
   String methodName = "Test3";

   // 1) Parse the given java class for information on a method
   parser.ParseMethodFromClass(parser.ParseFile(fileName, parser.SetSourceRoot(path,packageName)), className, methodName);

   // 2) Update the information structure that contains metadata on the method the user wants to display as a diagram
    sequenceDiagramGenerator.updateDiagramStructure("Test3", testMethod, String.class, int.class, boolean.class);

    // 3) Generate plantUML sequence diagram using the updated information structure.
    sequenceDiagramGenerator.generateSequenceDiagram(pathToSequenceDiagram);

Can we package the required information in a better way so that only one parameter needs to be passed to the API ?

manucapo commented 2 years ago

One possibility could be to implement a helper method that takes a custom data structure as a parameter and then distributes the needed information to the program as necessary.

That way the user only needs to interact with the program through a single API endpoint.

In other words:

The goal is to replace our current main() method by a single function call that takes as little parameters as possible

eirinikrev commented 2 years ago

Not quite sure how to do it the described way but this is what I managed :

private static HashMap<String, String> parseInput(String input) { HashMap<String, String> map = new HashMap<String, String>(); List parameters = Arrays.asList("fileName, path, packageName, className, methodName");

    List<String> values = Arrays.asList(input.split("\\s+"));
    for(int i=0; i<parameters.size(); i++){
        map.put(parameters.get(i), values.get(i));
    }
    return map;
}