Skip to content

Commit d6d1a22

Browse files
committed
Fix lambda mappers in commit
apache/lucene-solr@34993c2 lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java
1 parent 14883e8 commit d6d1a22

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

src/main/java/gr/uom/java/xmi/decomposition/ReplacementAlgorithm.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import gr.uom.java.xmi.UMLAnonymousClass;
2727
import gr.uom.java.xmi.UMLAttribute;
2828
import gr.uom.java.xmi.UMLClass;
29+
import gr.uom.java.xmi.UMLComment;
2930
import gr.uom.java.xmi.UMLOperation;
3031
import gr.uom.java.xmi.UMLParameter;
3132
import gr.uom.java.xmi.UMLType;
@@ -5876,7 +5877,44 @@ protected static void processLambdas(LambdaExpressionObject lambda1, LambdaExpre
58765877
else if(invocations1.size() == 0 && invocations2.size() > 0) {
58775878
nonMappedElementsT1 = nonMappedElementsT1 - ignoredNonMappedElements(invocations2, mapper.getNonMappedLeavesT1(), mapper.getNonMappedInnerNodesT1());
58785879
}
5879-
if((mappings >= nonMappedElementsT1 && mappings >= nonMappedElementsT2) ||
5880+
AbstractCodeFragment parentStatement1 = null;
5881+
if(operationBodyMapper.getContainer1().getBody() != null) {
5882+
for(AbstractCodeFragment leaf1 : operationBodyMapper.getContainer1().getBody().getCompositeStatement().getLeaves()) {
5883+
if(leaf1.getLocationInfo().subsumes(lambda1.getLocationInfo())) {
5884+
parentStatement1 = leaf1;
5885+
break;
5886+
}
5887+
}
5888+
}
5889+
AbstractCodeFragment parentStatement2 = null;
5890+
if(operationBodyMapper.getContainer2().getBody() != null) {
5891+
for(AbstractCodeFragment leaf2 : operationBodyMapper.getContainer2().getBody().getCompositeStatement().getLeaves()) {
5892+
if(leaf2.getLocationInfo().subsumes(lambda2.getLocationInfo())) {
5893+
parentStatement2 = leaf2;
5894+
break;
5895+
}
5896+
}
5897+
}
5898+
UMLComment previousComment1 = null;
5899+
if(parentStatement1 != null) {
5900+
for(UMLComment comment : operationBodyMapper.getContainer1().getComments()) {
5901+
if(parentStatement1.getLocationInfo().nextLine(comment.getLocationInfo())) {
5902+
previousComment1 = comment;
5903+
break;
5904+
}
5905+
}
5906+
}
5907+
UMLComment previousComment2 = null;
5908+
if(parentStatement2 != null) {
5909+
for(UMLComment comment : operationBodyMapper.getContainer2().getComments()) {
5910+
if(parentStatement2.getLocationInfo().nextLine(comment.getLocationInfo())) {
5911+
previousComment2 = comment;
5912+
break;
5913+
}
5914+
}
5915+
}
5916+
boolean identicalPreviousComment = previousComment1 != null && previousComment2 != null && previousComment1.getText().equals(previousComment2.getText());
5917+
if((mappings >= nonMappedElementsT1 && mappings >= nonMappedElementsT2) || identicalPreviousComment ||
58805918
(nonMappedElementsT1 == 0 && !methodReference1) || (nonMappedElementsT2 == 0 && !methodReference2) ||
58815919
(classDiff != null && (classDiff.isPartOfMethodExtracted(lambda1, lambda2) || classDiff.isPartOfMethodInlined(lambda1, lambda2) || isPartOfLambdaMovedToParentMapper(mapper)))) {
58825920
operationBodyMapper.addAllMappings(mapper.getMappings());

src/main/java/gr/uom/java/xmi/decomposition/VariableReplacementAnalysis.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,18 @@ private boolean replacementNotInsideMethodSignatureOfAnonymousClass(AbstractCode
23522352
}
23532353
return replacementBeforeNotFoundInMethodSignature && replacementAfterNotFoundInMethodSignature;
23542354
}
2355+
for(UMLOperationBodyMapper lambdaMapper : mapping.getLambdaMappers()) {
2356+
if(lambdaMapper.getOperationSignatureDiff().isPresent()) {
2357+
UMLOperationDiff signatureDiff = lambdaMapper.getOperationSignatureDiff().get();
2358+
List<String> parameterNameList1 = signatureDiff.getRemovedOperation().getParameterNameList();
2359+
int index1 = parameterNameList1.indexOf(replacement.getBefore());
2360+
List<String> parameterNameList2 = signatureDiff.getAddedOperation().getParameterNameList();
2361+
int index2 = parameterNameList2.indexOf(replacement.getAfter());
2362+
if(index1 != -1 && index2 != -1 && index1 != index2 && parameterNameList1.size() == parameterNameList2.size()) {
2363+
return false;
2364+
}
2365+
}
2366+
}
23552367
return true;
23562368
}
23572369

src/test/java/org/refactoringminer/test/TestNewDatasetRefactorings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ public void testAllRefactorings() throws Exception {
5151
.or(Refactorings.MoveCode.getValue());
5252
TestBuilder test = new TestBuilder(detector, REPOS, types);
5353
RefactoringPopulator.feedTSERefactoringInstances(test);
54-
test.assertExpectationsWithGitHubAPI(3427, 53, 114);
54+
test.assertExpectationsWithGitHubAPI(3427, 50, 114);
5555
}
5656
}

src/test/resources/oracle/tse-dataset/lucene-solr.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@
275275
"type": "MOVE_OPERATION",
276276
"description": "Move Method\tpackage escapeDash(re String) : String from class org.apache.lucene.analysis.hunspell.Dictionary to private escapeDash(re String) : String from class org.apache.lucene.analysis.hunspell.AffixCondition",
277277
"validation": true
278+
},
279+
{
280+
"type": "MOVE_CODE",
281+
"description": "Move Code\tfrom private parseAffix(affixes TreeMap<String,List<Integer>>, secondStageFlags Set<Character>, header String, reader LineNumberReader, isSuffix boolean, seenPatterns Map<String,Integer>, seenStrips Map<String,Integer>, flags FlagEnumerator) : void in class org.apache.lucene.analysis.hunspell.Dictionary to public compile(kind AffixKind, strip String, condition String, line String) : AffixCondition in class org.apache.lucene.analysis.hunspell.AffixCondition",
282+
"validation": true
283+
},
284+
{
285+
"type": "MOVE_CODE",
286+
"description": "Move Code\tfrom private parseAffix(affixes TreeMap<String,List<Integer>>, secondStageFlags Set<Character>, header String, reader LineNumberReader, isSuffix boolean, seenPatterns Map<String,Integer>, seenStrips Map<String,Integer>, flags FlagEnumerator) : void in class org.apache.lucene.analysis.hunspell.Dictionary to private skipCharPattern(condition String, pos int) : int in class org.apache.lucene.analysis.hunspell.AffixCondition",
287+
"validation": true
278288
}
279289
]
280290
},
@@ -501,12 +511,12 @@
501511
{
502512
"type": "RENAME_VARIABLE",
503513
"description": "Rename Variable\tkey : null to prefixLength : null in method private expandRoot(root Root<String>, misspelled String) : List<String> from class org.apache.lucene.analysis.hunspell.GeneratingSuggester",
504-
"validation": true
514+
"validation": false
505515
},
506516
{
507517
"type": "RENAME_VARIABLE",
508518
"description": "Rename Variable\tids : null to prefixId : null in method private expandRoot(root Root<String>, misspelled String) : List<String> from class org.apache.lucene.analysis.hunspell.GeneratingSuggester",
509-
"validation": true
519+
"validation": false
510520
}
511521
]
512522
},

0 commit comments

Comments
 (0)