Exemplo n.º 1
0
 public ArrayList<LSDPredicate> getMethodLevelDependency() {
   String prefix = this.getPrefix();
   ArrayList<LSDPredicate> preds = new ArrayList<LSDPredicate>();
   preds.add(LSDPredicate.getPredicate(prefix + "_calls"));
   preds.add(LSDPredicate.getPredicate(prefix + "_accesses"));
   return preds;
 }
Exemplo n.º 2
0
 public LSDPredicate toClassLevel() {
   if (isConclusionPredicate()) return LSDPredicate.getPredicate("changed_type");
   else {
     if (predName.contains("accesses") || predName.contains("calls")) {
       String newPred = predName.substring(0, predName.indexOf('_')) + "_dependency";
       return LSDPredicate.getPredicate(newPred);
     } else return this;
   }
 }
Exemplo n.º 3
0
 public static ArrayList<LSDPredicate> getPredicates(int kind, int arity) {
   Collection<LSDPredicate> predicates = allowedPredicate.values();
   ArrayList<LSDPredicate> results = new ArrayList<LSDPredicate>();
   for (LSDPredicate pred : predicates) {
     if (pred.kind == kind && pred.arity() == arity) {
       results.add(pred);
     }
   }
   if (results.size() == 0) return null;
   return results;
 }
Exemplo n.º 4
0
 /** @param args */
 public static void main(String[] args) {
   LSDPredicate foo = LSDPredicate.getPredicate("deleted_field");
   assert foo.getName() == "deleted_field";
   assert foo.arity() == 1;
   assert null == LSDPredicate.getPredicate("added_bogusMethod");
   foo = LSDPredicate.getPredicate("added_inheritedmethod");
   assert foo.getName() == "added_inheritedmethod";
   assert foo.arity() == 3;
   ArrayList<LSDBinding> bindings = new ArrayList<LSDBinding>();
   LSDBinding binding = new LSDBinding(new LSDVariable("a", 'm'));
   bindings.add(binding);
   binding = new LSDBinding(new LSDVariable("c", 't'));
   bindings.add(binding);
   assert false == foo.typeChecks(bindings);
   binding = new LSDBinding(new LSDVariable("b", 't'));
   bindings.add(binding);
   assert true == foo.typeChecks(bindings);
   bindings = new ArrayList<LSDBinding>();
   binding = new LSDBinding(new LSDVariable("a", 'f'));
   bindings.add(binding);
   binding = new LSDBinding(new LSDVariable("c", 't'));
   bindings.add(binding);
   binding = new LSDBinding(new LSDVariable("b", 't'));
   bindings.add(binding);
   assert false == foo.typeChecks(bindings);
   assert foo.toString().equals("added_inheritedmethod(m,t,t)");
   System.out.println("Predicate tests succeeded.");
 }
Exemplo n.º 5
0
  public boolean allowedInSameRule(LSDPredicate conclusion, LSDPredicate antecedant) {
    if (antecedant != null) {
      boolean x = (this.kind == antecedant.kind);
      return x;
    }

    // 1. C: added_calls must have an A:
    // deleted_accesses or deleted_calls or deleted_fieldoftype or
    // inherited_method
    // 2. C: deleted_accesses or added_accesses must have an A:
    // past_accesses or past_calls.
    // 3. C: added_return or deleted_return must have deleted_return
    // or added_return.
    // 4. C: modified_method must have A: inherited_method or
    // before_accesses, before_calls.
    // 5. C: modified_type must have A: subtype.
    if (RestrictionOption.OPTION_PreferDependencePredicates) {
      if (conclusion.getName().indexOf("added_calls") != -1) {
        return (this.getName().indexOf("deleted_accesses") != 1
            || this.getName().indexOf("deleted_calls") != -1
            || this.getName().indexOf("deleted_fieldoftype") != -1
            || this.getName().indexOf("deleted_inheritedmethod") != -1);
      }
      if (conclusion.getName().indexOf("deleted_accesses") != -1
          || conclusion.getName().indexOf("added_accesses") != -1) {
        return (this.getName().indexOf("before_calls") != -1);
      }
      if (conclusion.getName().indexOf("added_return") != -1) {
        return (this.getName().indexOf("deleted_return") != -1);
      }
      if (conclusion.getName().indexOf("deleted_return") != -1) {
        return (this.getName().indexOf("add_return") != -1);
      }
      if (conclusion.getName().indexOf("_method") != -1) {
        return (this.getName().indexOf("before_calls") != -1
            || this.getName().indexOf("before_accesses") != -1
            || this.getName().indexOf("before_inheritedmethod") != -1);
      }
      if (conclusion.getName().indexOf("_type") != -1) {
        return (this.getName().indexOf("before_subtype") != -1
            || this.getName().indexOf("before_extends") != -1
            || this.getName().indexOf("before_implements") != -1);
      }
      if (conclusion.getName().indexOf("_inherited") != -1) {
        return (this.getName().indexOf("_subtype") != -1
            || this.getName().indexOf("_extends") != -1
            || this.getName().indexOf("_implements") != -1);
      }
    }

    // MK Change  022310
    if (conclusion.kind == DELETED) {
      return (this.kind == BEFORE);
    }
    if (RestrictionOption.OPTION_AllowAfterInAntecedent == true) {
      if (conclusion.kind == ADDED) {
        return (this.kind == DELETED || this.kind == BEFORE || this.kind == AFTER);
      }
    } else {
      if (conclusion.kind == ADDED) {
        return (this.kind == DELETED || this.kind == BEFORE);
      }
    }
    if (conclusion.kind == MODIFIED) {
      return (this.kind == BEFORE);
    }
    return false;
  }