Module moduleNode = defUnit.getModuleNode();
if(moduleNode == null) {
continue; // consider this case more
}
ISourceModule defUnitSrcModule = findSourceModule(moduleNode, searchProj);
ArrayList<Integer> nodeTreePath = DeeSearchEngineTestUtils.getNodeTreePath(defUnit);
Pair<ISourceModule, ?> key = Pair.create(defUnitSrcModule, nodeTreePath);
if(defUnitToReferencesMap.get(key) == null) {
defUnitToReferencesMap.put(key, new HashSet<Reference>());
}
defUnitToReferencesMap.get(key).add(reference);
}
}
}
}.visitElementsAndNodes(getSrcFolder(searchProj, "srcA"), 10);
for (Pair<ISourceModule, ?> key : defUnitToReferencesMap.keySet()) {
ISourceModule sourceModule = key.getFirst();
ArrayList<Integer> nodeTreePath = blindCast(key.getSecond());
Path filePath = DLTKUtils.getFilePath(sourceModule);
ParsedModule parseModule = DToolClient.getDefaultModuleCache().getParsedModuleOrNull(filePath);
Module deeModule = parseModule == null ? null : parseModule.module;
ASTNode node = DeeSearchEngineTestUtils.getNodeFromPath(deeModule, nodeTreePath);
final DefUnit defUnit = (DefUnit) node;
final HashSet<Reference> expectedReferences = defUnitToReferencesMap.get(key);
IMember element = DeeModelEngine.findCorrespondingModelElement(defUnit, sourceModule);
// if(element == null) {
// // TODO: consider this case
// continue;
// }
final String keyIdentifier = DeeSearchEngineTestUtils.getModelElementFQName(element);
doTestSearchForElementReferences(element, new MatchChecker(){
@Override
public void checkMatch(SearchMatch match) throws CoreException {
IMember refElement = assertInstance(match.getElement(), IMember.class);
ISourceModule module = getSourceModule(refElement);
checkKey(module, match.getOffset(), keyIdentifier);
checkReferences(expectedReferences, match);
}
private void checkReferences(final HashSet<Reference> expectedReferences, SearchMatch referenceMatch) {
// Search for referenceMatch in expectedReferences, then remove it
for (Reference pair : expectedReferences) {
Reference reference = pair;
String refModuleName = reference.getModuleNode().getModuleFullyQualifiedName();
IModelElement modelElement = downCast(referenceMatch.getElement());
ISourceModule matchSrcModule = DeeSearchEngineTestUtils.getSourceModule(modelElement);
String matchModuleName = DeeSearchEngineTestUtils.getSourceModuleFQName(matchSrcModule);
if(areEqual(refModuleName, matchModuleName) &&
reference.getOffset() == referenceMatch.getOffset() &&