@Nullable
  private static CompiledPattern doCompilePattern(@NotNull Project project, @NotNull MatchOptions options,
                                                  boolean checkForErrors, boolean optimizeScope)
    throws MalformedPatternException, NoMatchFoundException {

    final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(options.getFileType());
    if (profile == null) {
      return null;
    }
    final CompiledPattern result = profile.createCompiledPattern();

    final String[] prefixes = result.getTypedVarPrefixes();
    assert prefixes.length > 0;

    final CompileContext context = new CompileContext(result, options, project);

    try {
      final List<PsiElement> elements = compileByAllPrefixes(project, options, result, context, prefixes, checkForErrors);
      if (elements.isEmpty()) {
        return null;
      }
      final CompiledPattern pattern = context.getPattern();
      collectVariableNodes(pattern, elements, checkForErrors);
      pattern.setNodes(elements);
      if (checkForErrors) {
        profile.checkSearchPattern(pattern);
      }
      if (optimizeScope) {
        optimizeScope(options, checkForErrors, context, result);
      }
      return result;
    }
    finally {
      context.clear();
    }
  }
@Nullable
  private static CompiledPattern doCompilePattern(@NotNull Project project, @NotNull MatchOptions options,
                                                  boolean checkForErrors, boolean optimizeScope)