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