Example #1
0
 private boolean tryApplyConstructor(InvocationExpr expr) {
   if (!expr.getMethod().getName().equals("<init>")) {
     return false;
   }
   if (resultSequence == null || resultSequence.isEmpty()) {
     return false;
   }
   Statement last = resultSequence.get(resultSequence.size() - 1);
   if (!(last instanceof AssignmentStatement)) {
     return false;
   }
   AssignmentStatement assignment = (AssignmentStatement) last;
   if (!(assignment.getLeftValue() instanceof VariableExpr)) {
     return false;
   }
   VariableExpr var = (VariableExpr) assignment.getLeftValue();
   if (!(expr.getArguments().get(0) instanceof VariableExpr)) {
     return false;
   }
   VariableExpr target = (VariableExpr) expr.getArguments().get(0);
   if (target.getIndex() != var.getIndex()) {
     return false;
   }
   if (!(assignment.getRightValue() instanceof NewExpr)) {
     return false;
   }
   NewExpr constructed = (NewExpr) assignment.getRightValue();
   if (!constructed.getConstructedClass().equals(expr.getMethod().getClassName())) {
     return false;
   }
   Expr[] args = expr.getArguments().toArray(new Expr[0]);
   args = Arrays.copyOfRange(args, 1, args.length);
   InvocationExpr constructrExpr = Expr.constructObject(expr.getMethod(), args);
   constructrExpr.setLocation(expr.getLocation());
   assignment.setRightValue(constructrExpr);
   readFrequencies[var.getIndex()]--;
   return true;
 }