From e133c1e8d8a9e95532c688d4160840ce341859e1 Mon Sep 17 00:00:00 2001 From: Pouryafard75 Date: Mon, 6 Jan 2025 16:44:36 -0500 Subject: [PATCH] ASTDiff: Fixes https://github.com/tsantalis/RefactoringMiner/issues/846 --- .../astDiff/matchers/wrappers/FieldDeclarationMatcher.java | 4 +++- .../refactoringminer/astDiff/utils/TreeUtilFunctions.java | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/refactoringminer/astDiff/matchers/wrappers/FieldDeclarationMatcher.java b/src/main/java/org/refactoringminer/astDiff/matchers/wrappers/FieldDeclarationMatcher.java index 5de0b7639c..17387ee51a 100644 --- a/src/main/java/org/refactoringminer/astDiff/matchers/wrappers/FieldDeclarationMatcher.java +++ b/src/main/java/org/refactoringminer/astDiff/matchers/wrappers/FieldDeclarationMatcher.java @@ -98,10 +98,12 @@ private void processFieldDeclaration(Tree srcTree, Tree dstTree, UMLAttribute sr new JavaDocMatcher(optimizationData, srcUMLAttribute.getJavadoc(), dstUMLAttribute.getJavadoc(), umlJavadocDiff) .match(srcTree, dstTree, mappingStore); if (srcVarDeclaration != null && dstVarDeclaration != null) - mappingStore.addMapping(srcVarDeclaration.getChild(0),dstVarDeclaration.getChild(0)); + if (!srcVarDeclaration.getChildren().isEmpty() && !dstVarDeclaration.getChildren().isEmpty()) + mappingStore.addMapping(srcVarDeclaration.getChild(0),dstVarDeclaration.getChild(0)); } private void matchFieldAllModifiers(Tree srcFieldDeclaration, Tree dstFieldDeclaration, UMLAttribute srcUMLAttribute, UMLAttribute dstUMLAttribute, ExtendedMultiMappingStore mappingStore) { + if (srcFieldDeclaration == null || dstFieldDeclaration == null) return; matchModifiersForField(srcFieldDeclaration,dstFieldDeclaration,srcUMLAttribute.getVisibility().toString(),dstUMLAttribute.getVisibility().toString(),mappingStore); if (srcUMLAttribute.isFinal() && dstUMLAttribute.isFinal()) matchModifierForField(srcFieldDeclaration,dstFieldDeclaration,Constants.FINAL,mappingStore); diff --git a/src/main/java/org/refactoringminer/astDiff/utils/TreeUtilFunctions.java b/src/main/java/org/refactoringminer/astDiff/utils/TreeUtilFunctions.java index bbe33ca14b..28b714615a 100644 --- a/src/main/java/org/refactoringminer/astDiff/utils/TreeUtilFunctions.java +++ b/src/main/java/org/refactoringminer/astDiff/utils/TreeUtilFunctions.java @@ -298,9 +298,10 @@ public static boolean isFromType(Tree t1, String type) { return t1.getType().name.equals(type); } - public static Tree findFirstByType(Tree srcFieldDeclaration, String typeName) { + public static Tree findFirstByType(Tree inputTree, String typeName) { + if (inputTree == null) return null; Tree fieldAnnotation = null; - for (Tree child : srcFieldDeclaration.getChildren()) { + for (Tree child : inputTree.getChildren()) { if (isFromType(child, typeName)) { fieldAnnotation = child; break;