Skip to content

Commit

Permalink
Enable detection of Extract Variable with Pattern Instance expression
Browse files Browse the repository at this point in the history
spring-projects/spring-framework@5dc6a16
Extract Variable	ann : Annotation in method protected createSynthesizedAnnotation() : A from class org.springframework.core.annotation.TypeMappedAnnotation
  • Loading branch information
tsantalis committed Dec 27, 2024
1 parent 623030f commit a144814
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<LeafExpression> 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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6971,6 +6971,17 @@ private void extractInlineVariableAnalysis(List<? extends AbstractCodeFragment>
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;
Expand Down

0 comments on commit a144814

Please sign in to comment.