diff --git a/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java b/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java index 0a908f93f3..cd35e9ad2e 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java @@ -706,6 +706,40 @@ else if(stringConcatMatch(initializer, before)) { return; } } + if(after.startsWith(JAVA.RETURN_SPACE) && after.endsWith(JAVA.STATEMENT_TERMINATION)) { + after = after.substring(JAVA.RETURN_SPACE.length(), after.length()-JAVA.STATEMENT_TERMINATION.length()); + } + if(variableName.equals(after) && statement.getPatternInstanceofExpressions().size() > 0) { + for(LeafExpression expression2 : statement.getPatternInstanceofExpressions()) { + if(expression2.getString().endsWith(" " + variableName) && expression2.getString().contains(before)) { + ExtractVariableRefactoring ref = new ExtractVariableRefactoring(declaration, operation1, operation2, insideExtractedOrInlinedMethod); + List expressions1 = fragment1.findExpression(before); + if(expressions1.size() > 0) { + LeafMapping leafMapping = new LeafMapping(expressions1.get(0), expression2, operation1, operation2); + ref.addSubExpressionMapping(leafMapping); + } + processExtractVariableRefactoring(ref, refactorings); + //if(identical()) { + identicalWithInlinedVariable = true; + //} + return; + } + } + } + if(after.contains(before) && initializer != null && fragment1.getPatternInstanceofExpressions().size() > 0) { + for(LeafExpression expression1 : fragment1.getPatternInstanceofExpressions()) { + if(expression1.getString().endsWith(" " + variableName)) { + ExtractVariableRefactoring ref = new ExtractVariableRefactoring(declaration, operation1, operation2, insideExtractedOrInlinedMethod); + LeafMapping leafMapping = new LeafMapping(expression1, initializer, operation1, operation2); + ref.addSubExpressionMapping(leafMapping); + processExtractVariableRefactoring(ref, refactorings); + //if(identical()) { + identicalWithInlinedVariable = true; + //} + return; + } + } + } } if(!fragment1.getString().equals(fragment2.getString()) && initializer != null && fragment1.getVariableDeclaration(variableName) == null && !isDefaultValue(initializer.toString()) && !isVariableReference(initializer.toString(), fragment2.getVariables())) { diff --git a/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java b/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java index af1b5b41f8..bf0254c49f 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java @@ -6971,6 +6971,17 @@ private void extractInlineVariableAnalysis(List break; } } + CompositeStatementObject parent2 = mapping.getFragment2().getParent(); + while(parent2 != null && parent2.getLocationInfo().getCodeElementType().equals(CodeElementType.BLOCK)) { + parent2 = parent2.getParent(); + } + if(parent2 != null && parent2.getExpressions().size() > 0) { + for(AbstractExpression expression : parent2.getExpressions()) { + if(expression.getPatternInstanceofExpressions().size() > 0) { + mapping.temporaryVariableAssignment(expression, leaves2, classDiff, parentMapper != null, mappings); + } + } + } for(AbstractCodeFragment leaf : leaves1) { if(leaf.equals(leaf1)) { break;