Search in sources :

Example 51 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class VfsRootAccess method allowedRoots.

// null means we were unable to get roots, so do not check access
private static Set<String> allowedRoots() {
    if (insideGettingRoots)
        return null;
    Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
    if (openProjects.length == 0)
        return null;
    final Set<String> allowed = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY);
    allowed.add(FileUtil.toSystemIndependentName(PathManager.getHomePath()));
    // In plugin development environment PathManager.getHomePath() returns path like "~/.IntelliJIdea/system/plugins-sandbox/test" when running tests
    // The following is to avoid errors in tests like "File accessed outside allowed roots: file://C:/Program Files/idea/lib/idea.jar"
    final String homePath2 = PathManager.getHomePathFor(Application.class);
    if (homePath2 != null) {
        allowed.add(FileUtil.toSystemIndependentName(homePath2));
    }
    try {
        URL outUrl = Application.class.getResource("/");
        if (outUrl != null) {
            String output = new File(outUrl.toURI()).getParentFile().getParentFile().getPath();
            allowed.add(FileUtil.toSystemIndependentName(output));
        }
    } catch (URISyntaxException ignored) {
    }
    String javaHome = SystemProperties.getJavaHome();
    allowed.add(FileUtil.toSystemIndependentName(javaHome));
    if (SystemInfo.isMac && SystemInfo.isAppleJvm) {
        // Apple SDK has jars in the folder _next_ to the java.home
        allowed.add(FileUtil.toSystemIndependentName(new File(new File(javaHome).getParent(), "Classes").getPath()));
    }
    allowed.add(FileUtil.toSystemIndependentName(new File(FileUtil.getTempDirectory()).getParent()));
    allowed.add(FileUtil.toSystemIndependentName(System.getProperty("java.io.tmpdir")));
    allowed.add(FileUtil.toSystemIndependentName(SystemProperties.getUserHome()));
    for (final Project project : openProjects) {
        if (!project.isInitialized()) {
            // all is allowed
            return null;
        }
        for (VirtualFile root : ProjectRootManager.getInstance(project).getContentRoots()) {
            allowed.add(root.getPath());
        }
        for (VirtualFile root : getAllRoots(project)) {
            allowed.add(StringUtil.trimEnd(root.getPath(), JarFileSystem.JAR_SEPARATOR));
        }
        String location = project.getBasePath();
        assert location != null : project;
        allowed.add(FileUtil.toSystemIndependentName(location));
    }
    allowed.addAll(ourAdditionalRoots);
    return allowed;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) URISyntaxException(java.net.URISyntaxException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) THashSet(gnu.trove.THashSet) URL(java.net.URL)

Example 52 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class EncodingManagerImpl method getFavorites.

@Override
@NotNull
public Collection<Charset> getFavorites() {
    Collection<Charset> result = new THashSet<>();
    Project[] projects = ProjectManager.getInstance().getOpenProjects();
    for (Project project : projects) {
        result.addAll(EncodingProjectManager.getInstance(project).getFavorites());
    }
    result.addAll(EncodingProjectManagerImpl.widelyKnownCharsets());
    return result;
}
Also used : Project(com.intellij.openapi.project.Project) Charset(java.nio.charset.Charset) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 53 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class PathInternerTest method main.

@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
public static void main(String[] args) throws InterruptedException, IOException {
    final HashSet<String> hs = new HashSet<>();
    FileUtil.processFilesRecursively(new File(PathManager.getHomePath()), file -> {
        hs.add(file.getPath());
        return true;
    });
    THashSet<String> thm = new THashSet<>();
    PathInterner.PathEnumerator interner = new PathInterner.PathEnumerator();
    for (String s : hs) {
        thm.add(s);
        if (!thm.contains(s)) {
            throw new AssertionError();
        }
        interner.addPath(s);
        if (!interner.containsPath(s)) {
            throw new AssertionError(s);
        }
    }
    System.out.println("Map collected, press when ready");
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    reader.readLine();
    System.out.println("Filling THashSet...");
    long start = System.currentTimeMillis();
    checkTrove(hs, thm);
    System.out.println("done " + (System.currentTimeMillis() - start));
    System.out.println("Filling PathInterner...");
    start = System.currentTimeMillis();
    checkInterner(hs, interner);
    System.out.println("done " + (System.currentTimeMillis() - start));
    hs.clear();
    System.out.println("press when ready");
    reader.readLine();
    System.out.println("interner.hashCode() = " + interner.hashCode());
    System.out.println("thm.hashCode() = " + thm.hashCode());
}
Also used : InputStreamReader(java.io.InputStreamReader) THashSet(gnu.trove.THashSet) BufferedReader(java.io.BufferedReader) File(java.io.File) THashSet(gnu.trove.THashSet)

Example 54 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class KeymapGenerator method main.

@Override
public void main(String[] args) {
    ActionManager actionManager = ActionManager.getInstance();
    StringBuilder xml = new StringBuilder();
    xml.append("<Keymaps>\n");
    for (Keymap keymap : KeymapManagerEx.getInstanceEx().getAllKeymaps()) {
        xml.append("  <Keymap name=\"").append(keymap.getPresentableName()).append("\">\n");
        for (String id : keymap.getActionIdList()) {
            String shortcuts = KeymapUtil.getShortcutsText(keymap.getShortcuts(id));
            if (!StringUtil.isEmpty(shortcuts)) {
                AnAction action = actionManager.getAction(id);
                xml.append("    <Action id=\"").append(id).append("\">\n");
                Set<String> addedShortcuts = new THashSet<>();
                for (Shortcut shortcut : keymap.getShortcuts(id)) {
                    // Different shortcuts may have equal display strings (e.g. shift+minus and shift+subtract)
                    // We don't want them do be duplicated for users
                    String shortcutText = KeymapUtil.getShortcutText(shortcut);
                    if (addedShortcuts.add(shortcutText)) {
                        xml.append("      <Shortcut>").append(shortcutText).append("</Shortcut>\n");
                    }
                }
                if (action != null) {
                    String text = action.getTemplatePresentation().getText();
                    if (text != null) {
                        xml.append("      <Text>").append(StringUtil.escapeXml(text)).append("</Text>\n");
                    }
                }
                xml.append("    </Action>\n");
            }
        }
        xml.append("  </Keymap>\n");
    }
    xml.append("</Keymaps>");
    final String path = args.length == 2 ? args[1] : PathManager.getHomePath() + File.separator + "AllKeymaps.xml";
    File out = new File(path);
    try {
        FileUtil.writeToFile(out, xml.toString());
        System.out.println("Saved to: " + out.getAbsolutePath());
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
    System.exit(0);
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) Shortcut(com.intellij.openapi.actionSystem.Shortcut) IOException(java.io.IOException) AnAction(com.intellij.openapi.actionSystem.AnAction) File(java.io.File) Keymap(com.intellij.openapi.keymap.Keymap) THashSet(gnu.trove.THashSet)

Example 55 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class ActionsTreeUtil method createOtherGroup.

@NotNull
private static Group createOtherGroup(@Nullable Condition<AnAction> filtered, Group addedActions, @Nullable Keymap keymap) {
    addedActions.initIds();
    Set<String> result = new THashSet<>();
    ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
    if (keymap != null) {
        for (String id : keymap.getActionIdList()) {
            if (id.startsWith(EDITOR_PREFIX) && actionManager.getActionOrStub("$" + id.substring(6)) != null) {
                continue;
            }
            if (!id.startsWith(QuickList.QUICK_LIST_PREFIX) && !addedActions.containsId(id)) {
                result.add(id);
            }
        }
    }
    // add all registered actions
    final KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
    String[] registeredActionIds = actionManager.getActionIds("");
    for (String id : registeredActionIds) {
        final AnAction actionOrStub = actionManager.getActionOrStub(id);
        if (actionOrStub instanceof ActionGroup && !((ActionGroup) actionOrStub).canBePerformed(DataManager.getInstance().getDataContext())) {
            continue;
        }
        if (id.startsWith(QuickList.QUICK_LIST_PREFIX) || addedActions.containsId(id) || result.contains(id) || keymapManager.getBoundActions().contains(id)) {
            continue;
        }
        result.add(id);
    }
    filterOtherActionsGroup(result);
    Group group = new Group(KeyMapBundle.message("other.group.title"), AllIcons.Nodes.KeymapOther);
    AnAction[] groupedActions = getActions("Other.KeymapGroup");
    for (AnAction action : groupedActions) {
        addAction(group, action, filtered);
    }
    result.removeAll(group.initIds());
    for (String id : ContainerUtil.sorted(result, (id1, id2) -> getTextToCompare(id1).compareToIgnoreCase(getTextToCompare(id2)))) {
        if (filtered == null || filtered.value(actionManager.getActionOrStub(id)))
            group.addActionId(id);
    }
    return group;
}
Also used : KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) KeymapManagerEx(com.intellij.openapi.keymap.ex.KeymapManagerEx) THashSet(gnu.trove.THashSet) ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

THashSet (gnu.trove.THashSet)239 NotNull (org.jetbrains.annotations.NotNull)65 VirtualFile (com.intellij.openapi.vfs.VirtualFile)62 Project (com.intellij.openapi.project.Project)35 File (java.io.File)35 THashMap (gnu.trove.THashMap)31 Nullable (org.jetbrains.annotations.Nullable)31 Module (com.intellij.openapi.module.Module)29 IOException (java.io.IOException)24 PsiElement (com.intellij.psi.PsiElement)21 PsiFile (com.intellij.psi.PsiFile)18 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)16 java.util (java.util)16 Element (org.jdom.Element)14 Pair (com.intellij.openapi.util.Pair)13 Logger (com.intellij.openapi.diagnostic.Logger)12 ContainerUtil (com.intellij.util.containers.ContainerUtil)12 Document (com.intellij.openapi.editor.Document)11 Library (com.intellij.openapi.roots.libraries.Library)11 StringUtil (com.intellij.openapi.util.text.StringUtil)10