main.progAnal
Class ConditionChecker

java.lang.Object
  extended bymain.progAnal.ProgramAnalyser
      extended bymain.progAnal.ConditionChecker

public class ConditionChecker
extends ProgramAnalyser

Class to check conditions under which variables are assigned and used

Author:
cbishop

Constructor Summary
ConditionChecker(LinkedHashMap inputMap, String var, ArrayList methodNames)
          Constructor for ConditionChecker
 
Method Summary
 ArrayList arrayCheck()
          Return list of statements where variable appears to be being used like an array
 ArrayList assignBeforeUse(HashMap usageInAssignments)
          Return list of statements where variable is assigned with value in loop before it is used in that loop
 ArrayList assignedWithMethod(HashMap assignmentsInLoop)
          Return list of statement in which variable is assigned with output from method call
 ArrayList assignmentInFor(String what)
          Return list of statements where variable is assigned in a "for" loop declaration
 HashMap conditionAssignStatement()
          Return map containing assignment statements and branch statements where variable is condition for branch
 HashMap conditionForAssignmentBranch(HashMap assignmentsInBranch, HashMap inputLoopStatements)
          Return map containing incidences where assignment in branch is also in loop
 HashMap foundIn(String what, String where)
          Return map of statements found in loops or branches
 HashMap foundInAssignmentLoop(HashMap assignmentsInLoop, HashMap inputLoopStatements)
          Return variable statements occuring in assignment loops together with loop signatures and line numbers
 boolean indirectUse(HashMap foundInAssignmentLoop)
          Return true if assignment loop is dependent on assignment statement following conditional use for a given variable
 ArrayList nestedBooleanAssign(HashMap assignmentsInLoop)
          Return list of statements in which variable is indirectly toggled by being set twice within a loop, once in a nested loop, with opposing values
 boolean noAssignmentStatement()
          Return whether there is no assignment statement for variable
 boolean noDirectUsage()
          Return if variable is not used directly in the program
 boolean onlyOneAssignmentStatement()
          Return whether there is only one assignment statement for the variable in the program
 ArrayList otherAssignment(HashMap assignmentsInLoop)
          Return list of statements where variable is assigned with value from instantiation of new object, or assigned directly with boolean value
 HashMap outsideAssignLoop(HashMap inAssignLoop, String what)
          Return map of statements where variable is used outside of the loop in which it is assigned
 ArrayList reorganize()
          Return list of statements where variable appears to be being used as organizer
 ArrayList statementTypeCheck(HashMap assignmentsInLoop, String statementType)
          Return list of statement of a given type
 ArrayList transform(HashMap assignmentsInLoop)
          Return list of statements where variable appears to be being used as transformation
 ArrayList useForLoopCondition(HashMap foundInAssignmentLoop)
          Return ArrayList of statements where use in assignment loop is directly or indirectly related to loop condition
 
Methods inherited from class main.progAnal.ProgramAnalyser
afterEquals, arithExp, arithExp, branch, contains, control, inBrackets, is, isClass, isElse, isIf, isInArray, loop, methodStatement, printUse, removeSpaces, subString, throwStatement, tryCatchStatement
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConditionChecker

public ConditionChecker(LinkedHashMap inputMap,
                        String var,
                        ArrayList methodNames)
Constructor for ConditionChecker

Parameters:
var - Name of input variable
inputMap - Analysed map of variable statements
methodNames - List of method names in calss
Method Detail

noAssignmentStatement

public boolean noAssignmentStatement()
Return whether there is no assignment statement for variable

Returns:
boolean true is there is no assignment statement

onlyOneAssignmentStatement

public boolean onlyOneAssignmentStatement()
Return whether there is only one assignment statement for the variable in the program

Returns:
boolean true if there is only one assignment statement

foundIn

public HashMap foundIn(String what,
                       String where)
Return map of statements found in loops or branches

Parameters:
what - String being the category of statement
where - String signifying whether to look in loops or branches
Returns:
HashMap containing statement and loop/branch statement in which it is found

foundInAssignmentLoop

public HashMap foundInAssignmentLoop(HashMap assignmentsInLoop,
                                     HashMap inputLoopStatements)
Return variable statements occuring in assignment loops together with loop signatures and line numbers

Parameters:
assignmentsInLoop - HashMap of assignment statements found in loops
inputLoopStatements - HashMap of loop statements
Returns:
HashMap containing assignment statements and which loops they are in

useForLoopCondition

public ArrayList useForLoopCondition(HashMap foundInAssignmentLoop)
Return ArrayList of statements where use in assignment loop is directly or indirectly related to loop condition

Parameters:
foundInAssignmentLoop - HashMap of statement found in assignment loop
Returns:
ArrayList of statements that relate to loop condition

indirectUse

public boolean indirectUse(HashMap foundInAssignmentLoop)
Return true if assignment loop is dependent on assignment statement following conditional use for a given variable

Parameters:
foundInAssignmentLoop - HashMap of statements found in assignment loop
Returns:
boolean

assignmentInFor

public ArrayList assignmentInFor(String what)
Return list of statements where variable is assigned in a "for" loop declaration

Parameters:
what - String signfying the category of statement
Returns:
ArrayList of "for" loop assignments

noDirectUsage

public boolean noDirectUsage()
Return if variable is not used directly in the program

Returns:
boolean

conditionAssignStatement

public HashMap conditionAssignStatement()
Return map containing assignment statements and branch statements where variable is condition for branch

Returns:
HashMap

conditionForAssignmentBranch

public HashMap conditionForAssignmentBranch(HashMap assignmentsInBranch,
                                            HashMap inputLoopStatements)
Return map containing incidences where assignment in branch is also in loop

Parameters:
assignmentsInBranch - HashMap containing assignmentsInBranch
inputLoopStatements - HashMap containing loop statements
Returns:
HashMap

statementTypeCheck

public ArrayList statementTypeCheck(HashMap assignmentsInLoop,
                                    String statementType)
Return list of statement of a given type

Parameters:
assignmentsInLoop - HashMap of assignment statements found in loops
statementType - String being the type of statement to look for
Returns:
ArrayList of statements

outsideAssignLoop

public HashMap outsideAssignLoop(HashMap inAssignLoop,
                                 String what)
Return map of statements where variable is used outside of the loop in which it is assigned

Parameters:
inAssignLoop - HashMap containing usage/conditional statement found in assignment loop
what - String being category of statement
Returns:
HashMap

arrayCheck

public ArrayList arrayCheck()
Return list of statements where variable appears to be being used like an array

Returns:
ArrayList

reorganize

public ArrayList reorganize()
Return list of statements where variable appears to be being used as organizer

Returns:
ArrayList

transform

public ArrayList transform(HashMap assignmentsInLoop)
Return list of statements where variable appears to be being used as transformation

Parameters:
assignmentsInLoop - HashMap containing assignments in loops
Returns:
ArrayList

nestedBooleanAssign

public ArrayList nestedBooleanAssign(HashMap assignmentsInLoop)
Return list of statements in which variable is indirectly toggled by being set twice within a loop, once in a nested loop, with opposing values

Parameters:
assignmentsInLoop - HashMap of assignment statements in loop
Returns:
ArrayList

assignedWithMethod

public ArrayList assignedWithMethod(HashMap assignmentsInLoop)
Return list of statement in which variable is assigned with output from method call

Parameters:
assignmentsInLoop - HashMap of assignment statements found in loops
Returns:
ArrayList

assignBeforeUse

public ArrayList assignBeforeUse(HashMap usageInAssignments)
Return list of statements where variable is assigned with value in loop before it is used in that loop

Parameters:
usageInAssignments -
Returns:
ArrayList

otherAssignment

public ArrayList otherAssignment(HashMap assignmentsInLoop)
Return list of statements where variable is assigned with value from instantiation of new object, or assigned directly with boolean value

Parameters:
assignmentsInLoop - HashMap of assignment statement found in loops
Returns:
ArrayList