/*
 * Copyright 2000-2015 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.psi.stubsHierarchy.impl.test;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.psi.stubsHierarchy.ClassHierarchy;
import com.intellij.psi.stubsHierarchy.HierarchyService;

public class BuildStubsHierarchyAction extends InheritanceAction {
  private static final Logger LOG = Logger.getInstance("#com.intellij.psi.stubsHierarchy.impl.test.BuildStubsHierarchyAction");
  @Override
  public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null) return;

    HierarchyService service = HierarchyService.getService(project);
    service.clearHierarchy();

    long start = System.currentTimeMillis();
    ThrowableComputable<ClassHierarchy, RuntimeException> computable = () -> ReadAction.compute(service::getHierarchy);
    ClassHierarchy hierarchy = ProgressManager.getInstance().runProcessWithProgressSynchronously(computable, "Building Hierarchy", false, project);
    long elapsed = System.currentTimeMillis() - start;
    LOG.info("Building stub hierarchy took " + elapsed + " ms" +
             "; classes=" + hierarchy.getAllClasses().size() +
             "; covered=" + hierarchy.getCoveredClasses().size());
  }
}

@@ -1122,16 +1122,97 @@
 Service;
+%0Aimport com.intellij.psi.stubsHierarchy.SmartClassAnchor;%0A%0Aimport java.util.List;
 %0A%0Apublic
@@ -2026,16 +2026,94 @@
  start;%0A
+    List%3C? extends SmartClassAnchor%3E covered = hierarchy.getCoveredClasses();%0A
     LOG.
@@ -2264,42 +2264,115 @@
 %22 + 
-hierarchy.getCoveredClasses().size
+covered.size() +%0A             %22; ambiguous=%22 + covered.stream().filter(hierarchy::hasAmbiguousSupers).count
 ());

build stub hierarchy: print the number of classes with ambiguous supers