Eliminating extract variable mappings, if they involve expressions of
split conditionals
@@ -407,8 +407,13 @@ public class UMLOperationBodyMapper implements Comparable<UMLOperationBodyMapper
processLeaves(expressionsT1, leaves2, parameterToArgumentMap2, false);
List<AbstractCodeMapping> mappings = new ArrayList<>(this.mappings);
for(int i = numberOfMappings; i < mappings.size(); i++) {
+ if(!isSplitConditionalExpression(mappings.get(i))) {
mappings.get(i).temporaryVariableAssignment(refactorings, parentMapper != null);
}
+ else {
+ this.mappings.remove(mappings.get(i));
+ }
+ }
if(container1.getBodyHashCode() != container2.getBodyHashCode() && containsCallToExtractedMethod) {
for(Iterator<AbstractCodeMapping> mappingIterator = mappings.iterator(); mappingIterator.hasNext();) {
@@ -644,6 +649,21 @@ public class UMLOperationBodyMapper implements Comparable<UMLOperationBodyMapper
return false;
}
+ private boolean isSplitConditionalExpression(AbstractCodeMapping mapping) {
+ for(Refactoring r : this.refactorings) {
+ if(r instanceof SplitConditionalRefactoring) {
+ SplitConditionalRefactoring split = (SplitConditionalRefactoring)r;
+ if(split.getOriginalConditional() instanceof CompositeStatementObject) {
+ CompositeStatementObject comp = (CompositeStatementObject)split.getOriginalConditional();
+ if(comp.getExpressions().contains(mapping.getFragment1())) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
private boolean nestedUnderSplitConditional(AbstractCodeMapping mapping) {
for(Refactoring r : this.refactorings) {
if(r instanceof SplitConditionalRefactoring) {
