Skip to content
Sarah Abdelkhalek edited this page Aug 26, 2019 · 11 revisions

Welcome to the Java-Parser wiki! first of all instantiate the parser object

  • using input File
File file = new File("BubbleSort.java");
parser p=new  parser(file);   
  • using input String
String s = "public class BubbleSort {}";
parser p=new  parser(p);

Methods

  • Add Import Statements
    Method: addImportStatment
    • Takes as an input the import statements to be added.
    • Returns String containing the code after the addition.
String imports = "import java.io.BufferedReader;\r\n" +
                "import java.io.File;\r\n"+
                "import java.io.FileNotFoundException;\r\n" +
                "import java.io.FileReader;\r\n";
p.addImportStatment(imports);
  • Get All Classes Declarations
    Method: getClasses
    • Takes no input.
    • Returns ArrayList of all classes declerations as Strings.
p.getClasses();
  • Get a Class Body
    Method: getClassBody=
    • Take as an input order(zero-indexed) of the Class.
    • Return the Class's Body as a String.
p.getClassBody(0);
  • Refactor/Transform Class Body
    Method: refactorClassBody
    • Take as an input the order(zero-indexed) of the Class and the new body code.
    • Returns String containing the code after the transformation.
p.refactorClassBody(0, "//he new code" + p.getClassBody(0));
  • Get All Constructor Declarations
    Method: getClasses
    • Takes no input.
    • Returns ArrayList of all constructors declerations as Strings.
p.getConstructorDecleration();
  • Get All Methods Declarations
    Method: getMethodDeclerations
    • Takes no input.
    • Returns Array-list of all Methods declarations as Strings.
p.getMethodDeclerations();
  • Get a Method Body
    Method: getMethodBody
    • Take as an input the order(zero-indexed) of the Method.
    • Return the Methods's Body as a String.
p.getMethodBody(0);
  • Refactor/Transform Method Body
    Method: refactorMethodBody
    • Take as an input order(zero-indexed) of the Method and the new body code.
    • Returns String containing the code after the transformation.
p.refactorMethodBody(0, "//the new code" + p.getMethodBody(0));
  • Get the main Method Body
    Method: getMainMethodBody
    • Take as an input the order(zero-indexed) of the Method.
    • Return the Methods's Body as a String.
p.getMainMethodBody(0);
  • Refactor/Transform the main Method Body
    Method: refactorMethodBody
    • Takes as an input the new body code.
    • Returns String containing the code after the transformation.
p.refactorMainMethodBody("//the new code" + p.getMainMethodBody(0));
  • Get all Array Assignments (i.e. arr[index] = value;)
    Method: getArrayAssignment
    • Takes no input.
    • Returns ArrayList of all Array assignments as Strings.
p.getArrayAssignment();
  • Refactor/Transform an Array Assignment
    Method: refactorArrayAssignment
    • Takes as an input the order(zero-indexed) of the array Assignment instruction and the new code to be add instead of the chosen array assignment.
    • Returns String containing the code after the transformation.
p.refactorArrayAssignment(0,p.getArrayAssignment().get(0)+"//the new code");
Clone this wiki locally