Skip to content

Commit e5aaae5

Browse files
committed
Cross-language performance optimization
1 parent e51f843 commit e5aaae5

9 files changed

Lines changed: 1892 additions & 1717 deletions

‎src/main/java/org/codetracker/AnnotationTrackerImpl.java‎

Lines changed: 1106 additions & 1080 deletions
Large diffs are not rendered by default.

‎src/main/java/org/codetracker/AttributeTrackerImpl.java‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import gr.uom.java.xmi.UMLModel;
44
import gr.uom.java.xmi.diff.*;
5+
6+
import org.apache.commons.io.FilenameUtils;
57
import org.apache.commons.lang3.tuple.Pair;
68
import org.codetracker.api.AttributeTracker;
79
import org.codetracker.api.CodeElementNotFoundException;
@@ -15,6 +17,7 @@
1517
import org.refactoringminer.api.RefactoringType;
1618

1719
import java.util.*;
20+
import java.util.stream.Collectors;
1821

1922
public class AttributeTrackerImpl extends BaseTracker implements AttributeTracker {
2023
private final AttributeTrackerChangeHistory changeHistory;
@@ -85,7 +88,17 @@ public History<Attribute> track() throws Exception {
8588
break;
8689
}
8790
UMLModel leftModel = getUMLModel(parentCommitId, Collections.singleton(rightAttribute.getFilePath()));
88-
91+
if(leftModel.getClassList().isEmpty()) {
92+
Set<String> filePathsBefore = new LinkedHashSet<String>();
93+
Set<String> filePathsCurrent = new LinkedHashSet<String>();
94+
Map<String, String> renamedFilesHint = new HashMap<String, String>();
95+
populateFileSets(commitId, filePathsBefore, filePathsCurrent, renamedFilesHint);
96+
String noExtension = FilenameUtils.removeExtension(rightAttribute.getFilePath());
97+
Set<String> matchingNames = filePathsBefore.stream().filter(path -> path.startsWith(noExtension + ".")).collect(Collectors.toSet());
98+
if(matchingNames.size() > 0) {
99+
leftModel = getUMLModel(parentCommitId, matchingNames);
100+
}
101+
}
89102
//NO CHANGE
90103
Attribute leftAttribute = getAttribute(leftModel, parentVersion, rightAttribute::equalIdentifierIgnoringVersion);
91104
if (leftAttribute != null) {
@@ -284,7 +297,17 @@ public HistoryInfo<Attribute> blame() throws Exception {
284297
break;
285298
}
286299
UMLModel leftModel = getUMLModel(parentCommitId, Collections.singleton(rightAttribute.getFilePath()));
287-
300+
if(leftModel.getClassList().isEmpty()) {
301+
Set<String> filePathsBefore = new LinkedHashSet<String>();
302+
Set<String> filePathsCurrent = new LinkedHashSet<String>();
303+
Map<String, String> renamedFilesHint = new HashMap<String, String>();
304+
populateFileSets(commitId, filePathsBefore, filePathsCurrent, renamedFilesHint);
305+
String noExtension = FilenameUtils.removeExtension(rightAttribute.getFilePath());
306+
Set<String> matchingNames = filePathsBefore.stream().filter(path -> path.startsWith(noExtension + ".")).collect(Collectors.toSet());
307+
if(matchingNames.size() > 0) {
308+
leftModel = getUMLModel(parentCommitId, matchingNames);
309+
}
310+
}
288311
//NO CHANGE
289312
Attribute leftAttribute = getAttribute(leftModel, parentVersion, rightAttribute::equalIdentifierIgnoringVersion);
290313
if (leftAttribute != null) {

‎src/main/java/org/codetracker/BlockTrackerImpl.java‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import gr.uom.java.xmi.LocationInfo.CodeElementType;
55
import gr.uom.java.xmi.decomposition.*;
66
import gr.uom.java.xmi.diff.*;
7+
8+
import org.apache.commons.io.FilenameUtils;
79
import org.apache.commons.lang3.tuple.Pair;
810
import org.codetracker.api.BlockTracker;
911
import org.codetracker.api.CodeElementNotFoundException;
@@ -18,6 +20,7 @@
1820

1921
import java.util.*;
2022
import java.util.function.Predicate;
23+
import java.util.stream.Collectors;
2124

2225
public class BlockTrackerImpl extends BaseTracker implements BlockTracker {
2326
private final BlockTrackerChangeHistory changeHistory;
@@ -97,6 +100,17 @@ public History<Block> track() throws Exception {
97100
break;
98101
}
99102
UMLModel leftModel = getUMLModel(parentCommitId, Collections.singleton(currentMethod.getFilePath()));
103+
if(leftModel.getClassList().isEmpty()) {
104+
Set<String> filePathsBefore = new LinkedHashSet<String>();
105+
Set<String> filePathsCurrent = new LinkedHashSet<String>();
106+
Map<String, String> renamedFilesHint = new HashMap<String, String>();
107+
populateFileSets(commitId, filePathsBefore, filePathsCurrent, renamedFilesHint);
108+
String noExtension = FilenameUtils.removeExtension(currentMethod.getFilePath());
109+
Set<String> matchingNames = filePathsBefore.stream().filter(path -> path.startsWith(noExtension + ".")).collect(Collectors.toSet());
110+
if(matchingNames.size() > 0) {
111+
leftModel = getUMLModel(parentCommitId, matchingNames);
112+
}
113+
}
100114
//NO CHANGE
101115
Method leftMethod = getMethod(leftModel, parentVersion, rightMethod::equalIdentifierIgnoringVersion);
102116
if (leftMethod != null) {
@@ -345,8 +359,8 @@ public History.HistoryInfo<Block> blame() throws Exception {
345359
List<String> commits = null;
346360
String lastFileName = null;
347361
while (!changeHistory.isEmpty()) {
348-
History.HistoryInfo<Block> blame = changeHistory.blameReturn(startBlock);
349-
if (blame != null) return blame;
362+
History.HistoryInfo<Block> blame = changeHistory.blameReturn(startBlock);
363+
if (blame != null) return blame;
350364
Block currentBlock = changeHistory.poll();
351365
if (currentBlock.isAdded()) {
352366
commits = null;
@@ -392,6 +406,17 @@ public History.HistoryInfo<Block> blame() throws Exception {
392406
break;
393407
}
394408
UMLModel leftModel = getUMLModel(parentCommitId, Collections.singleton(currentMethod.getFilePath()));
409+
if(leftModel.getClassList().isEmpty()) {
410+
Set<String> filePathsBefore = new LinkedHashSet<String>();
411+
Set<String> filePathsCurrent = new LinkedHashSet<String>();
412+
Map<String, String> renamedFilesHint = new HashMap<String, String>();
413+
populateFileSets(commitId, filePathsBefore, filePathsCurrent, renamedFilesHint);
414+
String noExtension = FilenameUtils.removeExtension(currentMethod.getFilePath());
415+
Set<String> matchingNames = filePathsBefore.stream().filter(path -> path.startsWith(noExtension + ".")).collect(Collectors.toSet());
416+
if(matchingNames.size() > 0) {
417+
leftModel = getUMLModel(parentCommitId, matchingNames);
418+
}
419+
}
395420
//NO CHANGE
396421
Method leftMethod = getMethod(leftModel, parentVersion, rightMethod::equalIdentifierIgnoringVersion);
397422
if (leftMethod != null) {

‎src/main/java/org/codetracker/ClassTrackerImpl.java‎

Lines changed: 80 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import gr.uom.java.xmi.UMLModel;
55
import gr.uom.java.xmi.UMLType;
66
import gr.uom.java.xmi.diff.*;
7+
8+
import org.apache.commons.io.FilenameUtils;
79
import org.apache.commons.lang3.tuple.Pair;
810
import org.codetracker.api.ClassTracker;
911
import org.codetracker.api.History;
@@ -18,9 +20,10 @@
1820
import org.refactoringminer.api.Refactoring;
1921

2022
import java.util.*;
23+
import java.util.stream.Collectors;
2124

2225
public class ClassTrackerImpl extends BaseTracker implements ClassTracker {
23-
private final ClassTrackerChangeHistory changeHistory;
26+
private final ClassTrackerChangeHistory changeHistory;
2427

2528
public ClassTrackerImpl(Repository repository, String startCommitId, String filePath, String className, int classDeclarationLineNumber) {
2629
super(repository, startCommitId, filePath);
@@ -82,30 +85,40 @@ public History<Class> track() throws Exception {
8285
break;
8386
}
8487
UMLModel leftModel = getUMLModel(parentCommitId, Collections.singleton(rightClass.getFilePath()));
85-
88+
if(leftModel.getClassList().isEmpty()) {
89+
Set<String> filePathsBefore = new LinkedHashSet<String>();
90+
Set<String> filePathsCurrent = new LinkedHashSet<String>();
91+
Map<String, String> renamedFilesHint = new HashMap<String, String>();
92+
populateFileSets(commitId, filePathsBefore, filePathsCurrent, renamedFilesHint);
93+
String noExtension = FilenameUtils.removeExtension(rightClass.getFilePath());
94+
Set<String> matchingNames = filePathsBefore.stream().filter(path -> path.startsWith(noExtension + ".")).collect(Collectors.toSet());
95+
if(matchingNames.size() > 0) {
96+
leftModel = getUMLModel(parentCommitId, matchingNames);
97+
}
98+
}
8699
//NO CHANGE
87100
Class leftClass = getClass(leftModel, parentVersion, rightClass::equalIdentifierIgnoringVersion);
88101
if (leftClass != null) {
89-
UMLType leftSuperclass = leftClass.getUmlClass().getSuperclass();
90-
UMLType rightSuperclass = rightClass.getUmlClass().getSuperclass();
91-
if (leftSuperclass != null && rightSuperclass != null) {
92-
if (!leftSuperclass.equals(rightSuperclass)) {
93-
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
94-
changeHistory.get().connectRelatedNodes();
95-
}
96-
}
97-
else if (leftSuperclass != null && rightSuperclass == null) {
98-
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
99-
changeHistory.get().connectRelatedNodes();
100-
}
101-
else if (leftSuperclass == null && rightSuperclass != null) {
102-
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
103-
changeHistory.get().connectRelatedNodes();
104-
}
105-
if (!leftClass.getUmlClass().getImplementedInterfaces().equals(rightClass.getUmlClass().getImplementedInterfaces())) {
106-
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.INTERFACE_LIST_CHANGE));
107-
changeHistory.get().connectRelatedNodes();
108-
}
102+
UMLType leftSuperclass = leftClass.getUmlClass().getSuperclass();
103+
UMLType rightSuperclass = rightClass.getUmlClass().getSuperclass();
104+
if (leftSuperclass != null && rightSuperclass != null) {
105+
if (!leftSuperclass.equals(rightSuperclass)) {
106+
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
107+
changeHistory.get().connectRelatedNodes();
108+
}
109+
}
110+
else if (leftSuperclass != null && rightSuperclass == null) {
111+
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
112+
changeHistory.get().connectRelatedNodes();
113+
}
114+
else if (leftSuperclass == null && rightSuperclass != null) {
115+
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
116+
changeHistory.get().connectRelatedNodes();
117+
}
118+
if (!leftClass.getUmlClass().getImplementedInterfaces().equals(rightClass.getUmlClass().getImplementedInterfaces())) {
119+
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.INTERFACE_LIST_CHANGE));
120+
changeHistory.get().connectRelatedNodes();
121+
}
109122
historyReport.step2PlusPlus();
110123
continue;
111124
}
@@ -187,8 +200,8 @@ public HistoryInfo<Class> blame() throws Exception {
187200
List<String> commits = null;
188201
String lastFileName = null;
189202
while (!changeHistory.isEmpty()) {
190-
History.HistoryInfo<Class> blame = startPackage != null ? changeHistory.blameReturn(startPackage) : changeHistory.blameReturn(startClass);
191-
if (blame != null) return blame;
203+
History.HistoryInfo<Class> blame = startPackage != null ? changeHistory.blameReturn(startPackage) : changeHistory.blameReturn(startClass);
204+
if (blame != null) return blame;
192205
Class currentClass = changeHistory.poll();
193206
if (currentClass.isAdded()) {
194207
commits = null;
@@ -226,30 +239,40 @@ public HistoryInfo<Class> blame() throws Exception {
226239
break;
227240
}
228241
UMLModel leftModel = getUMLModel(parentCommitId, Collections.singleton(rightClass.getFilePath()));
229-
242+
if(leftModel.getClassList().isEmpty()) {
243+
Set<String> filePathsBefore = new LinkedHashSet<String>();
244+
Set<String> filePathsCurrent = new LinkedHashSet<String>();
245+
Map<String, String> renamedFilesHint = new HashMap<String, String>();
246+
populateFileSets(commitId, filePathsBefore, filePathsCurrent, renamedFilesHint);
247+
String noExtension = FilenameUtils.removeExtension(rightClass.getFilePath());
248+
Set<String> matchingNames = filePathsBefore.stream().filter(path -> path.startsWith(noExtension + ".")).collect(Collectors.toSet());
249+
if(matchingNames.size() > 0) {
250+
leftModel = getUMLModel(parentCommitId, matchingNames);
251+
}
252+
}
230253
//NO CHANGE
231254
Class leftClass = getClass(leftModel, parentVersion, rightClass::equalIdentifierIgnoringVersion);
232255
if (leftClass != null) {
233-
UMLType leftSuperclass = leftClass.getUmlClass().getSuperclass();
234-
UMLType rightSuperclass = rightClass.getUmlClass().getSuperclass();
235-
if (leftSuperclass != null && rightSuperclass != null) {
236-
if (!leftSuperclass.equals(rightSuperclass)) {
237-
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
238-
changeHistory.get().connectRelatedNodes();
239-
}
240-
}
241-
else if (leftSuperclass != null && rightSuperclass == null) {
242-
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
243-
changeHistory.get().connectRelatedNodes();
244-
}
245-
else if (leftSuperclass == null && rightSuperclass != null) {
246-
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
247-
changeHistory.get().connectRelatedNodes();
248-
}
249-
if (!leftClass.getUmlClass().getImplementedInterfaces().equals(rightClass.getUmlClass().getImplementedInterfaces())) {
250-
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.INTERFACE_LIST_CHANGE));
251-
changeHistory.get().connectRelatedNodes();
252-
}
256+
UMLType leftSuperclass = leftClass.getUmlClass().getSuperclass();
257+
UMLType rightSuperclass = rightClass.getUmlClass().getSuperclass();
258+
if (leftSuperclass != null && rightSuperclass != null) {
259+
if (!leftSuperclass.equals(rightSuperclass)) {
260+
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
261+
changeHistory.get().connectRelatedNodes();
262+
}
263+
}
264+
else if (leftSuperclass != null && rightSuperclass == null) {
265+
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
266+
changeHistory.get().connectRelatedNodes();
267+
}
268+
else if (leftSuperclass == null && rightSuperclass != null) {
269+
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
270+
changeHistory.get().connectRelatedNodes();
271+
}
272+
if (!leftClass.getUmlClass().getImplementedInterfaces().equals(rightClass.getUmlClass().getImplementedInterfaces())) {
273+
changeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.INTERFACE_LIST_CHANGE));
274+
changeHistory.get().connectRelatedNodes();
275+
}
253276
historyReport.step2PlusPlus();
254277
continue;
255278
}
@@ -271,24 +294,24 @@ else if (leftSuperclass == null && rightSuperclass != null) {
271294
}
272295
}
273296
if(commitModel.fileContentsBeforeOriginal.isEmpty()) {
274-
Pair<UMLModel, UMLModel> umlModelPairPartial = getUMLModelPair(commitModel, rightClass.getFilePath(), s -> true, true);
275-
List<UMLClass> classList = umlModelPairPartial.getRight().getClassList();
276-
UMLClass matchedClass = null;
277-
for(UMLClass umlClass : classList) {
278-
Class tempClass = Class.of(umlClass, currentVersion);
279-
if(rightClass.equalIdentifierIgnoringVersion(tempClass)) {
280-
matchedClass = umlClass;
281-
break;
282-
}
283-
}
284-
if(matchedClass != null) {
297+
Pair<UMLModel, UMLModel> umlModelPairPartial = getUMLModelPair(commitModel, rightClass.getFilePath(), s -> true, true);
298+
List<UMLClass> classList = umlModelPairPartial.getRight().getClassList();
299+
UMLClass matchedClass = null;
300+
for(UMLClass umlClass : classList) {
301+
Class tempClass = Class.of(umlClass, currentVersion);
302+
if(rightClass.equalIdentifierIgnoringVersion(tempClass)) {
303+
matchedClass = umlClass;
304+
break;
305+
}
306+
}
307+
if(matchedClass != null) {
285308
leftClass = Class.of(matchedClass, parentVersion);
286309
changeHistory.get().handleAdd(leftClass, rightClass, "new class");
287310
changeHistory.get().connectRelatedNodes();
288311
changeHistory.addFirst(leftClass);
289312
historyReport.step5PlusPlus();
290313
break;
291-
}
314+
}
292315
}
293316
{
294317
Pair<UMLModel, UMLModel> umlModelPairAll = getUMLModelPair(commitModel, rightClass.getFilePath(), s -> true, false);

0 commit comments

Comments
 (0)