Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program that takes a Java source file as an input. The program needs to collect the following pieces of information: imple Input import
Write a program that takes a Java source file as an input. The program needs to collect the following pieces of information:
imple Input import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.I0Exception; public class ContentReader \{ private File inputFile; public ContentReader(File file) \{ this. inputFile = file; \} public File getInputFile() \{ return inputFile; \} public void setInputFile(File inputFile) \{ this. inputFile = inputFile; \} public String read() throws IOException \{ BufferedReader br= new BufferedReader ( new FileReader(this.getInputFile())); StringBuilder sb= new StringBuilder(); try \{ String line =br, readLine () ; while (line != null) \{ sb. append (line); sb. append (System. lineSeparator( )); line =br. readLine () ; \} \} finally \{ br.close(); \} sb.trimToSize( ); String everything = sb. toString (); return everything; \} public static void main (String args[]) \{ ContentReader reader = new ContentReader(new File ("Person.java") try \{ System. out. print ln( reader. read()); \} catch (I0Exception e) \{ // TODO Auto-generated catch block e.printStackTrace( ); \} \} \} Dutput Examples 1. Line: 22 Method Declaration: public String read() Variables declared in this method declaration: [1] Line: 23 Variable Name: br [2] Line: 25 Variable Name: sb [3] Line: 27 Variable Name: line [3] Line: 38 Variable Name: everything 2. I am going to show the result for only one method call. You need to do it for all method calls (a regular method call or a constructor) Line Number: 44 Method Call: reader.read() Method Signature: read:0: Method Number of There is no parameter. Thus, this part name parameters is empty. This part should contain the types of parameters separated by comma or semicolon. 3. Line: 22 Method Declaration: public String read() There are many method calls within this method declaration or body whose receiver is a variable. I am going to show one example: Line: 35 Methods call: br.close() Method called on br: [BufferedReader, readLine, readLine] Line: 38 Methods call: sb.toString() Method called on sb: [StringBuilder, append, append, trimToSize] 4. Consider the following code example: public void addButton (Panel panel) ; Button b= new Button ( ) ; b.setVisible (true) ; b.setAttrib (0) ; panel.init ( ) ; panel.addElement ( b ) ; panel.setAttrib (b.getAttrib( )) ; Consider the b.getAttrib method call: Your program should print the following: Line: X Method Declaration: Y Line: Z Method Call: b.getAttrib( ) Methods that use b in their arguments: [addElement, setAttrib] Write a program that takes a Java source file as an input. The program needs to collect the following pieces of information: 1. For each method declaration, identify the variables declared in the method body along with the line number (2 Marks) 2. For each method call (mc) located in the source code, determine the signature of the method. A method signature consists of the method name, number of parameters and types of parameters. Consider that the method declarations correspond to method calls are located in the same file. (2 Marks) 3. For each method call (mc) located in a method body (mb), determine the receiver variable ( v) and collect those methods that are called on the same variable (including the method call that define the variable) prior to calling mc and are located within mb. (3 Marks) 4. For each method call (mc) located in a method body (mb) whose receiver is a variable (v), determine those methods that are called prior to calling mc, use v in their argument and are located within mb
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started