use of com.intellij.util.Function in project intellij-community by JetBrains.
the class LoadContextAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = getProject(e);
assert project != null;
DefaultActionGroup group = new DefaultActionGroup();
final WorkingContextManager manager = WorkingContextManager.getInstance(project);
List<ContextInfo> history = manager.getContextHistory();
List<ContextHolder> infos = new ArrayList<>(ContainerUtil.map2List(history, (Function<ContextInfo, ContextHolder>) info -> new ContextHolder() {
@Override
void load(final boolean clear) {
LoadContextUndoableAction undoableAction = LoadContextUndoableAction.createAction(manager, clear, info.name);
UndoableCommand.execute(project, undoableAction, "Load context " + info.comment, "Context");
}
@Override
void remove() {
manager.removeContext(info.name);
}
@Override
Date getDate() {
return new Date(info.date);
}
@Override
String getComment() {
return info.comment;
}
@Override
Icon getIcon() {
return TasksIcons.SavedContext;
}
}));
final TaskManager taskManager = TaskManager.getManager(project);
List<LocalTask> tasks = taskManager.getLocalTasks();
infos.addAll(ContainerUtil.mapNotNull(tasks, (NullableFunction<LocalTask, ContextHolder>) task -> {
if (task.isActive()) {
return null;
}
return new ContextHolder() {
@Override
void load(boolean clear) {
LoadContextUndoableAction undoableAction = LoadContextUndoableAction.createAction(manager, clear, task);
UndoableCommand.execute(project, undoableAction, "Load context " + TaskUtil.getTrimmedSummary(task), "Context");
}
@Override
void remove() {
SwitchTaskAction.removeTask(project, task, taskManager);
}
@Override
Date getDate() {
return task.getUpdated();
}
@Override
String getComment() {
return TaskUtil.getTrimmedSummary(task);
}
@Override
Icon getIcon() {
return task.getIcon();
}
};
}));
Collections.sort(infos, (o1, o2) -> o2.getDate().compareTo(o1.getDate()));
final Ref<Boolean> shiftPressed = Ref.create(false);
boolean today = true;
Calendar now = Calendar.getInstance();
for (int i = 0, historySize = Math.min(MAX_ROW_COUNT, infos.size()); i < historySize; i++) {
final ContextHolder info = infos.get(i);
Calendar calendar = Calendar.getInstance();
calendar.setTime(info.getDate());
if (today && (calendar.get(Calendar.YEAR) != now.get(Calendar.YEAR) || calendar.get(Calendar.DAY_OF_YEAR) != now.get(Calendar.DAY_OF_YEAR))) {
group.addSeparator();
today = false;
}
group.add(createItem(info, shiftPressed));
}
final ListPopupImpl popup = (ListPopupImpl) JBPopupFactory.getInstance().createActionGroupPopup("Load Context", group, e.getDataContext(), false, null, MAX_ROW_COUNT);
popup.setAdText("Press SHIFT to merge with current context");
popup.registerAction("shiftPressed", KeyStroke.getKeyStroke("shift pressed SHIFT"), new AbstractAction() {
public void actionPerformed(ActionEvent e) {
shiftPressed.set(true);
popup.setCaption("Merge with Current Context");
}
});
popup.registerAction("shiftReleased", KeyStroke.getKeyStroke("released SHIFT"), new AbstractAction() {
public void actionPerformed(ActionEvent e) {
shiftPressed.set(false);
popup.setCaption("Load Context");
}
});
popup.registerAction("invoke", KeyStroke.getKeyStroke("shift ENTER"), new AbstractAction() {
public void actionPerformed(ActionEvent e) {
popup.handleSelect(true);
}
});
popup.addPopupListener(new JBPopupAdapter() {
@Override
public void onClosed(LightweightWindowEvent event) {
}
});
popup.showCenteredInCurrentWindow(project);
}
use of com.intellij.util.Function in project intellij-community by JetBrains.
the class GroovyGenerateEqualsHandler method generateMemberPrototypes.
@Override
@NotNull
protected List<? extends GenerationInfo> generateMemberPrototypes(PsiClass aClass, ClassMember[] originalMembers) throws IncorrectOperationException {
Project project = aClass.getProject();
final boolean useInstanceofToCheckParameterType = CodeInsightSettings.getInstance().USE_INSTANCEOF_ON_EQUALS_PARAMETER;
GroovyGenerateEqualsHelper helper = new GroovyGenerateEqualsHelper(project, aClass, myEqualsFields, myHashCodeFields, myNonNullFields, useInstanceofToCheckParameterType);
Collection<PsiMethod> methods = helper.generateMembers();
return ContainerUtil.map2List(methods, (Function<PsiMethod, PsiGenerationInfo<PsiMethod>>) s -> new GroovyGenerationInfo<>(s));
}
use of com.intellij.util.Function in project intellij-community by JetBrains.
the class WebConfigurationBuilderImplTest method testDefaultWarModel.
@Test
public void testDefaultWarModel() throws Exception {
DomainObjectSet<? extends IdeaModule> ideaModules = allModels.getIdeaProject().getModules();
List<WebConfiguration> ideaModule = ContainerUtil.mapNotNull(ideaModules, new Function<IdeaModule, WebConfiguration>() {
@Override
public WebConfiguration fun(IdeaModule module) {
return allModels.getExtraProject(module, WebConfiguration.class);
}
});
assertEquals(1, ideaModule.size());
WebConfiguration webConfiguration = ideaModule.get(0);
assertEquals(1, webConfiguration.getWarModels().size());
final WarModel warModel = webConfiguration.getWarModels().iterator().next();
assertEquals("src/main/webapp", warModel.getWebAppDirName());
assertArrayEquals(new String[] { "MANIFEST.MF", "additionalWebInf", "rootContent" }, ContainerUtil.map2Array(warModel.getWebResources(), new Function<WebResource, Object>() {
@Override
public String fun(WebResource resource) {
return resource.getFile().getName();
}
}));
}
use of com.intellij.util.Function in project intellij-community by JetBrains.
the class SrcFileAnnotator method createRangeHighlighter.
private RangeHighlighter createRangeHighlighter(final long date, final MarkupModel markupModel, final boolean coverageByTestApplicable, final TreeMap<Integer, LineData> executableLines, @Nullable final String className, final int line, final int lineNumberInCurrent, @NotNull final CoverageSuitesBundle coverageSuite, Object[] lines, @NotNull MyEditorBean editorBean) {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
final TextAttributes attributes = scheme.getAttributes(CoverageLineMarkerRenderer.getAttributesKey(line, executableLines));
TextAttributes textAttributes = null;
if (attributes.getBackgroundColor() != null) {
textAttributes = attributes;
}
Document document = editorBean.getDocument();
Editor editor = editorBean.getEditor();
final int startOffset = document.getLineStartOffset(lineNumberInCurrent);
final int endOffset = document.getLineEndOffset(lineNumberInCurrent);
final RangeHighlighter highlighter = markupModel.addRangeHighlighter(startOffset, endOffset, HighlighterLayer.SELECTION - 1, textAttributes, HighlighterTargetArea.LINES_IN_RANGE);
final Function<Integer, Integer> newToOldConverter = newLine -> {
if (editor == null)
return -1;
final TIntIntHashMap oldLineMapping = getNewToOldLineMapping(date, editorBean);
return oldLineMapping != null ? oldLineMapping.get(newLine.intValue()) : newLine.intValue();
};
final Function<Integer, Integer> oldToNewConverter = newLine -> {
if (editor == null)
return -1;
final TIntIntHashMap newLineMapping = getOldToNewLineMapping(date, editorBean);
return newLineMapping != null ? newLineMapping.get(newLine.intValue()) : newLine.intValue();
};
final LineMarkerRendererWithErrorStripe markerRenderer = coverageSuite.getLineMarkerRenderer(line, className, executableLines, coverageByTestApplicable, coverageSuite, newToOldConverter, oldToNewConverter, CoverageDataManager.getInstance(myProject).isSubCoverageActive());
highlighter.setLineMarkerRenderer(markerRenderer);
final LineData lineData = className != null ? (LineData) lines[line + 1] : null;
if (lineData != null && lineData.getStatus() == LineCoverage.NONE) {
highlighter.setErrorStripeMarkColor(markerRenderer.getErrorStripeColor(editor));
highlighter.setThinErrorStripeMark(true);
highlighter.setGreedyToLeft(true);
highlighter.setGreedyToRight(true);
}
return highlighter;
}
use of com.intellij.util.Function in project intellij-community by JetBrains.
the class DirectoryAsPackageRenameHandlerBase method buildMultipleDirectoriesInPackageMessage.
public static void buildMultipleDirectoriesInPackageMessage(StringBuffer message, String packageQname, PsiDirectory[] directories) {
message.append(RefactoringBundle.message("multiple.directories.correspond.to.package"));
message.append(packageQname);
message.append(":\n\n");
final List<PsiDirectory> generated = new ArrayList<>();
final List<PsiDirectory> source = new ArrayList<>();
for (PsiDirectory directory : directories) {
final VirtualFile virtualFile = directory.getVirtualFile();
if (GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(virtualFile, directory.getProject())) {
generated.add(directory);
} else {
source.add(directory);
}
}
final Function<PsiDirectory, String> directoryPresentation = directory -> directory.getVirtualFile().getPresentableUrl();
message.append(StringUtil.join(source, directoryPresentation, "\n"));
if (!generated.isEmpty()) {
message.append("\n\nalso generated:\n");
message.append(StringUtil.join(generated, directoryPresentation, "\n"));
}
}
Aggregations