Esempio n. 1
0
 @Override
 protected final Collection<Unit> getUnits() {
   Set<Unit> result = new HashSet<>();
   result.addAll(this.forwardEdges.keySet());
   this.forwardEdges.values().forEach(result::addAll);
   return result;
 }
 /**
  * Returns any duplicate elements from the given collection.
  *
  * @param <T> the generic type of the given collection.
  * @param c the given collection that might have duplicate elements.
  * @return a collection containing the duplicate elements of the given one. If no duplicates are
  *     found, an empty collection is returned.
  */
 public static <T> Collection<T> duplicatesFrom(Collection<T> c) {
   Set<T> duplicates = new HashSet<T>();
   if (isEmpty(c)) return duplicates;
   Set<T> onlyOne = new HashSet<T>();
   for (T e : c) {
     if (onlyOne.contains(e)) {
       duplicates.add(e);
       continue;
     }
     onlyOne.add(e);
   }
   return duplicates;
 }
Esempio n. 3
0
  /**
   * Create a method conveniently. The method is added to the class "TestClass". Parameters can be
   * given as an (positional) array of local variables (the "identity statements", required by Soot
   * to map parameters to local variables, are inserted automatically)
   */
  public SootMethod makeMethod(
      int modifier, String name, List<Local> params, soot.Type retType, List<Unit> bodyStmts) {
    SootMethod m =
        new SootMethod(
            name, params.stream().map(Local::getType).collect(toList()), retType, modifier);
    this.testClass.addMethod(m);
    Body body = Jimple.v().newBody(m);
    m.setActiveBody(body);

    // set the statements for the body.. first the identity statements, then the bodyStmts
    if (!m.isStatic()) {
      body.getLocals().add(localThis);
      body.getUnits()
          .add(Jimple.v().newIdentityStmt(localThis, Jimple.v().newThisRef(testClass.getType())));
    }
    IntStream.range(0, params.size())
        .forEach(
            pos -> {
              Local l = params.get(pos);
              ParameterRef pr = Jimple.v().newParameterRef(l.getType(), pos);
              body.getUnits().add(Jimple.v().newIdentityStmt(l, pr));
            });
    body.getUnits().addAll(bodyStmts);

    // set the locals for the body
    Set<Local> locals =
        Stream.concat(
                params.stream(),
                body.getUseAndDefBoxes()
                    .stream()
                    .filter(b -> b.getValue() instanceof Local)
                    .map(b -> (Local) b.getValue()))
            .collect(toSet());
    locals.removeAll(body.getLocals());
    body.getLocals().addAll(locals);

    return m;
  }
 /**
  * Creates a set containing the given elements.
  *
  * @param <T> the type of elements of the set to create.
  * @param elements the elements to store in the set.
  * @return the created set.
  * @since 1.1.5
  */
 public static <T> Set<T> set(T... elements) {
   if (elements == null) return null;
   Set<T> set = new LinkedHashSet<T>();
   for (T e : elements) set.add(e);
   return set;
 }