package wcanalysis.heuristic;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import isstac.structure.cfg.Block;
import isstac.structure.cfg.CFG;
import isstac.structure.cfg.CFGGenerator;

/**
 * @author Kasper Luckow
 *
 */
public abstract class PathProjector {

  private final CFGGenerator cfgGenerator;
  public PathProjector(CFGGenerator cfgGenerator) {
    this.cfgGenerator = cfgGenerator;
  }
  
  public Collection<CFG> projectPath(Path path) {
    if(path.size() < 1)
      return null;
    CFG cfg = null;
    Decision prevDecision = null;
    
    Set<CFG> transformedCFGs = new HashSet<>();
    
    for(Decision dec : path) {
      
      BranchInstruction currInstruction = dec.getInstruction();
      //We optimize cfg extraction a bit here...
      if(prevDecision == null ||
          (prevDecision != null && !currInstruction.getMethodName().equals(prevDecision.getInstruction().getMethodName()))) {
        cfg = this.cfgGenerator.getCFG(currInstruction.getClassName(), currInstruction.getMethodName());
        transformedCFGs.add(cfg);
      }
      assert cfg != null;
      
      int instrIdx = currInstruction.getInstructionIndex();      
      Block condBlock = cfg.getBlockWithIndex(instrIdx);

      this.projectDecision(condBlock, dec);

      prevDecision = dec;
    }
    return transformedCFGs;
  }
  
  protected abstract void projectDecision(Block basicBlock, Decision dec);
}

@@ -100,16 +100,49 @@
 til.Set;
+%0Aimport java.util.logging.Logger;
 %0A%0Aimport
@@ -203,16 +203,63 @@
 fg.CFG;%0A
+import isstac.structure.cfg.CFGBuildException;%0A
 import i
@@ -411,16 +411,104 @@
 erator;%0A
+  private static final Logger logger = Logger.getLogger(PathProjector.class.getName());%0A
   public
@@ -1107,24 +1107,40 @@
 Name()))) %7B%0A
+        try %7B%0A  
         cfg 
@@ -1240,16 +1240,18 @@
         
+  
 transfor
@@ -1278,23 +1278,196 @@
     
-%7D%0A      assert 
+  %7D catch (CFGBuildException e) %7B%0A          logger.severe(e.getMessage());%0A          logger.severe(%22Is the classpath set up correctly for the CFG generator?%22);%0A        %7D%0A%0A      %7D%0A      if(
 cfg 
@@ -1477,17 +1477,14 @@
 null
-;%0A    
+) %7B%0A
   
-%0A
     
@@ -1541,24 +1541,26 @@
 ex();      %0A
+  
       Block 
@@ -1607,24 +1607,26 @@
 dx);%0A%0A      
+  
 this.project
@@ -1651,16 +1651,23 @@
 , dec);%0A
+      %7D
 %0A      p

Update cfg extractor with more meaningful exceptions when classpath is incomplete for finding classes