/** * Determine if the given method should be instrumented * * @param className * @param methodName * @return */ public static boolean shouldInstrument(String className, String methodName) { // Always analyze if it is a target class if (isTargetClassName(className)) return true; // Also analyze if it is a superclass and instrument_parent = true if (Properties.INSTRUMENT_PARENT) { if (inheritanceTree.getSuperclasses(Properties.TARGET_CLASS).contains(className)) return true; } // Also analyze if it is in the calltree and we are considering the // context if (Properties.INSTRUMENT_CONTEXT) { CallGraph callGraph = callGraphs.get(Properties.TARGET_CLASS); if (callGraph != null && callGraph.isCalledMethod(className, methodName)){ if(Properties.INSTRUMENT_LIBRARIES || DependencyAnalysis.isTargetProject(className)) return true; } } return false; }
private static void analyze(String className, List<String> classPath) throws RuntimeException, ClassNotFoundException { if (!inheritanceTree.hasClass(Properties.TARGET_CLASS)) { throw new ClassNotFoundException("Target class not found in inheritance tree"); } logger.debug("Calculate call tree"); CallGraph callGraph = CallGraphGenerator.analyze(className); callGraphs.put(className, callGraph); loadCallTreeClasses(callGraph); // include all the project classes in the inheritance tree and in the callgraph. if (ArrayUtil.contains(Properties.CRITERION, Criterion.IBRANCH) || Properties.INSTRUMENT_CONTEXT) { for (String classn : inheritanceTree.getAllClasses()) { if (isTargetProject(classn)) { CallGraphGenerator.analyzeOtherClasses(callGraph, classn); } } } // TODO: Need to make sure that all classes in calltree are instrumented logger.debug("Update call tree with calls to overridden methods"); CallGraphGenerator.update(callGraph, inheritanceTree); logger.debug("Create test cluster"); // if a class is not instrumented but part of the callgraph, the // generateCluster method will instrument it // update: we instrument only classes reachable from the class // under test, the callgraph is populated with all classes, but only the // set of relevant ones are instrumented - mattia TestGenerationContext.getInstance().getTestClusterGenerator().generateCluster(callGraph); gatherStatistics(); }
try { if (callGraph.isCalledClass(callTreeClass)) { if (!Properties.INSTRUMENT_LIBRARIES && !DependencyAnalysis.isTargetProject(callTreeClass)) continue; TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(callTreeClass);
if(!limitToCUT && (!Properties.INSTRUMENT_LIBRARIES && !DependencyAnalysis.isTargetProject(className))) continue; final MethodNameMatcher matcher = new MethodNameMatcher();