Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
Solving EmptySet() issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lmove committed Jun 12, 2019
1 parent 7ac5012 commit fd3400c
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 58 deletions.
12 changes: 7 additions & 5 deletions maracas/src/org/maracas/Extractor.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,20 @@ void methodBreakingChangesExporter(loc delta, loc report=|file:///Users/juri/Des
}
}

void myRunAll(loc libs=|file:///Users/juri/development/git/api-migration-dataset/sonarqube/libraries/|, loc clients=|file:///Users/juri/development/git/api-migration-dataset/sonarqube/clients/|,loc output=|file:///users/juri/Desktop/results.txt|){
void myRunAll(loc libs=|file:///Users/ochoa/Documents/cwi/crossminer/data/api-migration-dataset/sonarqube/erase/|, loc clients=|file:///Users/ochoa/Documents/cwi/crossminer/data/api-migration-dataset/sonarqube/clients/|,loc output=|file:///Users/ochoa/Desktop/results.txt|){

set[loc] libraries = walkJARs(libs);
for (lib1 <- libraries){
for (lib2 <- libraries)
if(lib1 != lib2){
try{
if (lib1 != lib2){
try {
str v1 = lib1.path[findLast(lib1.path,"/")+1..-4];
v1 = replaceLast(v1, "sonar-plugin-api-","sonar-plugin-api__");
loc clients_loc = clients + v1;
if(exists(clients_loc)){
println("Computing Delta model <lib1.path> <lib2.path>");


Delta d;
if(!exists(libs + "Delta" + lib1.file + "-" + lib2.file + ".delta"))
d = delta(lib1, lib2);
else
Expand All @@ -85,7 +86,7 @@ void myRunAll(loc libs=|file:///Users/juri/development/git/api-migration-dataset
int count = size(clients);

for (client <- clients) {
try{
try {
i = i + 1;
println("[<i>/<count>] Computing detection model for <client>... ");

Expand Down Expand Up @@ -132,6 +133,7 @@ void methodBreakingChangesExporter(loc libV1, loc libV2, loc report=|file:///Use
writeHtml(report + ("Delta" + libV1.file + "-" + libV2.file + ".html"), d);
}
}

Delta parseDeltaFile(loc report) {
loc entry = report;
Delta deltas = readBinaryValueFile(#Delta, entry);
Expand Down
142 changes: 93 additions & 49 deletions maracas/src/org/maracas/delta/DeltaBuilder.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,56 @@ import org::maracas::match::matcher::LevenshteinMatcher;
import Relation;
import Set;
import String;
import Type;


Delta createDelta(M3 from, M3 to, loc optionsFile = |project://maracas/config/config.properties|) {
M3Diff diff = createM3Diff(from, to);
Delta delta = delta(<from.id, to.id>);
Delta d = delta(<from.id, to.id>);

delta.options = readProperties(optionsFile);
delta.accessModifiers = accessModifiers(diff);
delta.finalModifiers = finalModifiers(diff);
delta.staticModifiers = staticModifiers(diff);
delta.abstractModifiers = abstractModifiers(diff);
delta.paramLists = paramLists(diff);
delta.types = returnTypes(diff) + types(diff);
delta.extends = extends(diff);
delta.implements = implements(diff);
delta.deprecated = deprecated(diff, delta);
delta.renamed = renamed(diff, delta);
delta.moved = moved(diff, delta);
delta.removed = removed(diff, delta);
delta.added = added(diff, delta);

return delta;
println("--------------------------");
println("Computing options");
d.options = readProperties(optionsFile);
println("--------------------------");
println("Computing accessModifiers");
d.accessModifiers = accessModifiers(diff);
println("--------------------------");
println("Computing finalModifiers");
d.finalModifiers = finalModifiers(diff);
println("--------------------------");
println("Computing staticModifiers");
d.staticModifiers = staticModifiers(diff);
println("--------------------------");
println("Computing abstractModifiers");
d.abstractModifiers = abstractModifiers(diff);
println("--------------------------");
println("Computing paramLists");
d.paramLists = paramLists(diff);
println("--------------------------");
println("Computing types");
d.types = returnTypes(diff) + types(diff);
println("--------------------------");
println("Computing extends");
d.extends = extends(diff);
println("--------------------------");
println("Computing implements");
d.implements = implements(diff);
println("--------------------------");
println("Computing deprecated");
d.deprecated = deprecated(diff, d);
println("--------------------------");
println("Computing renamed");
d.renamed = renamed(diff, d);
println("--------------------------");
println("Computing moved");
d.moved = moved(diff, d);
println("--------------------------");
println("Computing removed");
d.removed = removed(diff, d);
println("--------------------------");
println("Computing added");
d.added = added(diff, d);

return d;
}


Expand Down Expand Up @@ -109,42 +136,67 @@ private rel[loc, Mapping[loc]] deprecated(M3Diff diff, Delta delta) {
*/
private rel[loc, Mapping[loc]] renamed(M3Diff diff, Delta delta) {
diff = filterDiffRenamed(diff, delta);
removals = diff.removals;
additions = diff.additions;
result = {};

for (<cont, elem> <- removals.containment, elem in diff.removedDecls, isTargetMember(elem)) {
// In type cases we need the owner package instead of its compilation unit.
if (isCompilationUnit(cont)) {
cont = getOneFrom(invert(removals.containment)[cont]);
}
for (elem <- diff.removedDecls, isTargetMember(elem)) {
invCont = invert(diff.from.containment);

elemsSameCont = {};
for (a <- additions.containment[cont], a in diff.addedDecls) {
if (isCompilationUnit(a)) {
a = getOneFrom(additions.containment[a]);
if (invCont[elem] != {}) {
// In type cases we need the owner package instead of its compilation unit.
cont = getNonCUContainer(elem, diff.from);
elemsSameCont = {};

for (a <- diff.to.containment[cont], a in diff.addedDecls) {
a = getNonCUChild(a, diff.to);
if (a.scheme == elem.scheme) {
elemsSameCont += a;
}
}
if (a.scheme == elem.scheme) {
elemsSameCont += a;

if (elemsSameCont != {}) {
diffTemp = diff;
diffTemp.removedDecls = { elem };
diffTemp.addedDecls = elemsSameCont;
result += applyMatchers(diffTemp, delta.options, MATCHERS);
}
}

if (elemsSameCont != {}) {
diffTemp = diff;
//diffTemp.removals = filterM3(removals, {elem});
//diffTemp.additions = filterM3(additions, elemsSameCont);
diffTemp.removedDecls = { elem };
diffTemp.addedDecls = elemsSameCont;
result += applyMatchers(diffTemp, delta.options, MATCHERS);
else {
c = diff.from.containment;
p = c[elem];
println(elem);
}

}


//for (<cont, elem> <- removals.containment, elem in diff.removedDecls, isTargetMember(elem)) {
// // In type cases we need the owner package instead of its compilation unit.
// if (isCompilationUnit(cont)) {
// cont = getOneFrom(invert(removals.containment)[cont]);
// }
//
// elemsSameCont = {};
// for (a <- additions.containment[cont], a in diff.addedDecls) {
// if (isCompilationUnit(a)) {
// a = getOneFrom(additions.containment[a]);
// }
// if (a.scheme == elem.scheme) {
// elemsSameCont += a;
// }
// }
//
// if (elemsSameCont != {}) {
// diffTemp = diff;
// diffTemp.removedDecls = { elem };
// diffTemp.addedDecls = elemsSameCont;
// result += applyMatchers(diffTemp, delta.options, MATCHERS);
// }
//}
return result;
}

private M3Diff filterDiffRenamed(M3Diff diff, Delta delta) {
//elemsRemovals = (!isEmpty(delta.paramLists)) ? delta.paramLists.elem : {};
//excepRemovals = diff.removedDecls;
//diff.removals = filterXM3WithExcpetions(diff.removals, elemsRemovals, excepRemovals);
diff.removedDecls
= diff.removedDecls
- ((!isEmpty(delta.paramLists)) ? delta.paramLists.elem : {});
Expand All @@ -158,14 +210,6 @@ private rel[loc, Mapping[loc]] moved(M3Diff diff, Delta delta) {
}

private M3Diff filterDiffMoved(M3Diff diff, Delta delta) {
//elemsRemovals = ((!isEmpty(delta.renamed)) ? delta.renamed.mapping<0> : {})
// + ((!isEmpty(delta.paramLists)) ? delta.paramLists.elem : {});
//elemsAdditions = (!isEmpty(delta.renamed)) ? delta.renamed.mapping<1> : {};
//excepRemovals = diff.removedDecls;
//excepAdditions = diff.addedDecls;
//
//diff.removals = filterXM3WithExcpetions(diff.removals, elemsRemovals, excepRemovals);
//diff.additions = filterXM3WithExcpetions(diff.additions, elemsAdditions, excepAdditions);
diff.removedDecls
= diff.removedDecls
- ((!isEmpty(delta.paramLists)) ? delta.paramLists.elem : {})
Expand Down
25 changes: 24 additions & 1 deletion maracas/src/org/maracas/m3/Core.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ list[value] getM3SortValue(loc elem, map[loc, set[value]] m)
str getM3SortString(loc elem, map[loc, set[value]] m)
= toString(getM3SortValue(elem, m));

loc getNonCUContainer(loc elem, M3 m) {
invCont = invert(m.containment);
cont = getOneFrom(invCont[elem]);

if (isCompilationUnit(cont)) {
pkg = invCont[cont];
cont = (pkg != {}) ? getOneFrom(pkg) : cont;
}
else {
cont = getOneFrom(invCont[elem]);
}

return cont;
}

loc getNonCUChild(loc elem, M3 m) {
if (isCompilationUnit(elem)) {
child = m.containment[elem];
elem = (child != {}) ? getOneFrom(child) : elem;
}
return elem;
}

// TODO: consider moving this function to Rascal module lang::java::m3::Core
bool isType(loc entity) = isClass(entity) || isInterface(entity);

Expand All @@ -50,7 +73,7 @@ bool isTargetMemberExclInterface(loc elem)
bool isTargetMember(loc elem)
= isTargetMemberExclInterface(elem)
|| isInterface(elem);

@memo
M3 m3(loc project, loc mvnExec=|file:///Users/ochoa/installations/apache-maven-3.5.4/bin/mvn|) {
M3 m = (project.scheme == "jar" || project.extension == "jar") ? createM3FromJar(project) : m3FromFolder(project);
Expand Down
8 changes: 5 additions & 3 deletions maracas/src/org/maracas/m3/M3Diff.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import Relation;


data M3Diff(
M3 removals = {},
M3 additions = {},
M3 removals = m3(|file:///|),
M3 additions = m3(|file:///|),
set[loc] removedDecls = {},
set[loc] addedDecls = {}
)
= m3Diff(M3 from, M3 to);


M3Diff createM3Diff(M3 from, M3 to)
= m3Diff (
from,
Expand All @@ -22,11 +23,12 @@ M3Diff createM3Diff(M3 from, M3 to)
addedDecls = m3AddedDecls(from, to)
);


private M3 m3Removals(M3 from, M3 to)
= diffJavaM3(from.id, [from, to]);

private M3 m3Additions(M3 from, M3 to)
= diffJavaM3(from.id, [to, from]);
= diffJavaM3(to.id, [to, from]);


private set[loc] m3RemovedDecls(M3 from, M3 to)
Expand Down

1 comment on commit fd3400c

@lmove
Copy link
Contributor Author

@lmove lmove commented on fd3400c Jun 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@md2manoppello I did a couple of tests and the issue seems to be gone. Can you please verify? I still need to look further into it, but your help is appreciated.

Please sign in to comment.