Package org.trifort.rootbeer.compiler

Source Code of org.trifort.rootbeer.compiler.FindMethodCalls

/*
* Copyright 2012 Phil Pratt-Szeliga and other contributors
* http://chirrup.org/
*
* See the file LICENSE for copying permission.
*/

package org.trifort.rootbeer.compiler;

import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import soot.Body;
import soot.PatchingChain;
import soot.SootMethod;
import soot.Unit;
import soot.Value;
import soot.ValueBox;
import soot.jimple.InvokeExpr;

public class FindMethodCalls {
   
  public FindMethodCalls(){
  }
 
  public Set<SootMethod> findForBody(Body body) {
    Set<SootMethod> methods = new LinkedHashSet<SootMethod>();   
    PatchingChain<Unit> chain = body.getUnits();
    Iterator<Unit> iter = chain.iterator();
    while(iter.hasNext()){
      Unit unit = iter.next();
      List<ValueBox> vboxes = unit.getUseAndDefBoxes();
      for(ValueBox vbox : vboxes){
        Value value = vbox.getValue();
        if(value instanceof InvokeExpr == false)
          continue;
        InvokeExpr expr = (InvokeExpr) value;
        SootMethod method = expr.getMethod();
        if(methods.contains(method) == false)
          methods.add(method);
      }
    }
    return methods;
  }
 
  public Set<SootMethod> findForMethod(SootMethod method){
    if(method.isConcrete() == false){
      return new HashSet<SootMethod>();
    }
    Body body = method.getActiveBody();
    return findForBody(body);
  }
}
TOP

Related Classes of org.trifort.rootbeer.compiler.FindMethodCalls

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.