Skip to content

Commit

Permalink
Fix import declaration handling when inner classes exist
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Jul 31, 2024
1 parent ef4236f commit 80902e8
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 80 deletions.
18 changes: 18 additions & 0 deletions src/main/java/org/codetracker/AbstractTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.codetracker.element.Block;
import org.codetracker.element.Class;
import org.codetracker.element.Comment;
import org.codetracker.element.Import;
import org.codetracker.element.Method;
import org.refactoringminer.api.RefactoringMinerTimedOutException;
import org.refactoringminer.rm1.GitHistoryRefactoringMinerImpl;
Expand Down Expand Up @@ -567,9 +568,26 @@ else if (current instanceof Block) {
else if (current instanceof Comment) {
return getComment(umlModel, version, current::equalIdentifierIgnoringVersion);
}
else if (current instanceof Import) {
return getImport(umlModel, version, current::equalIdentifierIgnoringVersion);
}
return current;
}

protected static Import getImport(UMLModel umlModel, Version version, Predicate<Import> predicate) {
if (umlModel != null)
for (UMLClass umlClass : umlModel.getClassList()) {
if (umlClass.isTopLevel()) {
Class clazz = Class.of(umlClass, version);
Import im = clazz.findImport(predicate);
if (im != null) {
return im;
}
}
}
return null;
}

protected static Block getBlock(UMLModel umlModel, Version version, Predicate<Block> predicate) {
if (umlModel != null)
for (UMLClass umlClass : umlModel.getClassList()) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/codetracker/FileTrackerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ private void processImportsAndClassComments(UMLAbstractClassDiff classDiff, Clas
ImportTrackerChangeHistory startImportChangeHistory = (ImportTrackerChangeHistory) programElementMap.get(startImport);
if (rightClass.getUmlClass().getImportedTypes().size() > 0) {
Import currentImport = startImportChangeHistory.poll();
if (currentImport == null) {
if (currentImport == null || currentImport.isAdded()) {
continue;
}
Import rightImport = rightClass.findImport(currentImport::equalIdentifierIgnoringVersion);
Expand All @@ -415,7 +415,7 @@ else if (key instanceof Comment) {
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if (startComment.getClazz().isPresent()) {
Comment currentComment = startCommentChangeHistory.poll();
if (currentComment == null) {
if (currentComment == null || currentComment.isAdded()) {
continue;
}
Comment rightComment = rightClass.findComment(currentComment::equalIdentifierIgnoringVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ protected static Class getClass(UMLModel umlModel, Version version, String fileP
protected static Import getImport(UMLModel umlModel, Version version, String filePath, Predicate<Import> predicate) {
if (umlModel != null)
for (UMLClass umlClass : umlModel.getClassList()) {
if (umlClass.getSourceFile().equals(filePath)) {
if (umlClass.getSourceFile().equals(filePath) && umlClass.isTopLevel()) {
for (UMLImport umlImport : umlClass.getImportedTypes()) {
Import imp = Import.of(umlImport, umlClass, version);
if (predicate.test(imp))
Expand Down
Loading

0 comments on commit 80902e8

Please sign in to comment.