public ConstructFixContainmentCheck(ConstructId _c, JarAnalyzer _ja, ConstructChange _cc) { this.constructId = _c; this.ja = _ja; this.repo = _cc.getRepo(); this.repoPath = _cc.getRepoPath(); this.commit = _cc.getCommit(); }
/** * Given a list of changes, returns true if the the construct existed before the first commit * @param changes * @return */ private boolean isConstructExistedBeforeFirstCommit(SortedSet<ConstructChange> changes) { if(changes.size()==0) throw new IllegalStateException("No commits exist"); return !changes.first().getConstructChangeType().equals("ADD"); }
private SignatureChange getDiffChange(ConstructChange _prec, ConstructChange _follow) { SignatureChange chg = null; if(this.getOverallChangeType().equals(ConstructChangeType.MOD)) { if(_follow.getBuggyBody()!=null && _prec.getFixedBody()!=null) { Signature sp = this.gson.fromJson(_prec.getFixedBody(), ASTConstructBodySignature.class); Signature sf = this.gson.fromJson(_follow.getBuggyBody(), ASTConstructBodySignature.class); final SignatureComparator comparator = new ASTSignatureComparator(); chg = comparator.computeChange(sp, sf); } } return chg; }
/** * Returns true if 2 commits have no intermediate commit between them, false otherwise */ private boolean isFollowingCommit(ConstructChange _cc1, ConstructChange _cc2){ if ( _cc1.equals(_cc2) ){ return true; } if ( _cc1.getFixedBody() != null && _cc2.getBuggyBody() != null ){ SignatureChange chg = null; Signature s1 = this.gson.fromJson(_cc1.getFixedBody(), ASTConstructBodySignature.class); Signature s2 = this.gson.fromJson(_cc2.getBuggyBody(), ASTConstructBodySignature.class); final SignatureComparator comparator = new ASTSignatureComparator(); chg = comparator.computeChange(s1, s2); return chg.getModifications().isEmpty(); } return false; }
for ( ConstructChange cc : o.getChanges() ){ JsonObject json = new JsonObject(); json.addProperty("repo", cc.getRepo()); json.addProperty("commit", cc.getCommit()); json.addProperty("repoPath", cc.getRepoPath()); json.add("constructId", gson.toJsonTree(cc.getConstructId())); jscommits.add(json);
final ConstructId cid = _construct_change.getConstructId(); if(this.isTestConstruct(cid) || this.isBelowTestDir(_construct_change.getRepoPath()) || this.isInTestClass(cid)){
json_cid = cc.getConstructId(); if(json_cid.getLang().equals(ProgrammingLanguage.JAVA) && !cc.getConstructChangeType().equals(ConstructChangeType.ADD)) { changes_set.add(json_cid);
public final String toString(boolean _deep) { final StringBuilder builder = new StringBuilder(); if(_deep) { builder.append("Bug ").append(this.toString(false)).append(System.getProperty("line.separator")); for(ConstructChange cc: this.getConstructChanges()) { builder.append(" construct change ").append(cc); builder.append(", construct ID ").append(cc.getConstructId()).append(System.getProperty("line.separator")); } } else { builder.append("[").append(this.getId()).append(":").append(this.getBugId()).append("]"); } return builder.toString(); }
public void addConstructChange(ConstructChange _construct_change) throws IllegalArgumentException { String path = _construct_change.getRepoPath(); if(path==null) { ArchiveFixContainmentCheck.log.warn("Construct change with commit [" + _construct_change.getCommit()+ "] has not path information"); path = ""; } //throw new IllegalArgumentException("Cannot analyze construct fix containment without path information"); OrderedCommitsForPath commits_per_path = this.commits.get(path); if(commits_per_path==null) { commits_per_path = new OrderedCommitsForPath(this.constructId, this.ja, path); this.commits.put(path, commits_per_path); } commits_per_path.addConstructChange(_construct_change); }/* old public void addConstructChange(ConstructChange _construct_change) throws IllegalArgumentException {
public String getCommitsAsString() { final StringBuffer b = new StringBuffer(); int i = 0; for(ConstructChange chg: this.changes) { if(i++>0) b.append(","); b.append(chg.getCommit()); } return b.toString(); }
/** * Returns a new set with all changes that match to the given path. */ @JsonIgnore public static Set<ConstructChange> filter(Set<ConstructChange> _changes, String _path) { final Set<ConstructChange> changes = new HashSet<ConstructChange>(); for(ConstructChange change: _changes) { if(_path.equals("") || change.getRepoPath()==null || change.getRepoPath().startsWith(_path)) { changes.add(change); } } return changes; } }
private String getAfter() { String s = null; if(this.changes.last().getFixedBody()!=null){ s = this.changes.last().getFixedBody(); } return s; }
private String getBefore() { String s = null; if(this.changes.first().getBuggyBody()!=null){ s = this.changes.first().getBuggyBody(); } return s; }
if(cpa.getConstruct().equals(c.getConstructId().getQname()) && c.getRepoPath().contains(cpa.getPath()) && c.getConstructChangeType().toString().equals(cpa.getType())){ JsonObject thisCc = new JsonObject(); cc.addProperty("repo", c.getRepo()); cc.addProperty("commit", c.getCommit()); cc.addProperty("repoPath", c.getRepoPath()); JsonObject constructId = new JsonObject(); constructId.addProperty("lang", c.getConstructId().getLang().toString()); constructId.addProperty("type", c.getConstructId().getType().toString()); constructId.addProperty("qname", c.getConstructId().getQname()); cc.add("constructId", constructId); thisCc.addProperty("qnameInJar", cpa.getQnameInJar()); if(c.getConstructChangeType().equals(ConstructChangeType.MOD)){ thisCc.addProperty("dtv", cpa.getdToV()); thisCc.addProperty("dtf", cpa.getdToF());
if(cc.getConstructId().getLang()==ProgrammingLanguage.JAVA) hasJava = true; if ( !isBelowTestDir(cc.getConstructId().getQname()) && !isInTestClass(cc.getConstructId()) && (cc.getConstructId().getType().equals(ConstructType.METH) || cc.getConstructId().getType().equals(ConstructType.CONS) || cc.getConstructId().getType().equals(ConstructType.FUNC) || cc.getConstructId().getType().equals(ConstructType.MODU) ) ){ OrderedCCperConstructPath2 a = new OrderedCCperConstructPath2(cc.getConstructId(),cc.getRepoPath()); if(orderedQnamePerCC.contains(a)){ orderedQnamePerCC.get(orderedQnamePerCC.indexOf(a)).addConstructChange(cc);
if((c.getConstructId().getType().equals(ConstructType.CONS)||c.getConstructId().getType().equals(ConstructType.METH))&&c.getConstructChangeType().equals(ConstructChangeType.MOD)){ mod_exists=true; BugLibManager.log.info("At least one MOD constructor/method for bug ["+b.getBugId()+"] exists, continue patchEval");
private void setChangeList(){ Collection<ConstructChange> constructChanges = bugChangeList.getConstructChanges(); this.methsConsCC = new ArrayList<>(); for (ConstructChange cc : constructChanges) { if (cc.getConstructId().getType().equals(ConstructType.METH) || cc.getConstructId().getType().equals(ConstructType.CONS)) this.methsConsCC.add(cc); } }
/** * Returns true if 2 commits have no intermediate commit between them, false otherwise * @param _ccBefore * @param _ccAfter */ private boolean isFollowingCommit(ConstructChange _ccBefore, ConstructChange _ccAfter) { if(_ccBefore.equals(_ccAfter)) throw new IllegalArgumentException("Provided construct changes are equal"); if(_ccBefore.getFixedBody()==null && _ccAfter.getBuggyBody()==null) throw new IllegalArgumentException("First change has no fixed body and/or later change has no buggy body"); final Signature s1 = gson.fromJson(_ccBefore.getFixedBody(), Signature.class); final Signature s2 = gson.fromJson(_ccAfter.getBuggyBody(), Signature.class); final SignatureComparator comparator = new ASTSignatureComparator(); final SignatureChange chg = comparator.computeChange(s1, s2); // Return whether the edit script is empty return chg.getModifications().isEmpty(); }
/** * Checks if two commits have no intermediate commits between them and logs it to console */ private void checkFollowingCommits(){ for(int i=1; i<this.changes.size(); i++){ boolean isFollowing = isFollowingCommit(Iterables.get(changes, i-1), Iterables.get(changes, i)); log.info("Commits " + Iterables.get(changes, i-1).getCommit() + " and " + Iterables.get(changes, i).getCommit() + " are " + (isFollowing ? "" : "not") + " sequential"); } }