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;
}
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;
}
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());
}
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);
}
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;
}
Aggregations