Skip to content

Commit

Permalink
Fix for pouryafard75#75
Browse files Browse the repository at this point in the history
Enable the matching of leaf subtrees with the different EXPRESSION_OPERATOR
  • Loading branch information
pouryafard75 authored and tsantalis committed May 1, 2023
1 parent db509c5 commit 1497444
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/org/refactoringminer/astDiff/matchers/CustomGTSimple.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ private static boolean isAcceptableMatch(Mapping mapping) {
mapping.first.getParent().getType().name.equals(Constants.METHOD_INVOCATION));
}

private static boolean isOnlyOneMethodInvocation(Tree input1, Tree input2)
{
private static boolean isOnlyOneMethodInvocation(Tree input1, Tree input2) {
if (input1 == null || input2 == null) return false;
if (input1.getParent() == null || input2.getParent() == null) return false;
if (input1.getParent().getType().name.equals(Constants.METHOD_INVOCATION) && !input2.getParent().getType().name.equals(Constants.METHOD_INVOCATION))
Expand All @@ -63,6 +62,7 @@ else if (!input1.getParent().getType().name.equals(Constants.METHOD_INVOCATION)
return false;

}

private static boolean isPartOfConditional(Tree input) {
if (input.getType().name.equals(Constants.CONDITIONAL_EXPRESSION))
return true;
Expand All @@ -73,8 +73,8 @@ private static boolean isPartOfConditional(Tree input) {
return isPartOfConditional(parent);
}
}
private static boolean isSamePositionInConditional(Tree input1, Tree input2)
{

private static boolean isSamePositionInConditional(Tree input1, Tree input2) {
int input1Index = 0;
int input2Index = 0;
while (!input1.getParent().getType().name.equals(Constants.CONDITIONAL_EXPRESSION))
Expand Down Expand Up @@ -106,11 +106,23 @@ public MappingStore match(Tree src, Tree dst, MappingStore mappings) {

for (var currentSrc : currentPrioritySrcTrees)
for (var currentDst : currentPriorityDstTrees)
if (currentSrc.getMetrics().hash == currentDst.getMetrics().hash)
if (currentSrc.getMetrics().hash == currentDst.getMetrics().hash) {
if (currentSrc.isIsomorphicTo(currentDst)) {
if (!isOnlyOneMethodInvocation(currentSrc,currentDst))
if (!isOnlyOneMethodInvocation(currentSrc, currentDst))
multiMappings.addMapping(currentSrc, currentDst);
}
}
else {
if (currentSrc.getLabel().equals(currentDst.getLabel()))
{
if (currentSrc.getType().name.contains("_EXPRESSION_OPERATOR")
&&
currentDst.getType().name.contains("_EXPRESSION_OPERATOR"))
multiMappings.addMapping(currentSrc, currentDst);
}
}



for (var t : currentPrioritySrcTrees)
if (!multiMappings.hasSrc(t))
Expand All @@ -123,6 +135,7 @@ public MappingStore match(Tree src, Tree dst, MappingStore mappings) {
filterMappings(multiMappings);
return this.mappings;
}

@Override
public void filterMappings(MultiMappingStore multiMappings) {
// Select unique mappings first and extract ambiguous mappings.
Expand Down Expand Up @@ -152,7 +165,6 @@ public void filterMappings(MultiMappingStore multiMappings) {
// Rank the mappings by score.
Set<Tree> srcIgnored = new HashSet<>();
Set<Tree> dstIgnored = new HashSet<>();

Collections.sort(ambiguousList, new MappingComparators.FullMappingComparator(mappings));
if (ambiguousList.size() > 1)
ambiguousStringLiteralModification(ambiguousList,srcIgnored,dstIgnored);
Expand Down Expand Up @@ -180,8 +192,7 @@ private void ambiguousStringLiteralModification(List<Mapping> ambiguousList, Set
}
}
}
}
else {
} else {
break;
}
}
Expand Down

0 comments on commit 1497444

Please sign in to comment.