/** * Creates and adds a new {@link Construct} to the set of constructs found in the analyzed file. * This method is called during the various visitor methods inherited from {@link JavaBaseListener}. * @param _id * @param _body */ private void saveConstruct(ConstructId _id, String _body) { try { final Construct c = new Construct(_id, _body); this.constructs.put(_id, c); JavaFileAnalyzer2.log.debug("Added " + c.getId()); } catch (IllegalArgumentException e) { JavaFileAnalyzer2.log.error(e); } }
/** * Returns true if construct id and revision are equal. */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final ConstructChange other = (ConstructChange)obj; final ConstructId tc = (this.def!=null ? com.sap.psr.vulas.ConstructId.toSharedType(this.def.getId()) : com.sap.psr.vulas.ConstructId.toSharedType(this.fix.getId())); final ConstructId oc = (other.def!=null ? com.sap.psr.vulas.ConstructId.toSharedType(other.def.getId()) : com.sap.psr.vulas.ConstructId.toSharedType(other.fix.getId())); return (tc.equals(oc) && this.commit.equals(other.commit)); }
public ConstructChange(String _repo, String _repo_path, Construct _def, Construct _fix, String _rev, String _time_stamp) { if(_def==null && _fix==null) throw new IllegalArgumentException("At least one construct must be provided (defective, fixed or both)"); this.repo = _repo; this.repoPath = _repo_path; this.def = _def; this.fix = _fix; this.commit = (_rev!=null&&_rev.contains(":"))?_rev.substring(0,_rev.indexOf(":")-1):_rev; this.committedAt = _time_stamp; // Signatures of the defective and fixed constructs (if any, can be null) and the so-called signature change final SignatureFactory factory = CoreConfiguration.getSignatureFactory( com.sap.psr.vulas.ConstructId.toSharedType( (_def!=null ? _def.getId() : _fix.getId()) )); if(factory!=null) { defSignature = factory.createSignature(def); fixSignature = factory.createSignature(fix); signatureChange = factory.computeChange(def, fix); } }
/** * Creates the construct signature on the basis of the source code provided by {@link Construct#getContent()}. * @param _c the construct for which the siganture shall be created * @param _src * @return */ @Override public Signature createSignature(Construct _c) { if(_c==null) return null; ASTConstructBodySignature ast_signature = null; try { ast_signature = new ASTConstructBodySignature(_c); final String construct_name = ((JavaId)_c.getId()).getSimpleName(); //this.extractConstructName(_c.getId()); if(construct_name!=null && !construct_name.equals("")) //!=" ") ast_signature.convertConstructBody(construct_name); } catch(Exception e){ JavaSignatureFactory.log.error(e.getMessage().toString()); } return ast_signature; }
public String toJSON() { final StringBuilder b = new StringBuilder(); // Key information b.append("{"); b.append(" \"repo\" : \"").append(this.repo).append("\","); if(this.repoPath!=null) b.append(" \"repoPath\" : \"").append(this.repoPath).append("\","); b.append(" \"constructId\" : ").append(this.getConstruct().getId().toJSON()).append(","); if(this.commit!=null) b.append(" \"commit\" : \"").append(this.commit).append("\","); // Other information b.append(" \"constructChangeType\":\"").append(this.getType().toString()).append("\","); if(this.committedAt!=null) b.append(" \"committedAt\" : \"").append(StringUtil.formatDate(Long.parseLong(this.getCommittedAt()))).append("\""); // Buggy method body, fixed one and applied changes if(this.getType() == ConstructChangeType.MOD ){ if(this.fixSignature != null) //b.append(" \"description\" : ").append(JsonBuilder.escape(this.bugDescription)).append(", "); b.append(",\"fixedBody\":").append(JsonBuilder.escape(this.fixSignature.toJson().toString())); //b.append(getFixConstructASTSignature().toJson().toString()).append(" ,"); if(this.defSignature != null) b.append(",\"buggyBody\":").append(JsonBuilder.escape(this.defSignature.toJson().toString())); //b.append(getDefConstructASTSignature().toJson().toString()).append(" ,"); if(signatureChange != null) //b.append(" \"signatureChange\" : ").append(astDiff.toJSON().toString()).append(" ,"); //b.append("\"sigchg \" :[").append(JsonBuilder.escape(astDiff.toJSON().toString())).append("]").append(" ,"); b.append(",\"bodyChange\":").append(JsonBuilder.escape(signatureChange.toJSON().toString())); //b.append(astDiff.toJSON().toString()).append(" ,"); } b.append("}"); return b.toString(); }
public ASTConstructBodySignature(Construct _construct){ super(JavaEntityType.METHOD, _construct.getId().getSimpleName()); sMethodBodyConverter = sInjector.getInstance(JavaMethodBodyConverter.class); this._construct = _construct; fCompilation = CompilationUtils.compileSource(getSourceCodeWithSnippets(_construct.getContent())); }