Skip to content

Commit

Permalink
Improved statement mappings for issue #715
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed May 23, 2024
1 parent f096939 commit c4dcf76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,12 @@ else if(methodInvocations1.contains(s1) && variables2.contains(s2)) {
findReplacements(set1, set2, replacementInfo, ReplacementType.METHOD_INVOCATION_REPLACED_WITH_STRING_LITERAL, container1, container2, classDiff);
break;
}
else if(value1.endsWith(".") && value2.contains(value1.substring(0, value1.length()-1))) {
Set<String> set1 = Set.of(stringLiteral1);
Set<String> set2 = Set.of(call2.actualString());
findReplacements(set1, set2, replacementInfo, ReplacementType.METHOD_INVOCATION_REPLACED_WITH_STRING_LITERAL, container1, container2, classDiff);
break;
}
}
}
}
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -4584,9 +4584,7 @@ private boolean mappedElementsMoreThanNonMappedT1AndT2(int mappings, UMLOperatio
String attributeInitializer = attributeDeclaration.getInitializer().getString();
String variableInitializer = v1.getInitializer().getString();
if(attributeInitializer.equals(variableInitializer) && attributeDeclaration.equalType(v1) && !initializerContainsTypeLiteral(v1, attributeDeclaration) &&
(attribute.getName().equals(v1.getVariableName()) ||
attribute.getName().toLowerCase().contains(v1.getVariableName().toLowerCase()) ||
v1.getVariableName().toLowerCase().contains(attribute.getName().toLowerCase()))) {
matchingName(v1, attribute)) {
nonMappedStatementsDeclaringSameVariable++;
leafIterator1.remove();
LeafMapping mapping = new LeafMapping(v1.getInitializer(), attributeDeclaration.getInitializer(),
Expand Down Expand Up @@ -4636,9 +4634,7 @@ else if(addedClass != null && s1.getString().contains(JAVA.ASSIGNMENT)) {
String attributeInitializer = attributeDeclaration.getInitializer().getString();
String variableInitializer = v1.getInitializer().getString();
if(attributeInitializer.equals(variableInitializer) && attributeDeclaration.equalType(v1) &&
(attribute.getName().equals(v1.getVariableName()) ||
attribute.getName().toLowerCase().contains(v1.getVariableName().toLowerCase()) ||
v1.getVariableName().toLowerCase().contains(attribute.getName().toLowerCase()))) {
matchingName(v1, attribute)) {
LeafMapping newMapping = new LeafMapping(v1.getInitializer(), attributeDeclaration.getInitializer(),
operationBodyMapper.getContainer1(),
operationBodyMapper.getContainer2());
Expand All @@ -4650,7 +4646,7 @@ else if(addedClass != null && s1.getString().contains(JAVA.ASSIGNMENT)) {
}
}
}
else if(addedClass != null && s1.getString().contains(JAVA.ASSIGNMENT) && !s1.getString().contains("==") && !s1.getString().contains("!=")) {
else if(addedClass != null && s1.getString().contains(JAVA.ASSIGNMENT) && !s1.getString().contains("==") && !s1.getString().contains("!=") && !s1.getString().contains("<=") && !s1.getString().contains(">=")) {
for(UMLAttribute attribute : addedClass.getAttributes()) {
VariableDeclaration attributeDeclaration = attribute.getVariableDeclaration();
if(attributeDeclaration.getInitializer() != null) {
Expand Down Expand Up @@ -4706,6 +4702,19 @@ else if(addedClass != null && s1.getString().contains(JAVA.ASSIGNMENT) && !s1.ge
(mappings > Math.floor(nonMappedElementsT2/2.0) && mappings > Math.floor(nonMappedElementsT1/2.0) && identicalJavadoc);
}

private boolean matchingName(VariableDeclaration v1, UMLAttribute attribute) {
if(attribute.getName().equals(v1.getVariableName())) {
return true;
}
if(attribute.getName().toLowerCase().contains(v1.getVariableName().toLowerCase()) && v1.getVariableName().length() > 1) {
return true;
}
if(v1.getVariableName().toLowerCase().contains(attribute.getName().toLowerCase()) && attribute.getName().length() > 1) {
return true;
}
return false;
}

private static Set<String> convertToStringSet(List<? extends LeafExpression> expressions) {
Set<String> set = new LinkedHashSet<>();
for(LeafExpression expression : expressions) {
Expand Down

0 comments on commit c4dcf76

Please sign in to comment.