/*
   * Look for annotations references
   */
  private void matchAnnotations(
      SearchPattern pattern, MatchLocator locator, ClassFile classFile, IBinaryType binaryType)
      throws CoreException {
    // Only process TypeReference patterns
    switch (pattern.kind) {
      case TYPE_REF_PATTERN:
        break;
      case OR_PATTERN:
        SearchPattern[] patterns = ((OrPattern) pattern).patterns;
        for (int i = 0, length = patterns.length; i < length; i++) {
          matchAnnotations(patterns[i], locator, classFile, binaryType);
        }
        // $FALL-THROUGH$ - fall through default to return
      default:
        return;
    }
    TypeReferencePattern typeReferencePattern = (TypeReferencePattern) pattern;

    // Look for references in class annotations
    IBinaryAnnotation[] annotations = binaryType.getAnnotations();
    BinaryType classFileBinaryType = (BinaryType) classFile.getType();
    BinaryTypeBinding binaryTypeBinding = null;
    if (checkAnnotations(typeReferencePattern, annotations, binaryType.getTagBits())) {
      classFileBinaryType =
          new ResolvedBinaryType(
              (JavaElement) classFileBinaryType.getParent(),
              classFileBinaryType.getElementName(),
              classFileBinaryType.getKey());
      TypeReferenceMatch match =
          new TypeReferenceMatch(
              classFileBinaryType,
              SearchMatch.A_ACCURATE,
              -1,
              0,
              false,
              locator.getParticipant(),
              locator.currentPossibleMatch.resource);
      // TODO 3.4 M7 (frederic) - bug 209996: see how create the annotation handle from the binary
      // and put it in the local element
      match.setLocalElement(null);
      locator.report(match);
    }

    // Look for references in methods annotations
    MethodInfo[] methods = (MethodInfo[]) binaryType.getMethods();
    if (methods != null) {
      for (int i = 0, max = methods.length; i < max; i++) {
        MethodInfo method = methods[i];
        if (checkAnnotations(typeReferencePattern, method.getAnnotations(), method.getTagBits())) {
          binaryTypeBinding = locator.cacheBinaryType(classFileBinaryType, binaryType);
          IMethod methodHandle =
              classFileBinaryType.getMethod(
                  new String(
                      method.isConstructor()
                          ? binaryTypeBinding
                              .compoundName[binaryTypeBinding.compoundName.length - 1]
                          : method.getSelector()),
                  CharOperation.toStrings(
                      Signature.getParameterTypes(
                          convertClassFileFormat(method.getMethodDescriptor()))));
          TypeReferenceMatch match =
              new TypeReferenceMatch(
                  methodHandle,
                  SearchMatch.A_ACCURATE,
                  -1,
                  0,
                  false,
                  locator.getParticipant(),
                  locator.currentPossibleMatch.resource);
          // TODO 3.4 M7 (frederic) - bug 209996: see how create the annotation handle from the
          // binary and put it in the local element
          match.setLocalElement(null);
          locator.report(match);
        }
      }
    }

    // Look for references in fields annotations
    FieldInfo[] fields = (FieldInfo[]) binaryType.getFields();
    if (fields != null) {
      for (int i = 0, max = fields.length; i < max; i++) {
        FieldInfo field = fields[i];
        if (checkAnnotations(typeReferencePattern, field.getAnnotations(), field.getTagBits())) {
          IField fieldHandle = classFileBinaryType.getField(new String(field.getName()));
          TypeReferenceMatch match =
              new TypeReferenceMatch(
                  fieldHandle,
                  SearchMatch.A_ACCURATE,
                  -1,
                  0,
                  false,
                  locator.getParticipant(),
                  locator.currentPossibleMatch.resource);
          // TODO 3.4 M7 (frederic) - bug 209996: see how create the annotation handle from the
          // binary and put it in the local element
          match.setLocalElement(null);
          locator.report(match);
        }
      }
    }
  }