de.hdu.pvs.crashfinder.analysis.Intersection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of crashFinder Show documentation
Show all versions of crashFinder Show documentation
A tool for localizing the software regression errors
The newest version!
package de.hdu.pvs.crashfinder.analysis;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.ibm.wala.ipa.slicer.Statement;
import de.hdu.pvs.crashfinder.util.PackageExtractor;
import de.hdu.pvs.crashfinder.util.WALAUtils;
/**
*
* @author Mohammad Ghanavati Created in November 2015
*/
public class Intersection {
public List matchingSet(String diffFile) {
BufferedReader br = null;
String sCurrentLine;
List diffClassSet = new ArrayList();
List matchingSet = new ArrayList();
try {
br = new BufferedReader(new FileReader(diffFile));
while ((sCurrentLine = br.readLine()) != null) {
Pattern p = Pattern.compile("\\+++ (.*)/(.*?).java");
Matcher m = p.matcher(sCurrentLine);
if (m.find()) {
String strFound = m.group();
String absPath = strFound.replace("+", "").trim();
File javaFile = new File(absPath);
if (!javaFile.exists())
continue;
String packageName = new PackageExtractor(javaFile)
.extractPackageName();
String fileName = javaFile.getName();
String fullClassName = packageName + "."
+ fileName.substring(0, fileName.length() - 5);
matchingSet.add(fullClassName);
diffClassSet.add(fullClassName);
}
}
return matchingSet;
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
public Collection intersection(List diff,
Collection extends Statement> slice) {
if (diff.isEmpty()) {
throw new IllegalArgumentException("Cannot intersect with empty "
+ "diff.");
}
if (slice.isEmpty()) {
throw new IllegalArgumentException("Cannot intersect with empty "
+ "slice");
}
Collection sliceDiff = new ArrayList();
for (Statement s1 : slice) {
String fullClassName = null;
String extractedFullClassName = WALAUtils.getJavaFullClassName(s1
.getNode().getMethod().getDeclaringClass());
if (extractedFullClassName.contains("$")) {
String[] dollarReplace = extractedFullClassName.split("\\$");
fullClassName = dollarReplace[0];
} else {
fullClassName = extractedFullClassName;
}
if (diff.contains(fullClassName)) {
sliceDiff.add(s1);
}
}
return sliceDiff;
}
}