代写 html Java software Ob jective

Ob jective
OOSE, Workshop 3
Visitors Design Pattern with JavaParser
In this coursework, you will learn how to use the software framework called JavaParser and its documentation to build a static analyser. You will also understand how the visitor design pattern is applied in the implementation of such framework. This objective will be evaluated based on your ability to extend the VoidVisitorAdapter in JavaParser. This is to implement concrete detectors that traverses an Abstract Syntax Tree representation of a program code using the visitors design pattern.
Setup
Create a simple maven project without archtype using eclipse IDE:
1. • Check create a simple project (skip archetype selection). • Enter Group Id = oose.workshop3
• Artifact Id= workshop3
• Name = workshop3
• Click on pom.xml file and Include the following dependency:


com.github.javaparser
javaparser-core
3.12.0


2. Create a package called detectors to contain the four java classes for Tasks 1 and 2 highlighted below.
You may refer to the following link for how to create a simple maven project: https: //www.javaguides.net/2018/11/how-to-create-simple-maven-project-in.html
1

Task 1: (5 Marks)
A control flow statement in a method is characterised as a useless control flow when the control flow continues onto the same place regardless of whether or not the branch is taken. For example, having an empty statement block for an if statement:
if (argv.length == 1);
System.out.println( argv[0]);
if (argv.length == 0) {
// TODO: handle this case
}
There are other forms of control flows such as for, while, do…
Using the visitors design pattern, create the class UselessControlFlowDetector.java that detects useless control flow in java program code. Create a container class called Breakpoints.java to collect this observed behaviour as the visit method(s) imple- mented in detector transverses through the program structure. Finally, implement the class Driver.java that instantiates the detector and provides it with program code to operate on. Driver.java should print each detected pattern to command line in the format:
Useless Control Flows:
className =?, methodName =?, startline =?, endline =?
className =?, methodName =?, startline =?, endline =?

Task 2: (5 Marks)
Polymorphic recursion is a property of a program code where the parameter types of a method may change with each recursive invocation. Hence, in detecting a function that implements polymorphic recursion, the number of parameters and their types does not matter. For example, the methods named method1 in Test.java below implement polymorphic recursion.
class Test{
int x;
public void method1(String args[]){
method1(args);
}
public void method1(String args[],int x, Test t){
while and switch.
2

this.x =1;
method1(args);
}
}
Using the visitors design pattern, create the class RecursionDetector.java that de- tects polymorphic recursion in java program code. Use the container Breakpoints.java to collect observed recursive behaviour as the visit method(s) implemented in detec- tor transverses through the program structure. Also extend Driver.java to instantiate this detector and provide it with program code to operate on. Finally, the output of Driver.java for detected behaviour should be similar to Task 1, by printing the class and method name, and also start and end line of observed pattern to command line. in the format:
Polymorphic Recursions:
className =?, methodName =?, startline =?, endline =? className =?, methodName =?, startline =?, endline =? …
Hints
• You may need to reference JavaParser’s documentation which is available at: http: //www.javadoc.io/doc/com.github.javaparser/javaparser-core/3.12.0
• You may find the tool AstVisualizer – for visualising Abstract Syntax Trees of java programs useful for understanding the structure of that matches a desired behaviour. This tool can be downloaded from OOSE Moodle webpage.
• Finally, we will use Calculator.java that is available on Moodle to test your solutions. For example, we may refactor Calculator.java to introduce recursion or change the control flow to match a desired pattern. We assume there are no nested classes.
• We will also check the clarity of your solution, documentation and the extent it satisfies the SOLID software design principles.
Deliverables
Submission should be made electronically via Moodle for Workshop 3.
3

1. Attach your zipped maven project with your solutions to Task1 and Task2. State your name and registration number at the top of UselessControlFlowDetector.java, RecursionDetector.java, Breakpoints.java and Driver.java.
2. A runnable jar file of your project.
Assessment
Submissions is due by 16.30 on 15th March 2019. You should endeavour to attend each lab so you can get the necessary help from your tutor and demonstrators. As per the Code of Assessment policy regarding late submissions, submissions will be accepted for up to 5 working days beyond the due date. Any late submissions will be marked as if submitted on time, but reduced by 2 marks for each additional day. Submissions received more than 5 working days after the due date will receive an H (band value of 0).
Dr Inah Omoronyia, S152, School of Computing Science, University of Glasgow
4