/** * Returns true of the given signature contains the given change, false otherwise. */ @Override public boolean containsChange(Signature _s, SignatureChange _change) { // Do a couple of casts before calling the worker method final Node root_of_signature_under_test = ((ASTSignature)_s).getRoot(); final ASTSignatureChange sign_change = (ASTSignatureChange)_change; final Set<SourceCodeChange> list_of_modifications = sign_change.getListOfChanges(); // Return the result of the worker method return containsChange(root_of_signature_under_test, list_of_modifications); }
@Override public float computeSimilarity(Signature _a, Signature _b) { Node _vulnerableConstruct = ((ASTSignature)_a).getRoot(); Node _fixedConstruct = ((ASTSignature)_b).getRoot(); float similarity = computeSimilarity(_vulnerableConstruct, _fixedConstruct); return similarity; }
public boolean isEqual(ASTUtil.NODE_COMPARE_MODE _mode, OrderedCommitsForPath.Version _version) { boolean equal = false; final ASTSignature construct_signature = (ASTSignature)this.getConstructSignature(); // The version to compare to (before or after) ASTSignature version = null; if(_version==Version.BEFORE) version = (ASTSignature)this.getBefore(); else version = (ASTSignature)this.getAfter(); if(construct_signature!=null && version!=null) { equal = ASTUtil.isEqual(construct_signature.getRoot(), version.getRoot(), _mode); } return equal; }
/** * Computes a so-called signature change, i.e., changes required to transform the signature of the first given {@link Construct} into the signature of the second. */ @Override public SignatureChange computeChange(Construct _from, Construct _to) { ASTSignatureChange change = null; if(_from!=null && _to!=null) { final ASTConstructBodySignature from_sign = (ASTConstructBodySignature)this.createSignature(_from); final ASTConstructBodySignature to_sign = (ASTConstructBodySignature)this.createSignature(_to); // Note: The call in class ASTSignatureChange.getModifications() { mDistiller.extractClassifiedSourceCodeChanges(defSignatureNode, fixSignatureNode);} // changes the from version into the to version, i.e., afterwards both will look the same if(from_sign!=null && to_sign!=null) { change = new ASTSignatureChange(from_sign, to_sign); change.getModifications(); } } return change; }
public void prepareCompilationFromSource(String src){ fCompilation = CompilationUtils.compileSource(getSourceCodeWithSnippets(src)); }
/** * Returns the type of change considering all commits. * @param changes * @return */ private ConstructChangeType getOverallChangeType(SortedSet<ConstructChange> changes) { if(this.isConstructExistedBeforeFirstCommit(changes) && this.isConstructExistsAfterLastCommit(changes)) { return ConstructChangeType.MOD; } else if(this.isConstructExistedBeforeFirstCommit(changes) && !this.isConstructExistsAfterLastCommit(changes)) { return ConstructChangeType.DEL; } else if(!this.isConstructExistedBeforeFirstCommit(changes) && this.isConstructExistsAfterLastCommit(changes)) { return ConstructChangeType.ADD; } else { return ConstructChangeType.NUL; } } }
public Version getEqualVersion(ASTUtil.NODE_COMPARE_MODE _mode) { if(this.isEqualToVersionBeforeOrAfter(_mode)) { if(this.isEqual(_mode, Version.BEFORE)) return Version.BEFORE; else if(this.isEqual(_mode, Version.AFTER)) return Version.AFTER; else throw new IllegalStateException("Signature supposed to be equal to BEFORE or AFTER versions of the overall change"); } else { return null; } }
/** * Reads the construct from cache and creates the signature. */ private Signature createFromSourceCache(ConstructId _cid) { Signature signature = null; if(this.sourceCache.containsKey(_cid)) signature = this.createSignature(this.sourceCache.get(_cid)); return signature; }
public ASTSignatureChange(Signature defSignature, Signature fixSignature){ this.mDefSignature = defSignature; this.mFixSignature = fixSignature; //Name of the root of the AST for either the fixed or for the defective AST mMethodName = ((ASTSignature)mFixSignature).getValue(); }
/** * Returns the generated {@link JavaCompilation} from the file identified by the given filename. This method assumes * that the filename is relative to <code>{@value #TEST_DATA_BASE_DIR}</code>. * * @param filename * of the file to compile (relative to {@value #TEST_DATA_BASE_DIR}). * @return the compilation of the file */ public void prepareCompilationFromFile(String _file) { fCompilation = CompilationUtils.compileFile(_file); }
public void addConstructChanges(Set<ConstructChange> _changes) { for(ConstructChange change: _changes) { this.addConstructChange(change); } }
public static synchronized UniqueNameNormalizer getInstance() { if(instance==null) instance = new UniqueNameNormalizer(); return instance; }
public Signature getConstructSignature() { return signatureFactory.createFromCtClass(this.constructId, ArchiveFixContainmentCheck.cp); }
/** * Depending on the number of source code changes, the method sets a suitable threshold for string similarity. * @param sizeOfSourceCodeChange * @return Similarity Threshold * */ private void assignSimlarityScheme(int _change_count){ if(_change_count <= 2) this.setStringSimilarityThreshold(STRING_SIMILARITY_THRESHOLD_LESS_THAN_TWO_CHANGES); else if(_change_count <= 5) this.setStringSimilarityThreshold(STRING_SIMILARITY_THRESHOLD_BETWEEN_TWO_AND_FIVE_CHANGES); else this.setStringSimilarityThreshold(STRING_SIMILARITY_THRESHOLD_MORE_THAN__FIVE_CHANGES); }
@Override public boolean isEmpty() { return this.getListOfChanges().size()==0; } }
public String toRTEDString(){ return treeRTED(fRoot, new StringBuffer()); } }
@Override public SignatureChange computeChange(Signature _a, Signature _b) { SignatureChange astChange = new ASTSignatureChange(_a, _b); astChange.getModifications(); return astChange; }
public ASTConstructBodySignature(Construct _construct){ super(JavaEntityType.METHOD, _construct.getId().getSimpleName()); sMethodBodyConverter = sInjector.getInstance(JavaMethodBodyConverter.class); this._construct = _construct; fCompilation = CompilationUtils.compileSource(getSourceCodeWithSnippets(_construct.getContent())); }
/** * Reads the construct from cache and creates the signature. */ private Signature createFromCompiledCache(ConstructId _cid) { Signature signature = null; if(this.compiledCache.containsKey(_cid)) signature = this.createSignature(this.compiledCache.get(_cid)); return signature; }