private void searchForDeclarations(
     SearchEngine engine,
     DartIdentifier identifier,
     SearchScope scope,
     SearchFilter filter,
     SearchListener listener,
     IProgressMonitor monitor)
     throws CoreException, SearchException {
   // Index lacks relationships required to do direct search, so first get all classes.
   String name = identifier.getName();
   boolean isProperty = identifier.getParent() instanceof DartPropertyAccess;
   SearchPattern pattern = SearchPatternFactory.createWildcardPattern("*", false);
   List<SearchMatch> allMatches = engine.searchTypeDeclarations(scope, pattern, filter, monitor);
   // Then see if the type or a child of the type matches the given name.
   // We are NOT looking for local function or local variable declarations.
   for (SearchMatch typeMatch : allMatches) {
     DartElement type = typeMatch.getElement();
     if (!isProperty) {
       if (type.getElementName().equals(name)) {
         addResult(name, type, listener);
       }
     }
     for (DartElement child : type.getChildren()) {
       if (child.getElementName().equals(name)) {
         addResult(name, child, listener);
       }
     }
   }
 }
 private void searchForReferences(
     SearchEngine engine,
     DartElement element,
     SearchScope scope,
     SearchFilter filter,
     SearchListener collector,
     IProgressMonitor monitor)
     throws SearchException {
   switch (element.getElementType()) {
     case DartElement.METHOD:
       engine.searchReferences((Method) element, scope, filter, collector, monitor);
       break;
     case DartElement.CLASS_TYPE_ALIAS:
       engine.searchReferences((DartClassTypeAlias) element, scope, filter, collector, monitor);
       break;
     case DartElement.FUNCTION_TYPE_ALIAS:
       engine.searchReferences((DartFunctionTypeAlias) element, scope, filter, collector, monitor);
       break;
     case DartElement.FIELD:
       engine.searchReferences((Field) element, scope, filter, collector, monitor);
       break;
     case DartElement.FUNCTION:
       engine.searchReferences((DartFunction) element, scope, filter, collector, monitor);
       break;
     case DartElement.TYPE:
       engine.searchReferences((Type) element, scope, filter, collector, monitor);
       break;
     case DartElement.IMPORT:
       engine.searchReferences((DartImport) element, scope, filter, collector, monitor);
       break;
     case DartElement.VARIABLE:
       engine.searchReferences(
           (DartVariableDeclaration) element, scope, filter, collector, monitor);
       break;
     default:
       throw new UnsupportedOperationException(
           "unsupported search type: " + element.getClass()); // $NON-NLS-1$
   }
 }