summaryrefslogtreecommitdiff
path: root/platform/lang-impl/src/com/intellij/internal/DumpDirectoryInfoAction.java
blob: b5d0ae16a0ca965f53f4da23b6a8eb3f3b658241 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright 2000-2012 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.internal;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ContentIterator;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.roots.impl.DirectoryIndex;
import com.intellij.openapi.roots.impl.DirectoryInfo;
import com.intellij.openapi.vfs.VirtualFile;

/**
 * User: anna
 * Date: 2/24/12
 */
public class DumpDirectoryInfoAction extends AnAction {
  public static final Logger LOG = Logger.getInstance("#" + DumpDirectoryInfoAction.class.getName());

  public DumpDirectoryInfoAction() {
    super("Dump Directory Info");
  }

  @Override
  public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final DirectoryIndex index = DirectoryIndex.getInstance(project);
    if (project != null) {
      final VirtualFile root = e.getData(CommonDataKeys.VIRTUAL_FILE);
      ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
        @Override
        public void run() {
          final ContentIterator contentIterator = new ContentIterator() {
            @Override
            public boolean processFile(VirtualFile fileOrDir) {
              LOG.info(fileOrDir.getPath());

              final DirectoryInfo directoryInfo = index.getInfoForDirectory(fileOrDir);
              if (directoryInfo != null) {
                LOG.info(directoryInfo.toString());
              }
              return true;
            }
          };
          if (root != null) {
            ProjectRootManager.getInstance(project).getFileIndex().iterateContentUnderDirectory(root, contentIterator);
          } else {
            ProjectRootManager.getInstance(project).getFileIndex().iterateContent(contentIterator);
          }
        }
      }, "Dumping directory index", true, project);
    }
  }

  @Override
  public void update(AnActionEvent e) {
    e.getPresentation().setEnabled(e.getData(CommonDataKeys.PROJECT) != null);
  }
}