use of com.intellij.util.NotNullFunction in project intellij-community by JetBrains.
the class FileTypeUsagesCollectorTest method doTest.
private void doTest(@NotNull Collection<FileType> fileTypes) throws CollectUsagesException {
final Set<UsageDescriptor> usages = new FileTypeUsagesCollector().getProjectUsages(getProject());
for (UsageDescriptor usage : usages) {
assertEquals(1, usage.getValue());
}
assertEquals(ContainerUtil.map2Set(fileTypes, (NotNullFunction<FileType, String>) fileType -> fileType.getName()), ContainerUtil.map2Set(usages, (NotNullFunction<UsageDescriptor, String>) usageDescriptor -> usageDescriptor.getKey()));
}
use of com.intellij.util.NotNullFunction in project android by JetBrains.
the class AndroidJavaDebugger method hasExistingDebugSession.
private static boolean hasExistingDebugSession(@NotNull Project project, @NotNull final String debugPort, @NotNull final String runConfigName) {
Collection<RunContentDescriptor> descriptors = null;
Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
Project targetProject = null;
// Scan through open project to find if this port has been opened in any session.
for (Project openProject : openProjects) {
targetProject = openProject;
// First check the titles of the run configurations.
descriptors = ExecutionHelper.findRunningConsoleByTitle(targetProject, new NotNullFunction<String, Boolean>() {
@NotNull
@Override
public Boolean fun(String title) {
return runConfigName.equals(title);
}
});
// If it can't find a matching title, check the debugger sessions.
if (descriptors.isEmpty()) {
DebuggerSession debuggerSession = findJdwpDebuggerSession(targetProject, debugPort);
if (debuggerSession != null) {
XDebugSession session = debuggerSession.getXDebugSession();
if (session != null) {
descriptors = Collections.singletonList(session.getRunContentDescriptor());
} else {
// Detach existing session.
debuggerSession.getProcess().stop(false);
}
}
}
if (!descriptors.isEmpty()) {
break;
}
}
if (descriptors != null && !descriptors.isEmpty()) {
return activateDebugSessionWindow(project, descriptors.iterator().next());
}
return false;
}
use of com.intellij.util.NotNullFunction in project intellij-community by JetBrains.
the class SimpleGraphInfo method build.
public static <CommitId> SimpleGraphInfo<CommitId> build(@NotNull LinearGraph linearGraph, @NotNull GraphLayout oldLayout, @NotNull PermanentCommitsInfo<CommitId> permanentCommitsInfo, int permanentGraphSize, @NotNull Set<Integer> branchNodeIds) {
// todo get first visible row from table somehow
int firstVisibleRow = VISIBLE_RANGE;
int start = Math.max(0, firstVisibleRow - VISIBLE_RANGE);
// no more than 2*1000 commits;
int end = Math.min(linearGraph.nodesCount(), start + 2 * VISIBLE_RANGE);
List<GraphCommit<CommitId>> graphCommits = ContainerUtil.newArrayListWithCapacity(end - start);
List<CommitId> commitsIdMap = ContainerUtil.newArrayListWithCapacity(end - start);
for (int row = start; row < end; row++) {
int nodeId = linearGraph.getNodeId(row);
CommitId commit = permanentCommitsInfo.getCommitId(nodeId);
List<CommitId> parents = ContainerUtil.newSmartList();
parents.addAll(ContainerUtil.mapNotNull(asLiteLinearGraph(linearGraph).getNodes(row, LiteLinearGraph.NodeFilter.DOWN), row1 -> {
if (row1 < start || row1 >= end)
return null;
return permanentCommitsInfo.getCommitId(linearGraph.getNodeId(row1));
}));
graphCommits.add(GraphCommitImpl.createCommit(commit, parents, permanentCommitsInfo.getTimestamp(nodeId)));
commitsIdMap.add(commit);
}
IntTimestampGetter timestampGetter = PermanentCommitsInfoImpl.createTimestampGetter(graphCommits);
NotNullFunction<Integer, CommitId> function = createCommitIdMapFunction(commitsIdMap);
PermanentLinearGraphImpl newLinearGraph = PermanentLinearGraphBuilder.newInstance(graphCommits).build();
int[] layoutIndexes = new int[end - start];
List<Integer> headNodeIndexes = ContainerUtil.newArrayList();
TObjectIntHashMap<CommitId> commitIdToInteger = reverseCommitIdMap(permanentCommitsInfo, permanentGraphSize);
for (int row = start; row < end; row++) {
CommitId commitId = commitsIdMap.get(row - start);
int layoutIndex = oldLayout.getLayoutIndex(commitIdToInteger.get(commitId));
layoutIndexes[row - start] = layoutIndex;
if (asLiteLinearGraph(newLinearGraph).getNodes(row - start, LiteLinearGraph.NodeFilter.UP).isEmpty()) {
headNodeIndexes.add(row - start);
}
}
ContainerUtil.sort(headNodeIndexes, Comparator.comparingInt(o -> layoutIndexes[o]));
int[] starts = new int[headNodeIndexes.size()];
for (int i = 0; i < starts.length; i++) {
starts[i] = layoutIndexes[headNodeIndexes.get(i)];
}
GraphLayoutImpl newLayout = new GraphLayoutImpl(layoutIndexes, headNodeIndexes, starts);
return new SimpleGraphInfo<>(newLinearGraph, newLayout, function, timestampGetter, LinearGraphUtils.convertIdsToNodeIndexes(linearGraph, branchNodeIds));
}
Aggregations