From 3b1ed30cbb1adfbdd64e556c88f61364fcca35f6 Mon Sep 17 00:00:00 2001 From: Pouryafard75 Date: Thu, 12 Sep 2024 15:15:38 -0400 Subject: [PATCH] ASTDiff: Improve JavaDocMatcher (Remove reported added and deleted doc elements --- .../matchers/wrappers/JavaDocMatcher.java | 21 +++++++++++- ....java.org.assertj.core.api.Assertions.json | 33 ------------------- 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/refactoringminer/astDiff/matchers/wrappers/JavaDocMatcher.java b/src/main/java/org/refactoringminer/astDiff/matchers/wrappers/JavaDocMatcher.java index ae6db519fd..fe6aaefbf2 100644 --- a/src/main/java/org/refactoringminer/astDiff/matchers/wrappers/JavaDocMatcher.java +++ b/src/main/java/org/refactoringminer/astDiff/matchers/wrappers/JavaDocMatcher.java @@ -1,6 +1,8 @@ package org.refactoringminer.astDiff.matchers.wrappers; import com.github.gumtreediff.matchers.CompositeMatchers; +import com.github.gumtreediff.matchers.Mapping; +import com.github.gumtreediff.matchers.MappingStore; import com.github.gumtreediff.tree.Tree; import gr.uom.java.xmi.UMLDocElement; @@ -45,7 +47,8 @@ private void processJavaDocs(Tree srcTree, Tree dstTree, UMLJavadoc srcUMLJavaDo mappingStore.addMappingRecursively(srcJavaDocNode,dstJavaDocNode); } else if(diff.getCommonTags().size() > 0 || diff.getCommonDocElements().size() > 0 || srcUMLJavaDoc.isEmpty() || dstUMLJavaDoc.isEmpty()) { - mappingStore.add(new CompositeMatchers.SimpleGumtree().match(srcJavaDocNode, dstJavaDocNode)); + MappingStore gtSimpleMappings = new CompositeMatchers.SimpleGumtree().match(srcJavaDocNode, dstJavaDocNode); + mappingStore.add(gtSimpleMappings); for (Pair pair : diff.getCommonTags()) { Tree srcTag = TreeUtilFunctions.findByLocationInfo(srcTree,pair.getLeft().getLocationInfo()); Tree dstTag = TreeUtilFunctions.findByLocationInfo(dstTree,pair.getRight().getLocationInfo()); @@ -103,6 +106,22 @@ else if (areBothFromThisType(src, dst, Constants.SIMPLE_NAME)) } } } + for (UMLDocElement deletedDocElement : diff.getDeletedDocElements()) { + Tree srcDocElement = TreeUtilFunctions.findByLocationInfo(srcTree, deletedDocElement.getLocationInfo()); + for (Mapping gtSimpleMapping : gtSimpleMappings) { + if (gtSimpleMapping.first.equals(srcDocElement)) { + mappingStore.removeMapping(gtSimpleMapping.first, gtSimpleMapping.second); + } + } + } + for (UMLDocElement addedDocElements : diff.getAddedDocElements()) { + Tree dstDocElement = TreeUtilFunctions.findByLocationInfo(dstTree, addedDocElements.getLocationInfo()); + for (Mapping gtSimpleMapping : gtSimpleMappings) { + if (gtSimpleMapping.second.equals(dstDocElement)) { + mappingStore.removeMapping(gtSimpleMapping.first, gtSimpleMapping.second); + } + } + } } } } diff --git a/src/test/resources/astDiff/commits/assertj_assertj/b36ab386559d04db114db8edd87c8d4cbf850c12/src.main.java.org.assertj.core.api.Assertions.json b/src/test/resources/astDiff/commits/assertj_assertj/b36ab386559d04db114db8edd87c8d4cbf850c12/src.main.java.org.assertj.core.api.Assertions.json index 465ce0a0c3..4150781d65 100644 --- a/src/test/resources/astDiff/commits/assertj_assertj/b36ab386559d04db114db8edd87c8d4cbf850c12/src.main.java.org.assertj.core.api.Assertions.json +++ b/src/test/resources/astDiff/commits/assertj_assertj/b36ab386559d04db114db8edd87c8d4cbf850c12/src.main.java.org.assertj.core.api.Assertions.json @@ -295,17 +295,6 @@ "secondPos" : 968, "firstEndPos" : 2510, "secondEndPos" : 980 -}, { - "firstType" : "TextElement", - "secondType" : "TextElement", - "firstLabel" : "

", - "secondLabel" : "The difference with ", - "firstParentType" : "TagElement", - "secondParentType" : "TagElement", - "firstPos" : 2514, - "secondPos" : 1353, - "firstEndPos" : 2518, - "secondEndPos" : 1373 }, { "firstType" : "TextElement", "secondType" : "TextElement", @@ -691,28 +680,6 @@ "secondPos" : 1336, "firstEndPos" : 2887, "secondEndPos" : 1349 -}, { - "firstType" : "TextElement", - "secondType" : "TextElement", - "firstLabel" : "

", - "secondLabel" : " is that this class contains assertThat methods with interface parameter", - "firstParentType" : "TagElement", - "secondParentType" : "TagElement", - "firstPos" : 2891, - "secondPos" : 1397, - "firstEndPos" : 2895, - "secondEndPos" : 1469 -}, { - "firstType" : "TextElement", - "secondType" : "TextElement", - "firstLabel" : "

", - "secondLabel" : "to avoid Java 8 ambiguous method error (see", - "firstParentType" : "TagElement", - "secondParentType" : "TagElement", - "firstPos" : 2899, - "secondPos" : 1473, - "firstEndPos" : 2903, - "secondEndPos" : 1516 }, { "firstType" : "TagElement", "secondType" : "TagElement",