Improved the extraction of variable references
for fields accessed through "this" reference
@@ -14,14 +14,19 @@ public class VariableReferenceExtractor {
AbstractCodeFragment fragment1 = mapping.getFragment1();
AbstractCodeFragment fragment2 = mapping.getFragment2();
if(scope1.subsumes(fragment1.getLocationInfo()) && scope2.subsumes(fragment2.getLocationInfo()) &&
- fragment1.getVariables().contains(declaration1.getVariableName()) &&
- fragment2.getVariables().contains(declaration2.getVariableName())) {
+ usesVariable(fragment1, declaration1) && usesVariable(fragment2, declaration2)) {
references.add(mapping);
}
}
return references;
}
+ private static boolean usesVariable(AbstractCodeFragment fragment, VariableDeclaration declaration) {
+ List<String> variables = fragment.getVariables();
+ return variables.contains(declaration.getVariableName()) ||
+ (declaration.isAttribute() && variables.contains("this." + declaration.getVariableName()));
+ }
+
public static Set<AbstractCodeMapping> findReferences(VariableDeclaration declaration1, VariableDeclaration declaration2, List<UMLOperationBodyMapper> operationBodyMapperList) {
Set<AbstractCodeMapping> references = new LinkedHashSet<AbstractCodeMapping>();
for(UMLOperationBodyMapper mapper : operationBodyMapperList) {
