Search in sources :

Example 6 with Function

use of com.intellij.util.Function in project intellij-community by JetBrains.

the class CCLessonMoveHandlerDelegate method doMove.

@Override
public void doMove(final Project project, PsiElement[] elements, @Nullable PsiElement targetContainer, @Nullable MoveCallback callback) {
    if (targetContainer == null || !(targetContainer instanceof PsiDirectory)) {
        return;
    }
    final Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return;
    }
    final PsiDirectory sourceDirectory = (PsiDirectory) elements[0];
    final Lesson sourceLesson = course.getLesson(sourceDirectory.getName());
    final Lesson targetLesson = course.getLesson(((PsiDirectory) targetContainer).getName());
    if (targetLesson == null) {
        Messages.showInfoMessage("Lessons can be moved only to other lessons", "Incorrect Target For Move");
        return;
    }
    final CCMoveStudyItemDialog dialog = new CCMoveStudyItemDialog(project, EduNames.LESSON, targetLesson.getName());
    dialog.show();
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
        return;
    }
    ApplicationManager.getApplication().runWriteAction(new Runnable() {

        @Override
        public void run() {
            try {
                sourceDirectory.getVirtualFile().rename(this, "tmp");
            } catch (IOException e) {
                LOG.error(e);
            }
        }
    });
    final VirtualFile[] lessonDirs = project.getBaseDir().getChildren();
    final Function<VirtualFile, StudyItem> getStudyItem = file -> course.getLesson(file.getName());
    int sourceLessonIndex = sourceLesson.getIndex();
    sourceLesson.setIndex(-1);
    CCUtils.updateHigherElements(lessonDirs, getStudyItem, sourceLessonIndex, EduNames.LESSON, -1);
    final int newItemIndex = targetLesson.getIndex() + dialog.getIndexDelta();
    CCUtils.updateHigherElements(lessonDirs, getStudyItem, newItemIndex - 1, EduNames.LESSON, 1);
    sourceLesson.setIndex(newItemIndex);
    Collections.sort(course.getLessons(), EduUtils.INDEX_COMPARATOR);
    ApplicationManager.getApplication().runWriteAction(new Runnable() {

        @Override
        public void run() {
            try {
                sourceDirectory.getVirtualFile().rename(this, EduNames.LESSON + newItemIndex);
            } catch (IOException e) {
                LOG.error(e);
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MoveHandlerDelegate(com.intellij.refactoring.move.MoveHandlerDelegate) DataContext(com.intellij.openapi.actionSystem.DataContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeView(com.intellij.ide.IdeView) EduUtils(com.jetbrains.edu.learning.core.EduUtils) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Logger(com.intellij.openapi.diagnostic.Logger) MoveCallback(com.intellij.refactoring.move.MoveCallback) CCMoveStudyItemDialog(com.jetbrains.edu.coursecreator.ui.CCMoveStudyItemDialog) PsiReference(com.intellij.psi.PsiReference) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) IOException(java.io.IOException) StudyTaskManager(com.jetbrains.edu.learning.StudyTaskManager) Editor(com.intellij.openapi.editor.Editor) DirectoryChooserUtil(com.intellij.ide.util.DirectoryChooserUtil) Nullable(org.jetbrains.annotations.Nullable) Function(com.intellij.util.Function) EduNames(com.jetbrains.edu.learning.core.EduNames) StudyItem(com.jetbrains.edu.learning.courseFormat.StudyItem) ApplicationManager(com.intellij.openapi.application.ApplicationManager) PsiDirectory(com.intellij.psi.PsiDirectory) LangDataKeys(com.intellij.openapi.actionSystem.LangDataKeys) Collections(java.util.Collections) CCUtils(com.jetbrains.edu.coursecreator.CCUtils) Course(com.jetbrains.edu.learning.courseFormat.Course) IOException(java.io.IOException) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) PsiDirectory(com.intellij.psi.PsiDirectory) Course(com.jetbrains.edu.learning.courseFormat.Course) CCMoveStudyItemDialog(com.jetbrains.edu.coursecreator.ui.CCMoveStudyItemDialog) StudyItem(com.jetbrains.edu.learning.courseFormat.StudyItem)

Example 7 with Function

use of com.intellij.util.Function in project intellij-elixir by KronicDeth.

the class CallDefinitionClause method execute.

/*
     * Private Instance Methods
     */
private boolean execute(@NotNull Call element, @NotNull final ResolveState state) {
    boolean keepProcessing = true;
    if (org.elixir_lang.structure_view.element.CallDefinitionClause.is(element)) {
        keepProcessing = executeOnCallDefinitionClause(element, state);
    } else if (Import.is(element)) {
        final ResolveState importState = state.put(IMPORT_CALL, element);
        try {
            Import.callDefinitionClauseCallWhile(element, new Function<Call, Boolean>() {

                @Override
                public Boolean fun(Call callDefinitionClause) {
                    return executeOnCallDefinitionClause(callDefinitionClause, importState);
                }
            });
        } catch (StackOverflowError stackOverflowError) {
            Logger.error(CallDefinitionClause.class, "StackOverflowError while processing import", element);
        }
    } else if (Module.is(element)) {
        Call[] childCalls = macroChildCalls(element);
        if (childCalls != null) {
            for (Call childCall : childCalls) {
                if (!execute(childCall, state)) {
                    break;
                }
            }
        }
        // Only check MultiResolve.keepProcessing at the end of a Module to all multiple arities
        keepProcessing = keepProcessing();
        if (keepProcessing) {
            // the implicit `import Kernel` and `import Kernel.SpecialForms`
            keepProcessing = implicitImports(element, state);
        }
    }
    return keepProcessing;
}
Also used : Function(com.intellij.util.Function) Call(org.elixir_lang.psi.call.Call) ResolveState(com.intellij.psi.ResolveState)

Example 8 with Function

use of com.intellij.util.Function in project intellij-community by JetBrains.

the class TreeTraverserTest method testTracingBfsLaziness.

public void testTracingBfsLaziness() {
    List<Integer> result = ContainerUtil.newArrayList();
    TreeTraversal.TracingIt<List<Integer>> it = TreeTraversal.TRACING_BFS.traversal((Function<List<Integer>, Iterable<List<Integer>>>) integers -> JBIterable.from(integers).skip(1).transform(WRAP_TO_LIST)).fun(ContainerUtil.newArrayList(1)).typedIterator();
    while (it.advance()) {
        Integer cur = it.current().get(0);
        result.add(cur);
        assertEquals(JBIterable.generate(cur, DIV_2).takeWhile(IS_POSITIVE).toList(), it.backtrace().transform(integers -> integers.get(0)).toList());
        if (cur > 4)
            continue;
        it.current().add(cur * 2);
        it.current().add(cur * 2);
    }
    assertEquals(JBIterable.of(1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8).toList(), result);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) java.util(java.util) TextRange(com.intellij.openapi.util.TextRange) Conditions.not(com.intellij.openapi.util.Conditions.not) Comparing(com.intellij.openapi.util.Comparing) PairFunction(com.intellij.util.PairFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Function(com.intellij.util.Function) Processor(com.intellij.util.Processor) Conditions(com.intellij.openapi.util.Conditions) TestCase(junit.framework.TestCase) NotNull(org.jetbrains.annotations.NotNull) Functions(com.intellij.util.Functions) Split(com.intellij.util.containers.JBIterable.Split) Condition(com.intellij.openapi.util.Condition)

Example 9 with Function

use of com.intellij.util.Function in project intellij-community by JetBrains.

the class IntelliSortChooserPopupAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    VcsLogUi logUI = e.getRequiredData(VcsLogDataKeys.VCS_LOG_UI);
    VcsLogUiProperties properties = e.getRequiredData(VcsLogInternalDataKeys.LOG_UI_PROPERTIES);
    ActionGroup settingsGroup = new DefaultActionGroup(ContainerUtil.map(PermanentGraph.SortType.values(), (Function<PermanentGraph.SortType, AnAction>) sortType -> new SelectIntelliSortTypeAction(logUI, properties, sortType)));
    ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, settingsGroup, e.getDataContext(), JBPopupFactory.ActionSelectionAid.MNEMONICS, true, ToolWindowContentUi.POPUP_PLACE);
    Component component = e.getInputEvent().getComponent();
    if (component instanceof ActionButtonComponent) {
        popup.showUnderneathOf(component);
    } else {
        popup.showInCenterOf(component);
    }
}
Also used : Function(com.intellij.util.Function) MainVcsLogUiProperties(com.intellij.vcs.log.impl.MainVcsLogUiProperties) VcsLogUiProperties(com.intellij.vcs.log.impl.VcsLogUiProperties) ListPopup(com.intellij.openapi.ui.popup.ListPopup) VcsLogUi(com.intellij.vcs.log.VcsLogUi) PermanentGraph(com.intellij.vcs.log.graph.PermanentGraph)

Example 10 with Function

use of com.intellij.util.Function in project intellij-community by JetBrains.

the class IncProjectBuilder method runBuildersForChunk.

private boolean runBuildersForChunk(final CompileContext context, final BuildTargetChunk chunk) throws ProjectBuildException, IOException {
    Set<? extends BuildTarget<?>> targets = chunk.getTargets();
    if (targets.size() > 1) {
        Set<ModuleBuildTarget> moduleTargets = new LinkedHashSet<>();
        for (BuildTarget<?> target : targets) {
            if (target instanceof ModuleBuildTarget) {
                moduleTargets.add((ModuleBuildTarget) target);
            } else {
                String targetsString = StringUtil.join(targets, (Function<BuildTarget<?>, String>) target1 -> StringUtil.decapitalize(target1.getPresentableName()), ", ");
                context.processMessage(new CompilerMessage("", BuildMessage.Kind.ERROR, "Cannot build " + StringUtil.decapitalize(target.getPresentableName()) + " because it is included into a circular dependency (" + targetsString + ")"));
                return false;
            }
        }
        return runModuleLevelBuilders(context, new ModuleChunk(moduleTargets));
    }
    final BuildTarget<?> target = targets.iterator().next();
    if (target instanceof ModuleBuildTarget) {
        return runModuleLevelBuilders(context, new ModuleChunk(Collections.singleton((ModuleBuildTarget) target)));
    }
    // In general the set of files corresponding to changed source file may be different
    // Need this for example, to keep up with case changes in file names  for case-insensitive OSes: 
    // deleting the output before copying is the only way to ensure the case of the output file's name is exactly the same as source file's case
    cleanOldOutputs(context, target);
    final List<TargetBuilder<?, ?>> builders = BuilderRegistry.getInstance().getTargetBuilders();
    final float builderProgressDelta = 1.0f / builders.size();
    for (TargetBuilder<?, ?> builder : builders) {
        buildTarget(target, context, builder);
        updateDoneFraction(context, builderProgressDelta);
    }
    return true;
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) BuildTargetConfiguration(org.jetbrains.jps.incremental.storage.BuildTargetConfiguration) ExternalJavacManager(org.jetbrains.jps.javac.ExternalJavacManager) THashSet(gnu.trove.THashSet) CanceledStatus(org.jetbrains.jps.api.CanceledStatus) CompilationRound(org.jetbrains.jps.incremental.fs.CompilationRound) THashMap(gnu.trove.THashMap) FilesDelta(org.jetbrains.jps.incremental.fs.FilesDelta) org.jetbrains.jps.incremental.messages(org.jetbrains.jps.incremental.messages) Predicate(com.intellij.util.containers.Predicate) TimingLog(org.jetbrains.jps.TimingLog) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) SmartList(com.intellij.util.SmartList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) BuildRunner(org.jetbrains.jps.cmdline.BuildRunner) MultiMap(com.intellij.util.containers.MultiMap) Method(java.lang.reflect.Method) BuildFSState(org.jetbrains.jps.incremental.fs.BuildFSState) ModuleChunk(org.jetbrains.jps.ModuleChunk) java.util.concurrent(java.util.concurrent) PersistentEnumerator(com.intellij.util.io.PersistentEnumerator) JpsModule(org.jetbrains.jps.model.module.JpsModule) DirtyFilesHolderBase(org.jetbrains.jps.builders.impl.DirtyFilesHolderBase) InvocationTargetException(java.lang.reflect.InvocationTargetException) Nullable(org.jetbrains.annotations.Nullable) Function(com.intellij.util.Function) NotNull(org.jetbrains.annotations.NotNull) ModuleExcludeIndex(org.jetbrains.jps.indices.ModuleExcludeIndex) OutputToTargetRegistry(org.jetbrains.jps.incremental.storage.OutputToTargetRegistry) java.util(java.util) Proxy(java.lang.reflect.Proxy) SharedThreadPool(org.jetbrains.jps.service.SharedThreadPool) SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) ContainerUtil(com.intellij.util.containers.ContainerUtil) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) AtomicReference(java.util.concurrent.atomic.AtomicReference) GlobalOptions(org.jetbrains.jps.api.GlobalOptions) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService) BuildTargetChunk(org.jetbrains.jps.builders.impl.BuildTargetChunk) BoundedTaskExecutor(com.intellij.util.concurrency.BoundedTaskExecutor) OneToManyPathsMapping(org.jetbrains.jps.incremental.storage.OneToManyPathsMapping) StringUtil(com.intellij.openapi.util.text.StringUtil) IOException(java.io.IOException) File(java.io.File) JavaBuilderUtil(org.jetbrains.jps.builders.java.JavaBuilderUtil) org.jetbrains.jps.builders(org.jetbrains.jps.builders) AtomicLong(java.util.concurrent.atomic.AtomicLong) JavacMain(org.jetbrains.jps.javac.JavacMain) Callbacks(org.jetbrains.jps.builders.java.dependencyView.Callbacks) InvocationHandler(java.lang.reflect.InvocationHandler) MappingFailedException(com.intellij.util.io.MappingFailedException) BuildOutputConsumerImpl(org.jetbrains.jps.builders.impl.BuildOutputConsumerImpl) JpsPathUtil(org.jetbrains.jps.util.JpsPathUtil) ModuleChunk(org.jetbrains.jps.ModuleChunk)

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