Search in sources :

Example 31 with Function

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);
}
Also used : ActionEvent(java.awt.event.ActionEvent) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent) NullableFunction(com.intellij.util.NullableFunction) Function(com.intellij.util.Function) ContextInfo(com.intellij.tasks.context.ContextInfo) WorkingContextManager(com.intellij.tasks.context.WorkingContextManager) LocalTask(com.intellij.tasks.LocalTask) NullableFunction(com.intellij.util.NullableFunction) Project(com.intellij.openapi.project.Project) LoadContextUndoableAction(com.intellij.tasks.context.LoadContextUndoableAction) TaskManager(com.intellij.tasks.TaskManager) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) JBPopupAdapter(com.intellij.openapi.ui.popup.JBPopupAdapter)

Example 32 with Function

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));
}
Also used : IncorrectOperationException(com.intellij.util.IncorrectOperationException) GroovyCodeInsightBundle(org.jetbrains.plugins.groovy.actions.generate.GroovyCodeInsightBundle) GenerateEqualsWizard(com.intellij.codeInsight.generation.ui.GenerateEqualsWizard) PsiMethod(com.intellij.psi.PsiMethod) Collection(java.util.Collection) CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Computable(com.intellij.openapi.util.Computable) ContainerUtil(com.intellij.util.containers.ContainerUtil) Nullable(org.jetbrains.annotations.Nullable) PsiClass(com.intellij.psi.PsiClass) List(java.util.List) com.intellij.codeInsight.generation(com.intellij.codeInsight.generation) Function(com.intellij.util.Function) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Project(com.intellij.openapi.project.Project) PsiField(com.intellij.psi.PsiField) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) GroovyGenerationInfo(org.jetbrains.plugins.groovy.actions.generate.GroovyGenerationInfo) PsiAnonymousClass(com.intellij.psi.PsiAnonymousClass) Project(com.intellij.openapi.project.Project) PsiMethod(com.intellij.psi.PsiMethod) GroovyGenerationInfo(org.jetbrains.plugins.groovy.actions.generate.GroovyGenerationInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with Function

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();
        }
    }));
}
Also used : Function(com.intellij.util.Function) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) WebResource(org.jetbrains.plugins.gradle.model.web.WebConfiguration.WebResource) WarModel(org.jetbrains.plugins.gradle.model.web.WebConfiguration.WarModel) WebConfiguration(org.jetbrains.plugins.gradle.model.web.WebConfiguration) Test(org.junit.Test)

Example 34 with Function

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;
}
Also used : AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) ProjectData(com.intellij.rt.coverage.data.ProjectData) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FilePath(com.intellij.openapi.vcs.FilePath) LineData(com.intellij.rt.coverage.data.LineData) LoadTextUtil(com.intellij.openapi.fileEditor.impl.LoadTextUtil) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) SoftReference(com.intellij.reference.SoftReference) com.intellij.openapi.editor.markup(com.intellij.openapi.editor.markup) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) LineTokenizer(com.intellij.openapi.util.text.LineTokenizer) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs) TextRange(com.intellij.openapi.util.TextRange) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Nullable(org.jetbrains.annotations.Nullable) EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) Function(com.intellij.util.Function) ApplicationManager(com.intellij.openapi.application.ApplicationManager) LocalHistory(com.intellij.history.LocalHistory) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) java.util(java.util) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) LineCoverage(com.intellij.rt.coverage.data.LineCoverage) Computable(com.intellij.openapi.util.Computable) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) CodeInsightBundle(com.intellij.codeInsight.CodeInsightBundle) VcsHistorySession(com.intellij.openapi.vcs.history.VcsHistorySession) ClassData(com.intellij.rt.coverage.data.ClassData) VcsContextFactory(com.intellij.openapi.vcs.actions.VcsContextFactory) FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) VcsUtil(com.intellij.vcsUtil.VcsUtil) TIntIntHashMap(gnu.trove.TIntIntHashMap) Key(com.intellij.openapi.util.Key) FileRevisionTimestampComparator(com.intellij.history.FileRevisionTimestampComparator) VcsHistoryProvider(com.intellij.openapi.vcs.history.VcsHistoryProvider) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Editor(com.intellij.openapi.editor.Editor) Disposable(com.intellij.openapi.Disposable) File(java.io.File) Diff(com.intellij.util.diff.Diff) Alarm(com.intellij.util.Alarm) LineData(com.intellij.rt.coverage.data.LineData) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Document(com.intellij.openapi.editor.Document) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Editor(com.intellij.openapi.editor.Editor) TIntIntHashMap(gnu.trove.TIntIntHashMap)

Example 35 with Function

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"));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Arrays(java.util.Arrays) ArrayUtil(com.intellij.util.ArrayUtil) DataContext(com.intellij.openapi.actionSystem.DataContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiPackageBase(com.intellij.psi.impl.file.PsiPackageBase) RefactoringBundle(com.intellij.refactoring.RefactoringBundle) BaseRefactoringProcessor(com.intellij.refactoring.BaseRefactoringProcessor) ContainerUtil(com.intellij.util.containers.ContainerUtil) ArrayList(java.util.ArrayList) ScrollType(com.intellij.openapi.editor.ScrollType) Comparing(com.intellij.openapi.util.Comparing) PsiDirectoryContainer(com.intellij.psi.PsiDirectoryContainer) CommonBundle(com.intellij.CommonBundle) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Messages(com.intellij.openapi.ui.Messages) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Editor(com.intellij.openapi.editor.Editor) TitledHandler(com.intellij.ide.TitledHandler) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) GeneratedSourcesFilter(com.intellij.openapi.roots.GeneratedSourcesFilter) Function(com.intellij.util.Function) PsiDirectory(com.intellij.psi.PsiDirectory) LangDataKeys(com.intellij.openapi.actionSystem.LangDataKeys) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) PsiDirectory(com.intellij.psi.PsiDirectory) ArrayList(java.util.ArrayList)

Aggregations

Function (com.intellij.util.Function)53 NotNull (org.jetbrains.annotations.NotNull)32 Nullable (org.jetbrains.annotations.Nullable)24 Project (com.intellij.openapi.project.Project)23 Logger (com.intellij.openapi.diagnostic.Logger)19 VirtualFile (com.intellij.openapi.vfs.VirtualFile)15 ContainerUtil (com.intellij.util.containers.ContainerUtil)15 List (java.util.List)15 StringUtil (com.intellij.openapi.util.text.StringUtil)12 Module (com.intellij.openapi.module.Module)11 com.intellij.psi (com.intellij.psi)11 java.util (java.util)10 ArrayList (java.util.ArrayList)10 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)9 ApplicationManager (com.intellij.openapi.application.ApplicationManager)8 PsiElement (com.intellij.psi.PsiElement)7 File (java.io.File)7 Messages (com.intellij.openapi.ui.Messages)6 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)6 IOException (java.io.IOException)6