Skip to content

Commit

Permalink
Restore mappings in commit
Browse files Browse the repository at this point in the history
apache/flink@7407076
flink-java/src/main/java/org/apache/flink/api/java/typeutils/runtime/PojoSerializer.java
  • Loading branch information
tsantalis committed Sep 22, 2024
1 parent a1dab09 commit 12586dc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2555,6 +2555,9 @@ else if(streamAPIStatements1.size() > 0 && streamAPIStatements2.size() == 0) {
mapping.getFragment1().getVariableDeclarations().toString().equals(mapping.getFragment2().getVariableDeclarations().toString())) {
continue;
}
if(expression.getLocationInfo().getCodeElementType().equals(CodeElementType.CATCH_CLAUSE_EXCEPTION_NAME)) {
continue;
}
expression.replaceParametersWithArguments(parameterToArgumentMap1);
expressionsT1.add(expression);
}
Expand Down Expand Up @@ -2961,6 +2964,9 @@ else if(streamAPIStatements1.size() > 0 && streamAPIStatements2.size() == 0) {
mapping.getFragment1().getVariableDeclarations().toString().equals(mapping.getFragment2().getVariableDeclarations().toString())) {
continue;
}
if(expression.getLocationInfo().getCodeElementType().equals(CodeElementType.CATCH_CLAUSE_EXCEPTION_NAME)) {
continue;
}
expression.replaceParametersWithArguments(parameterToArgumentMap2);
expressionsT2.add(expression);
}
Expand Down
60 changes: 45 additions & 15 deletions src/main/java/gr/uom/java/xmi/diff/MappingOptimizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import gr.uom.java.xmi.decomposition.VariableDeclaration;
import gr.uom.java.xmi.decomposition.AbstractCall.StatementCoverageType;
import gr.uom.java.xmi.decomposition.replacement.Replacement;
import gr.uom.java.xmi.decomposition.replacement.Replacement.ReplacementType;

public class MappingOptimizer {
private UMLAbstractClassDiff classDiff;
Expand Down Expand Up @@ -251,6 +252,20 @@ private void optimizeDuplicateMappings(Map<AbstractCodeFragment, List<AbstractCo
!stringRepresentation1.get(i).equals(JAVA.OPEN_BLOCK) && !stringRepresentation1.get(i).equals(JAVA.CLOSE_BLOCK)) {
identicalStatements++;
}
else if(comp1.getLocationInfo().getCodeElementType().equals(CodeElementType.CATCH_CLAUSE) && comp2.getLocationInfo().getCodeElementType().equals(CodeElementType.CATCH_CLAUSE) &&
!stringRepresentation1.get(i).equals(JAVA.OPEN_BLOCK) && !stringRepresentation1.get(i).equals(JAVA.CLOSE_BLOCK) &&
mapping.containsReplacement(ReplacementType.VARIABLE_NAME) && i > 0) {
//tolerate variable renames
int editDistance = StringDistance.editDistance(stringRepresentation1.get(i), stringRepresentation2.get(i));
for(Replacement r : mapping.getReplacements()) {
if(r.getType().equals(ReplacementType.VARIABLE_NAME)) {
if(editDistance == r.getBefore().length() && editDistance == r.getAfter().length()) {
identicalStatements++;
break;
}
}
}
}
}
identicalStatementsForCompositeMappings.add(identicalStatements);
exactMappingsNestedUnderCompositeExcludingBlocks.add(mapper.exactMappingsNestedUnderCompositeExcludingBlocks((CompositeStatementObjectMapping)mapping));
Expand Down Expand Up @@ -684,27 +699,42 @@ private void determineIndicesToBeRemoved(List<Boolean> nestedMapper, List<Boolea
}
}
else {
boolean allReplacementsCoverEntireStatement = false;
if(replacementCoversEntireStatement.contains(false)) {
for(int i=0; i<replacementCoversEntireStatement.size(); i++) {
if(replacementCoversEntireStatement.get(i) == true) {
int zeroCount = 0;
for(int i=0; i<exactMappingsNestedUnderCompositeExcludingBlocks.size(); i++) {
if(exactMappingsNestedUnderCompositeExcludingBlocks.get(i) == 0) {
zeroCount++;
}
}
if(zeroCount == 1) {
for(int i=0; i<exactMappingsNestedUnderCompositeExcludingBlocks.size(); i++) {
if(exactMappingsNestedUnderCompositeExcludingBlocks.get(i) == 0) {
indicesToBeRemoved.add(i);
}
}
}
else {
allReplacementsCoverEntireStatement = true;
}
if(!allReplacementsCoverEntireStatement) {
int minimum = replacementTypeCount.get(0);
for(int i=1; i<replacementTypeCount.size(); i++) {
if(replacementTypeCount.get(i) < minimum) {
minimum = replacementTypeCount.get(i);
if(indicesToBeRemoved.isEmpty()) {
boolean allReplacementsCoverEntireStatement = false;
if(replacementCoversEntireStatement.contains(false)) {
for(int i=0; i<replacementCoversEntireStatement.size(); i++) {
if(replacementCoversEntireStatement.get(i) == true) {
indicesToBeRemoved.add(i);
}
}
}
for(int i=0; i<replacementTypeCount.size(); i++) {
if(replacementTypeCount.get(i) > minimum && !extractInlineOverlappingRefactoring.get(i) == true) {
indicesToBeRemoved.add(i);
else {
allReplacementsCoverEntireStatement = true;
}
if(!allReplacementsCoverEntireStatement) {
int minimum = replacementTypeCount.get(0);
for(int i=1; i<replacementTypeCount.size(); i++) {
if(replacementTypeCount.get(i) < minimum) {
minimum = replacementTypeCount.get(i);
}
}
for(int i=0; i<replacementTypeCount.size(); i++) {
if(replacementTypeCount.get(i) > minimum && !extractInlineOverlappingRefactoring.get(i) == true) {
indicesToBeRemoved.add(i);
}
}
}
}
Expand Down

0 comments on commit 12586dc

Please sign in to comment.