diff --git a/src/main/java/org/codetracker/AbstractTracker.java b/src/main/java/org/codetracker/AbstractTracker.java index 9b8a5c6391d..d0cb1b72108 100644 --- a/src/main/java/org/codetracker/AbstractTracker.java +++ b/src/main/java/org/codetracker/AbstractTracker.java @@ -483,6 +483,7 @@ protected static boolean isNewlyAddedFile(CommitModel commitModel, String curren protected static Set getRightSideFileNames(Method currentMethod, CommitModel commitModel, UMLModelDiff umlModelDiff) { String currentFilePath = currentMethod.getFilePath(); + String currentSourceFolder = currentMethod.getLocation().getSourceFolder(); String currentClassName = currentMethod.getUmlOperation().getClassName(); Set toBeAddedFileNamesIfTheyAreNewFiles = new HashSet<>(); if (currentMethod.getUmlOperation() instanceof UMLOperation) { @@ -501,7 +502,7 @@ protected static Set getRightSideFileNames(Method currentMethod, CommitM continue; toBeAddedFileNamesIfTheyAreNewFiles.add(parameterType + ".java"); } - Set rightSideFileNames = getRightSideFileNames(currentFilePath, currentClassName, toBeAddedFileNamesIfTheyAreNewFiles, commitModel, umlModelDiff); + Set rightSideFileNames = getRightSideFileNames(currentFilePath, currentSourceFolder, currentClassName, toBeAddedFileNamesIfTheyAreNewFiles, commitModel, umlModelDiff); //add all right side files having a main method if (currentMethod.getUmlOperation().isMain()) { for (String filePath : commitModel.fileContentsCurrentOriginal.keySet()) { @@ -514,96 +515,94 @@ protected static Set getRightSideFileNames(Method currentMethod, CommitM return rightSideFileNames; } - protected static Set getRightSideFileNames(String currentFilePath, String currentClassName, Set toBeAddedFileNamesIfTheyAreNewFiles, CommitModel commitModel, UMLModelDiff umlModelDiff) { + protected static Set getRightSideFileNames(String currentFilePath, String sourceFolder, String currentClassName, Set toBeAddedFileNamesIfTheyAreNewFiles, CommitModel commitModel, UMLModelDiff umlModelDiff) { Set fileNames = new HashSet<>(); fileNames.add(currentFilePath); - Set classesInChildModel = umlModelDiff.findClassesInChildModel(currentClassName); + UMLAbstractClass classInChildModel = umlModelDiff.findClassInChildModel(sourceFolder, currentClassName); boolean newlyAddedFile = isNewlyAddedFile(commitModel, currentFilePath); - for (UMLAbstractClass classInChildModel : classesInChildModel) { - if (classInChildModel instanceof UMLClass) { - UMLClass umlClass = (UMLClass) classInChildModel; - - StringBuilder regxSb = new StringBuilder(); - - String orChar = ""; - if (umlClass.getSuperclass() != null) { - regxSb.append(orChar).append("\\s*extends\\s*").append(umlClass.getSuperclass().getClassType()); - orChar = "|"; - if (newlyAddedFile) { - regxSb.append(orChar).append("\\s*class\\s*").append(umlClass.getSuperclass().getClassType()).append("\\s\\s*"); - } - } - - for (UMLType implementedInterface : umlClass.getImplementedInterfaces()) { - regxSb.append(orChar).append("\\s*implements\\s*.*").append(implementedInterface).append("\\s*"); - orChar = "|"; - if (newlyAddedFile) { - regxSb.append(orChar).append("\\s*interface\\s*").append(implementedInterface.getClassType()).append("\\s*\\{"); - } - } - - //newly added file - if (newlyAddedFile) { - regxSb.append(orChar).append("@link\\s*").append(umlClass.getNonQualifiedName()); - orChar = "|"; - regxSb.append(orChar).append("new\\s*").append(umlClass.getNonQualifiedName()).append("\\("); - regxSb.append(orChar).append("@deprecated\\s*.*").append(umlClass.getNonQualifiedName()).append("\\s*.*\n"); - regxSb.append(orChar).append("\\s*extends\\s*").append(umlClass.getNonQualifiedName()).append("\\s*\\{"); - } - - String regx = regxSb.toString(); - if (!regx.isEmpty()) { - Pattern pattern = Pattern.compile(regx); - for (Map.Entry entry : commitModel.fileContentsCurrentTrimmed.entrySet()) { - Matcher matcher = pattern.matcher(entry.getValue()); - if (matcher.find()) { - String matcherGroup = matcher.group().trim(); - String filePath = entry.getKey(); - boolean isAnExistingFile = commitModel.fileContentsBeforeTrimmed.containsKey(filePath) || commitModel.renamedFilesHint.values().stream().anyMatch(s -> s.equals(filePath)); - if (matcherGroup.startsWith("extends") && matcherGroup.contains(umlClass.getNonQualifiedName())) { - if (isAnExistingFile) { - fileNames.add(filePath); - } - } else if (matcherGroup.startsWith("implements") || matcherGroup.startsWith("extends")) { - if (isAnExistingFile) { - String[] split = matcherGroup.split("\\s"); - String className = split[split.length - 1]; - if (className.contains(".")) { - className = className.substring(0, className.indexOf(".")); - } - String[] tokens = CAMEL_CASE_SPLIT_PATTERN.split(className); - final String fileName = className + ".java"; - if (commitModel.fileContentsCurrentTrimmed.keySet().stream().anyMatch(s -> s.endsWith(fileName) || s.endsWith(tokens[tokens.length - 1] + ".java"))) { - fileNames.add(filePath); - } - } - } else if (matcherGroup.startsWith("new")) { - if (isAnExistingFile) { - fileNames.add(filePath); - } - } else if (matcherGroup.startsWith("@link")) { - fileNames.add(filePath); //TODO: add existing file condition and test - } else if (matcherGroup.startsWith("class")) { - if (isAnExistingFile) { - fileNames.add(filePath); - } - } else if (matcherGroup.startsWith("@deprecated")) { - if (isAnExistingFile) { - fileNames.add(filePath); - } - } else if (matcherGroup.startsWith("interface")) { - if (isAnExistingFile) { - fileNames.add(filePath); - } - } - - } - } - } - if (!umlClass.isTopLevel()) { - fileNames.addAll(getRightSideFileNames(currentFilePath, umlClass.getPackageName(), toBeAddedFileNamesIfTheyAreNewFiles, commitModel, umlModelDiff)); - } - } + if (classInChildModel instanceof UMLClass) { + UMLClass umlClass = (UMLClass) classInChildModel; + + StringBuilder regxSb = new StringBuilder(); + + String orChar = ""; + if (umlClass.getSuperclass() != null) { + regxSb.append(orChar).append("\\s*extends\\s*").append(umlClass.getSuperclass().getClassType()); + orChar = "|"; + if (newlyAddedFile) { + regxSb.append(orChar).append("\\s*class\\s*").append(umlClass.getSuperclass().getClassType()).append("\\s\\s*"); + } + } + + for (UMLType implementedInterface : umlClass.getImplementedInterfaces()) { + regxSb.append(orChar).append("\\s*implements\\s*.*").append(implementedInterface).append("\\s*"); + orChar = "|"; + if (newlyAddedFile) { + regxSb.append(orChar).append("\\s*interface\\s*").append(implementedInterface.getClassType()).append("\\s*\\{"); + } + } + + //newly added file + if (newlyAddedFile) { + regxSb.append(orChar).append("@link\\s*").append(umlClass.getNonQualifiedName()); + orChar = "|"; + regxSb.append(orChar).append("new\\s*").append(umlClass.getNonQualifiedName()).append("\\("); + regxSb.append(orChar).append("@deprecated\\s*.*").append(umlClass.getNonQualifiedName()).append("\\s*.*\n"); + regxSb.append(orChar).append("\\s*extends\\s*").append(umlClass.getNonQualifiedName()).append("\\s*\\{"); + } + + String regx = regxSb.toString(); + if (!regx.isEmpty()) { + Pattern pattern = Pattern.compile(regx); + for (Map.Entry entry : commitModel.fileContentsCurrentTrimmed.entrySet()) { + Matcher matcher = pattern.matcher(entry.getValue()); + if (matcher.find()) { + String matcherGroup = matcher.group().trim(); + String filePath = entry.getKey(); + boolean isAnExistingFile = commitModel.fileContentsBeforeTrimmed.containsKey(filePath) || commitModel.renamedFilesHint.values().stream().anyMatch(s -> s.equals(filePath)); + if (matcherGroup.startsWith("extends") && matcherGroup.contains(umlClass.getNonQualifiedName())) { + if (isAnExistingFile) { + fileNames.add(filePath); + } + } else if (matcherGroup.startsWith("implements") || matcherGroup.startsWith("extends")) { + if (isAnExistingFile) { + String[] split = matcherGroup.split("\\s"); + String className = split[split.length - 1]; + if (className.contains(".")) { + className = className.substring(0, className.indexOf(".")); + } + String[] tokens = CAMEL_CASE_SPLIT_PATTERN.split(className); + final String fileName = className + ".java"; + if (commitModel.fileContentsCurrentTrimmed.keySet().stream().anyMatch(s -> s.endsWith(fileName) || s.endsWith(tokens[tokens.length - 1] + ".java"))) { + fileNames.add(filePath); + } + } + } else if (matcherGroup.startsWith("new")) { + if (isAnExistingFile) { + fileNames.add(filePath); + } + } else if (matcherGroup.startsWith("@link")) { + fileNames.add(filePath); //TODO: add existing file condition and test + } else if (matcherGroup.startsWith("class")) { + if (isAnExistingFile) { + fileNames.add(filePath); + } + } else if (matcherGroup.startsWith("@deprecated")) { + if (isAnExistingFile) { + fileNames.add(filePath); + } + } else if (matcherGroup.startsWith("interface")) { + if (isAnExistingFile) { + fileNames.add(filePath); + } + } + + } + } + } + if (!umlClass.isTopLevel()) { + fileNames.addAll(getRightSideFileNames(currentFilePath, sourceFolder, umlClass.getPackageName(), toBeAddedFileNamesIfTheyAreNewFiles, commitModel, umlModelDiff)); + } } @@ -632,7 +631,7 @@ protected static boolean isClassAdded(UMLModelDiff modelDiff, String className) return false; } - protected static boolean isAttributeAdded(UMLModelDiff modelDiff, String className, Predicate equalOperator, Version currentVersion) { + protected static boolean isAttributeAdded(UMLModelDiff modelDiff, String sourceFolder, String className, Predicate equalOperator, Version currentVersion) { List addedAttributes = getAllClassesDiff(modelDiff) .stream() .map(UMLClassBaseDiff::getAddedAttributes) @@ -652,8 +651,8 @@ protected static boolean isAttributeAdded(UMLModelDiff modelDiff, String classNa return true; } - Set addedClasses = modelDiff.getAllAddedClasses(className); - for (UMLClass addedClass : addedClasses) { + UMLClass addedClass = modelDiff.getAddedClass(sourceFolder, className); + if (addedClass != null) { for (UMLAttribute attribute : addedClass.getAttributes()) { if (isAttributeAdded(attribute, equalOperator, currentVersion)) return true; @@ -713,7 +712,7 @@ protected static boolean isAttributeAdded(UMLAttribute addedAttribute, Predicate return false; } - protected static boolean isMethodAdded(UMLModelDiff modelDiff, String className, Predicate equalOperator, Consumer addedMethodHandler, Version currentVersion) { + protected static boolean isMethodAdded(UMLModelDiff modelDiff, String sourceFolder, String className, Predicate equalOperator, Consumer addedMethodHandler, Version currentVersion) { List addedOperations = getAllClassesDiff(modelDiff) .stream() .map(UMLClassBaseDiff::getAddedOperations) @@ -724,8 +723,8 @@ protected static boolean isMethodAdded(UMLModelDiff modelDiff, String className, return true; } - Set addedClasses = modelDiff.getAllAddedClasses(className); - for (UMLClass addedClass : addedClasses) { + UMLClass addedClass = modelDiff.getAddedClass(sourceFolder, className); + if (addedClass != null) { for (UMLOperation operation : addedClass.getOperations()) { if (isMethodAdded(operation, equalOperator, addedMethodHandler, currentVersion)) return true; diff --git a/src/main/java/org/codetracker/AnnotationTrackerImpl.java b/src/main/java/org/codetracker/AnnotationTrackerImpl.java index a1951e5e710..fd39bf9309e 100644 --- a/src/main/java/org/codetracker/AnnotationTrackerImpl.java +++ b/src/main/java/org/codetracker/AnnotationTrackerImpl.java @@ -312,7 +312,7 @@ else if (leftOperation instanceof UMLInitializer && rightOperation instanceof UM } } - if (isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getClassName(), rightMethod::equalIdentifierIgnoringVersion, method -> { + if (isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getLocationInfo().getSourceFolder(), rightMethod.getUmlOperation().getClassName(), rightMethod::equalIdentifierIgnoringVersion, method -> { }, currentVersion)) { Annotation annotationBefore = Annotation.of(rightAnnotation.getAnnotation(), rightAnnotation.getOperation().get(), parentVersion); changeHistory.get().handleAdd(annotationBefore, rightAnnotation, "added with method"); @@ -441,7 +441,7 @@ else if (currentAnnotation.getOperation().get() instanceof UMLAttribute) { } } { - Set fileNames = getRightSideFileNames(currentAttribute.getFilePath(), currentAttribute.getUmlAttribute().getClassName(), Collections.emptySet(), commitModel, umlModelDiffLocal); + Set fileNames = getRightSideFileNames(currentAttribute.getFilePath(), currentAttribute.getUmlAttribute().getLocationInfo().getSourceFolder(), currentAttribute.getUmlAttribute().getClassName(), Collections.emptySet(), commitModel, umlModelDiffLocal); Pair umlModelPairAll = getUMLModelPair(commitModel, currentAttribute.getFilePath(), fileNames::contains, false); UMLModelDiff umlModelDiffAll = umlModelPairAll.getLeft().diff(umlModelPairAll.getRight()); @@ -505,7 +505,7 @@ else if (RefactoringType.MOVE_RENAME_ATTRIBUTE.equals(refactoring.getRefactoring } } - if (isAttributeAdded(umlModelDiffAll, rightAttribute.getUmlAttribute().getClassName(), rightAttribute::equalIdentifierIgnoringVersion, currentVersion)) { + if (isAttributeAdded(umlModelDiffAll, rightAttribute.getUmlAttribute().getLocationInfo().getSourceFolder(), rightAttribute.getUmlAttribute().getClassName(), rightAttribute::equalIdentifierIgnoringVersion, currentVersion)) { Annotation annotationBefore = Annotation.of(rightAnnotation.getAnnotation(), rightAnnotation.getOperation().get(), parentVersion); changeHistory.get().handleAdd(annotationBefore, rightAnnotation, "added with attribute"); changeHistory.add(annotationBefore); diff --git a/src/main/java/org/codetracker/AttributeTrackerChangeHistory.java b/src/main/java/org/codetracker/AttributeTrackerChangeHistory.java index 8c06afb1358..72b27d88481 100644 --- a/src/main/java/org/codetracker/AttributeTrackerChangeHistory.java +++ b/src/main/java/org/codetracker/AttributeTrackerChangeHistory.java @@ -240,7 +240,7 @@ else if (leftInitializer != null && rightInitializer == null) { return false; } - public boolean isAttributeAdded(UMLModelDiff modelDiff, String className, Version currentVersion, Version parentVersion, Predicate equalOperator, List allClassesDiff) { + public boolean isAttributeAdded(UMLModelDiff modelDiff, String sourceFolder, String className, Version currentVersion, Version parentVersion, Predicate equalOperator, List allClassesDiff) { List addedAttributes = allClassesDiff .stream() .map(UMLClassBaseDiff::getAddedAttributes) @@ -261,8 +261,8 @@ public boolean isAttributeAdded(UMLModelDiff modelDiff, String className, Versio return true; } - Set addedClasses = modelDiff.getAllAddedClasses(className); - for (UMLClass addedClass : addedClasses) { + UMLClass addedClass = modelDiff.getAddedClass(sourceFolder, className); + if (addedClass != null) { for (UMLAttribute umlAttribute : addedClass.getAttributes()) { if (handleAddAttribute(currentVersion, parentVersion, equalOperator, umlAttribute, "added with new class")) return true; diff --git a/src/main/java/org/codetracker/AttributeTrackerImpl.java b/src/main/java/org/codetracker/AttributeTrackerImpl.java index 3e85af0ad23..b470929e45c 100644 --- a/src/main/java/org/codetracker/AttributeTrackerImpl.java +++ b/src/main/java/org/codetracker/AttributeTrackerImpl.java @@ -163,7 +163,7 @@ public History track() throws Exception { } } { - Set fileNames = getRightSideFileNames(currentAttribute.getFilePath(), currentAttribute.getUmlAttribute().getClassName(), Collections.emptySet(), commitModel, umlModelDiffLocal); + Set fileNames = getRightSideFileNames(currentAttribute.getFilePath(), currentAttribute.getUmlAttribute().getLocationInfo().getSourceFolder(), currentAttribute.getUmlAttribute().getClassName(), Collections.emptySet(), commitModel, umlModelDiffLocal); if (extractedClassFilePath != null) { fileNames.add(extractedClassFilePath); } @@ -210,7 +210,7 @@ public History track() throws Exception { break; } - if (changeHistory.isAttributeAdded(umlModelDiffAll, rightAttribute.getUmlAttribute().getClassName(), currentVersion, parentVersion, rightAttribute::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { + if (changeHistory.isAttributeAdded(umlModelDiffAll, rightAttribute.getUmlAttribute().getLocationInfo().getSourceFolder(), rightAttribute.getUmlAttribute().getClassName(), currentVersion, parentVersion, rightAttribute::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { historyReport.step5PlusPlus(); break; } @@ -361,7 +361,7 @@ public HistoryInfo blame() throws Exception { } } { - Set fileNames = getRightSideFileNames(currentAttribute.getFilePath(), currentAttribute.getUmlAttribute().getClassName(), Collections.emptySet(), commitModel, umlModelDiffLocal); + Set fileNames = getRightSideFileNames(currentAttribute.getFilePath(), currentAttribute.getUmlAttribute().getLocationInfo().getSourceFolder(), currentAttribute.getUmlAttribute().getClassName(), Collections.emptySet(), commitModel, umlModelDiffLocal); if (extractedClassFilePath != null) { fileNames.add(extractedClassFilePath); } @@ -408,7 +408,7 @@ public HistoryInfo blame() throws Exception { break; } - if (changeHistory.isAttributeAdded(umlModelDiffAll, rightAttribute.getUmlAttribute().getClassName(), currentVersion, parentVersion, rightAttribute::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { + if (changeHistory.isAttributeAdded(umlModelDiffAll, rightAttribute.getUmlAttribute().getLocationInfo().getSourceFolder(), rightAttribute.getUmlAttribute().getClassName(), currentVersion, parentVersion, rightAttribute::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { historyReport.step5PlusPlus(); break; } diff --git a/src/main/java/org/codetracker/AttributeTrackerWithLocalFiles.java b/src/main/java/org/codetracker/AttributeTrackerWithLocalFiles.java index 4c0bb6df644..b763c6518ce 100644 --- a/src/main/java/org/codetracker/AttributeTrackerWithLocalFiles.java +++ b/src/main/java/org/codetracker/AttributeTrackerWithLocalFiles.java @@ -195,7 +195,7 @@ else if (leftInitializer != null && rightInitializer == null) { } } { - Set fileNames = getRightSideFileNames(currentAttribute.getFilePath(), currentAttribute.getUmlAttribute().getClassName(), Collections.emptySet(), commitModel, umlModelDiffLocal); + Set fileNames = getRightSideFileNames(currentAttribute.getFilePath(), currentAttribute.getUmlAttribute().getLocationInfo().getSourceFolder(), currentAttribute.getUmlAttribute().getClassName(), Collections.emptySet(), commitModel, umlModelDiffLocal); if (extractedClassFilePath != null) { fileNames.add(extractedClassFilePath); } @@ -242,7 +242,7 @@ else if (leftInitializer != null && rightInitializer == null) { break; } - if (changeHistory.isAttributeAdded(umlModelDiffAll, rightAttribute.getUmlAttribute().getClassName(), currentVersion, parentVersion, rightAttribute::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { + if (changeHistory.isAttributeAdded(umlModelDiffAll, rightAttribute.getUmlAttribute().getLocationInfo().getSourceFolder(), rightAttribute.getUmlAttribute().getClassName(), currentVersion, parentVersion, rightAttribute::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { historyReport.step5PlusPlus(); break; } diff --git a/src/main/java/org/codetracker/BlockTrackerImpl.java b/src/main/java/org/codetracker/BlockTrackerImpl.java index d005fcdfb39..f791caf386a 100644 --- a/src/main/java/org/codetracker/BlockTrackerImpl.java +++ b/src/main/java/org/codetracker/BlockTrackerImpl.java @@ -305,7 +305,7 @@ else if (leftOperation instanceof UMLInitializer && rightOperation instanceof UM } } - if (isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getClassName(), rightMethod::equalIdentifierIgnoringVersion, method -> { + if (isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getLocationInfo().getSourceFolder(), rightMethod.getUmlOperation().getClassName(), rightMethod::equalIdentifierIgnoringVersion, method -> { }, currentVersion)) { Block blockBefore = Block.of(rightBlock.getComposite(), rightBlock.getOperation(), parentVersion); changeHistory.get().handleAdd(blockBefore, rightBlock, "added with method"); @@ -600,7 +600,7 @@ else if (leftOperation instanceof UMLInitializer && rightOperation instanceof UM } } - if (isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getClassName(), rightMethod::equalIdentifierIgnoringVersion, method -> { + if (isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getLocationInfo().getSourceFolder(), rightMethod.getUmlOperation().getClassName(), rightMethod::equalIdentifierIgnoringVersion, method -> { }, currentVersion)) { Block blockBefore = Block.of(rightBlock.getComposite(), rightBlock.getOperation(), parentVersion); changeHistory.get().handleAdd(blockBefore, rightBlock, "added with method"); diff --git a/src/main/java/org/codetracker/BlockTrackerWithLocalFiles.java b/src/main/java/org/codetracker/BlockTrackerWithLocalFiles.java index 3ae207832e3..d61ab44a1db 100644 --- a/src/main/java/org/codetracker/BlockTrackerWithLocalFiles.java +++ b/src/main/java/org/codetracker/BlockTrackerWithLocalFiles.java @@ -334,7 +334,7 @@ else if (leftOperation instanceof UMLInitializer && rightOperation instanceof UM } } - if (isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getClassName(), rightMethod::equalIdentifierIgnoringVersion, method -> { + if (isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getLocationInfo().getSourceFolder(), rightMethod.getUmlOperation().getClassName(), rightMethod::equalIdentifierIgnoringVersion, method -> { }, currentVersion)) { Block blockBefore = Block.of(rightBlock.getComposite(), rightBlock.getOperation(), parentVersion); changeHistory.get().handleAdd(blockBefore, rightBlock, "added with method"); diff --git a/src/main/java/org/codetracker/CommentTrackerImpl.java b/src/main/java/org/codetracker/CommentTrackerImpl.java index 756e26e8ee5..7e549ec20db 100644 --- a/src/main/java/org/codetracker/CommentTrackerImpl.java +++ b/src/main/java/org/codetracker/CommentTrackerImpl.java @@ -331,7 +331,7 @@ else if (leftOperation instanceof UMLInitializer && rightOperation instanceof UM } } - if (isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getClassName(), rightMethod::equalIdentifierIgnoringVersion, method -> { + if (isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getLocationInfo().getSourceFolder(), rightMethod.getUmlOperation().getClassName(), rightMethod::equalIdentifierIgnoringVersion, method -> { }, currentVersion)) { Comment commentBefore = Comment.of(rightComment.getComment(), rightComment.getOperation().get(), parentVersion); changeHistory.get().handleAdd(commentBefore, rightComment, "added with method"); @@ -460,7 +460,7 @@ else if (currentComment.getOperation().get() instanceof UMLAttribute) { } } { - Set fileNames = getRightSideFileNames(currentAttribute.getFilePath(), currentAttribute.getUmlAttribute().getClassName(), Collections.emptySet(), commitModel, umlModelDiffLocal); + Set fileNames = getRightSideFileNames(currentAttribute.getFilePath(), currentAttribute.getUmlAttribute().getLocationInfo().getSourceFolder(), currentAttribute.getUmlAttribute().getClassName(), Collections.emptySet(), commitModel, umlModelDiffLocal); Pair umlModelPairAll = getUMLModelPair(commitModel, currentAttribute.getFilePath(), fileNames::contains, false); UMLModelDiff umlModelDiffAll = umlModelPairAll.getLeft().diff(umlModelPairAll.getRight()); @@ -524,7 +524,7 @@ else if (RefactoringType.MOVE_RENAME_ATTRIBUTE.equals(refactoring.getRefactoring } } - if (isAttributeAdded(umlModelDiffAll, rightAttribute.getUmlAttribute().getClassName(), rightAttribute::equalIdentifierIgnoringVersion, currentVersion)) { + if (isAttributeAdded(umlModelDiffAll, rightAttribute.getUmlAttribute().getLocationInfo().getSourceFolder(), rightAttribute.getUmlAttribute().getClassName(), rightAttribute::equalIdentifierIgnoringVersion, currentVersion)) { Comment commentBefore = Comment.of(rightComment.getComment(), rightComment.getOperation().get(), parentVersion); changeHistory.get().handleAdd(commentBefore, rightComment, "added with attribute"); changeHistory.add(commentBefore); diff --git a/src/main/java/org/codetracker/FileTrackerImpl.java b/src/main/java/org/codetracker/FileTrackerImpl.java index 6b6ebe913b8..a2d1c775d04 100644 --- a/src/main/java/org/codetracker/FileTrackerImpl.java +++ b/src/main/java/org/codetracker/FileTrackerImpl.java @@ -757,7 +757,7 @@ private void processAddedAttributes(UMLModel rightModel, UMLModelDiff umlModelDi Attribute rightAttribute = getAttribute(rightModel, currentVersion, currentAttribute::equalIdentifierIgnoringVersion); if (rightAttribute == null) rightAttribute = currentAttribute; - if (startAttributeChangeHistory.isAttributeAdded(umlModelDiffAll, rightAttribute.getUmlAttribute().getClassName(), currentVersion, parentVersion, rightAttribute::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { + if (startAttributeChangeHistory.isAttributeAdded(umlModelDiffAll, rightAttribute.getUmlAttribute().getLocationInfo().getSourceFolder(), rightAttribute.getUmlAttribute().getClassName(), currentVersion, parentVersion, rightAttribute::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { for (CodeElement key2 : programElementMap.keySet()) { if (key2 instanceof Comment) { Comment startComment = (Comment)key2; @@ -810,7 +810,7 @@ private void processAddedMethods(UMLModel rightModel, UMLModelDiff umlModelDiffA Method rightMethod = getMethod(rightModel, currentVersion, currentMethod::equalIdentifierIgnoringVersion); if (rightMethod == null) rightMethod = currentMethod; - if (startMethodChangeHistory.isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { + if (startMethodChangeHistory.isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getLocationInfo().getSourceFolder(), rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { for (CodeElement key2 : programElementMap.keySet()) { if (key2 instanceof Block) { Block startBlock = (Block)key2; @@ -993,7 +993,7 @@ else if (key2 instanceof Annotation) { } } } - else if(startAttributeChangeHistory.isAttributeAdded(umlModelDiff, rightAttribute.getUmlAttribute().getClassName(), currentVersion, parentVersion, rightAttribute::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiff))) { + else if(startAttributeChangeHistory.isAttributeAdded(umlModelDiff, rightAttribute.getUmlAttribute().getLocationInfo().getSourceFolder(), rightAttribute.getUmlAttribute().getClassName(), currentVersion, parentVersion, rightAttribute::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiff))) { for (CodeElement key2 : programElementMap.keySet()) { if (key2 instanceof Comment) { Comment startComment = (Comment)key2; @@ -1231,7 +1231,7 @@ else if (key2 instanceof Annotation) { startMethodChangeHistory.handleAddOperation(currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, rightMethod.getUmlOperation(), "moved method"); } } - else if(startMethodChangeHistory.isMethodAdded(umlModelDiff, rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiff))) { + else if(startMethodChangeHistory.isMethodAdded(umlModelDiff, rightMethod.getUmlOperation().getLocationInfo().getSourceFolder(), rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiff))) { for (CodeElement key2 : programElementMap.keySet()) { if (key2 instanceof Block) { Block startBlock = (Block)key2; diff --git a/src/main/java/org/codetracker/FileTrackerWithLocalFilesImpl.java b/src/main/java/org/codetracker/FileTrackerWithLocalFilesImpl.java index f0b70112409..2192507dd29 100644 --- a/src/main/java/org/codetracker/FileTrackerWithLocalFilesImpl.java +++ b/src/main/java/org/codetracker/FileTrackerWithLocalFilesImpl.java @@ -764,7 +764,7 @@ private void processAddedAttributes(UMLModel rightModel, UMLModelDiff umlModelDi Attribute rightAttribute = getAttribute(rightModel, currentVersion, currentAttribute::equalIdentifierIgnoringVersion); if (rightAttribute == null) rightAttribute = currentAttribute; - if (startAttributeChangeHistory.isAttributeAdded(umlModelDiffAll, rightAttribute.getUmlAttribute().getClassName(), currentVersion, parentVersion, rightAttribute::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { + if (startAttributeChangeHistory.isAttributeAdded(umlModelDiffAll, rightAttribute.getUmlAttribute().getLocationInfo().getSourceFolder(), rightAttribute.getUmlAttribute().getClassName(), currentVersion, parentVersion, rightAttribute::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { for (CodeElement key2 : programElementMap.keySet()) { if (key2 instanceof Comment) { Comment startComment = (Comment)key2; @@ -817,7 +817,7 @@ private void processAddedMethods(UMLModel rightModel, UMLModelDiff umlModelDiffA Method rightMethod = getMethod(rightModel, currentVersion, currentMethod::equalIdentifierIgnoringVersion); if (rightMethod == null) rightMethod = currentMethod; - if (startMethodChangeHistory.isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { + if (startMethodChangeHistory.isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getLocationInfo().getSourceFolder(), rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { for (CodeElement key2 : programElementMap.keySet()) { if (key2 instanceof Block) { Block startBlock = (Block)key2; @@ -1000,7 +1000,7 @@ else if (key2 instanceof Annotation) { } } } - else if(startAttributeChangeHistory.isAttributeAdded(umlModelDiff, rightAttribute.getUmlAttribute().getClassName(), currentVersion, parentVersion, rightAttribute::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiff))) { + else if(startAttributeChangeHistory.isAttributeAdded(umlModelDiff, rightAttribute.getUmlAttribute().getLocationInfo().getSourceFolder(), rightAttribute.getUmlAttribute().getClassName(), currentVersion, parentVersion, rightAttribute::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiff))) { for (CodeElement key2 : programElementMap.keySet()) { if (key2 instanceof Comment) { Comment startComment = (Comment)key2; @@ -1238,7 +1238,7 @@ else if (key2 instanceof Annotation) { startMethodChangeHistory.handleAddOperation(currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, rightMethod.getUmlOperation(), "moved method"); } } - else if(startMethodChangeHistory.isMethodAdded(umlModelDiff, rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiff))) { + else if(startMethodChangeHistory.isMethodAdded(umlModelDiff, rightMethod.getUmlOperation().getLocationInfo().getSourceFolder(), rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiff))) { for (CodeElement key2 : programElementMap.keySet()) { if (key2 instanceof Block) { Block startBlock = (Block)key2; diff --git a/src/main/java/org/codetracker/MethodTrackerChangeHistory.java b/src/main/java/org/codetracker/MethodTrackerChangeHistory.java index 46520bfc5d8..232757bc4c6 100644 --- a/src/main/java/org/codetracker/MethodTrackerChangeHistory.java +++ b/src/main/java/org/codetracker/MethodTrackerChangeHistory.java @@ -827,7 +827,7 @@ public Set isMethodContainerChanged(UMLModelDiff umlModelDiffAll, Collec return Collections.emptySet(); } - public boolean isMethodAdded(UMLModelDiff modelDiff, String className, Version currentVersion, Version parentVersion, Predicate equalOperator, List allClassesDiff) { + public boolean isMethodAdded(UMLModelDiff modelDiff, String sourceFolder, String className, Version currentVersion, Version parentVersion, Predicate equalOperator, List allClassesDiff) { List addedOperations = allClassesDiff .stream() .map(UMLClassBaseDiff::getAddedOperations) @@ -859,24 +859,23 @@ public boolean isMethodAdded(UMLModelDiff modelDiff, String className, Version c } } - Set addedClasses = modelDiff.getAllAddedClasses(className); - for (UMLClass addedClass : addedClasses) { + UMLClass addedClass = modelDiff.getAddedClass(sourceFolder, className); + if (addedClass != null) { for (UMLOperation operation : addedClass.getOperations()) { if (handleAddOperation(currentVersion, parentVersion, equalOperator, operation, "added with new class")) return true; } } - if (addedClasses.isEmpty()) { + else { String prefix = new String(className); - Set outerAddedClasses = null; while (prefix.contains(".")) { prefix = prefix.substring(0, prefix.lastIndexOf(".")); - outerAddedClasses = modelDiff.getAllAddedClasses(prefix); - if (!outerAddedClasses.isEmpty()) { + addedClass = modelDiff.getAddedClass(sourceFolder, prefix); + if (addedClass != null) { break; } } - for (UMLClass addedClass : outerAddedClasses) { + if (addedClass != null) { for (UMLAnonymousClass anonymousClass : addedClass.getAnonymousClassList()) { for (UMLOperation operation : anonymousClass.getOperations()) { if (handleAddOperation(currentVersion, parentVersion, equalOperator, operation, "added with new anonymous class")) @@ -940,7 +939,7 @@ public boolean isMethodAdded(UMLModelDiff modelDiff, String className, Version c if (handleAddOperation(currentVersion, parentVersion, equalOperator, operation, "new initializer")) return true; } - for (UMLClass addedClass : addedClasses) { + if (addedClass != null) { for (UMLInitializer operation : addedClass.getInitializers()) { if (handleAddOperation(currentVersion, parentVersion, equalOperator, operation, "added with new class")) return true; diff --git a/src/main/java/org/codetracker/MethodTrackerImpl.java b/src/main/java/org/codetracker/MethodTrackerImpl.java index eaede546817..2092d92db00 100644 --- a/src/main/java/org/codetracker/MethodTrackerImpl.java +++ b/src/main/java/org/codetracker/MethodTrackerImpl.java @@ -246,7 +246,7 @@ public History track() throws Exception { break; } - if (changeHistory.isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { + if (changeHistory.isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getLocationInfo().getSourceFolder(), rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { historyReport.step5PlusPlus(); break; } @@ -447,7 +447,7 @@ public History.HistoryInfo blame() throws Exception { break; } - if (changeHistory.isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { + if (changeHistory.isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getLocationInfo().getSourceFolder(), rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { historyReport.step5PlusPlus(); break; } diff --git a/src/main/java/org/codetracker/MethodTrackerWithLocalFilesImpl.java b/src/main/java/org/codetracker/MethodTrackerWithLocalFilesImpl.java index 0068c960c9d..5c01d72d490 100644 --- a/src/main/java/org/codetracker/MethodTrackerWithLocalFilesImpl.java +++ b/src/main/java/org/codetracker/MethodTrackerWithLocalFilesImpl.java @@ -243,7 +243,7 @@ public History track() throws Exception { break; } - if (changeHistory.isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { + if (changeHistory.isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getLocationInfo().getSourceFolder(), rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiffAll))) { historyReport.step5PlusPlus(); break; } diff --git a/src/main/java/org/codetracker/VariableTrackerImpl.java b/src/main/java/org/codetracker/VariableTrackerImpl.java index 1d7be560b74..43ff0408a09 100644 --- a/src/main/java/org/codetracker/VariableTrackerImpl.java +++ b/src/main/java/org/codetracker/VariableTrackerImpl.java @@ -291,7 +291,7 @@ else if (leftOperation instanceof UMLInitializer && rightOperation instanceof UM } } - if (isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getClassName(), rightMethod::equalIdentifierIgnoringVersion, method -> { + if (isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getLocationInfo().getSourceFolder(), rightMethod.getUmlOperation().getClassName(), rightMethod::equalIdentifierIgnoringVersion, method -> { }, currentVersion)) { Variable variableBefore = Variable.of(rightVariable.getVariableDeclaration(), rightVariable.getOperation(), parentVersion); changeHistory.get().handleAdd(variableBefore, rightVariable, "added with method"); diff --git a/src/main/java/org/codetracker/VariableTrackerWithLocalFiles.java b/src/main/java/org/codetracker/VariableTrackerWithLocalFiles.java index ebd43945b31..0797b3afc5c 100644 --- a/src/main/java/org/codetracker/VariableTrackerWithLocalFiles.java +++ b/src/main/java/org/codetracker/VariableTrackerWithLocalFiles.java @@ -320,7 +320,7 @@ else if (leftOperation instanceof UMLInitializer && rightOperation instanceof UM } } - if (isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getClassName(), rightMethod::equalIdentifierIgnoringVersion, method -> { + if (isMethodAdded(umlModelDiffAll, rightMethod.getUmlOperation().getLocationInfo().getSourceFolder(), rightMethod.getUmlOperation().getClassName(), rightMethod::equalIdentifierIgnoringVersion, method -> { }, currentVersion)) { Variable variableBefore = Variable.of(rightVariable.getVariableDeclaration(), rightVariable.getOperation(), parentVersion); changeHistory.get().handleAdd(variableBefore, rightVariable, "added with method");