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 HgVFSListener method performAdding.
@Override
protected void performAdding(final Collection<VirtualFile> addedFiles, final Map<VirtualFile, VirtualFile> copyFromMap) {
(new Task.ConditionalModal(myProject, HgVcsMessages.message("hg4idea.add.progress"), false, VcsConfiguration.getInstance(myProject).getAddRemoveOption()) {
@Override
public void run(@NotNull ProgressIndicator aProgressIndicator) {
final ArrayList<VirtualFile> adds = new ArrayList<>();
// from -> to
final HashMap<VirtualFile, VirtualFile> copies = new HashMap<>();
//delete unversioned and ignored files from copy source
LOG.assertTrue(myProject != null, "Project is null");
Collection<VirtualFile> unversionedAndIgnoredFiles = new ArrayList<>();
final Map<VirtualFile, Collection<VirtualFile>> sortedSourceFilesByRepos = HgUtil.sortByHgRoots(myProject, copyFromMap.values());
HgStatusCommand statusCommand = new HgStatusCommand.Builder(false).unknown(true).ignored(true).build(myProject);
for (Map.Entry<VirtualFile, Collection<VirtualFile>> entry : sortedSourceFilesByRepos.entrySet()) {
Set<HgChange> changes = statusCommand.executeInCurrentThread(entry.getKey(), ContainerUtil.map(entry.getValue(), new Function<VirtualFile, FilePath>() {
@Override
public FilePath fun(VirtualFile virtualFile) {
return VcsUtil.getFilePath(virtualFile);
}
}));
for (HgChange change : changes) {
unversionedAndIgnoredFiles.add(change.afterFile().toFilePath().getVirtualFile());
}
}
copyFromMap.values().removeAll(unversionedAndIgnoredFiles);
// separate adds from copies
for (VirtualFile file : addedFiles) {
if (file.isDirectory()) {
continue;
}
final VirtualFile copyFrom = copyFromMap.get(file);
if (copyFrom != null) {
copies.put(copyFrom, file);
} else {
adds.add(file);
}
}
// add for all files at once
if (!adds.isEmpty()) {
new HgAddCommand(myProject).executeInCurrentThread(adds);
}
// copy needs to be run for each file separately
if (!copies.isEmpty()) {
for (Map.Entry<VirtualFile, VirtualFile> copy : copies.entrySet()) {
new HgCopyCommand(myProject).executeInCurrentThread(copy.getKey(), copy.getValue());
}
}
for (VirtualFile file : addedFiles) {
dirtyScopeManager.fileDirty(file);
}
}
}).queue();
}
use of com.intellij.util.Function in project intellij-community by JetBrains.
the class YouTrackCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull final CompletionParameters parameters, @NotNull CompletionResultSet result) {
if (LOG.isDebugEnabled()) {
LOG.debug(DebugUtil.psiToString(parameters.getOriginalFile(), true));
}
super.fillCompletionVariants(parameters, result);
PsiFile file = parameters.getOriginalFile();
final YouTrackIntellisense intellisense = file.getUserData(YouTrackIntellisense.INTELLISENSE_KEY);
if (intellisense == null) {
return;
}
final Application application = ApplicationManager.getApplication();
Future<List<CompletionItem>> future = application.executeOnPooledThread(() -> intellisense.fetchCompletion(parameters.getOriginalFile().getText(), parameters.getOffset()));
try {
final List<CompletionItem> suggestions = future.get(TIMEOUT, TimeUnit.MILLISECONDS);
// actually backed by original CompletionResultSet
result = result.withPrefixMatcher(extractPrefix(parameters)).caseInsensitive();
result.addAllElements(ContainerUtil.map(suggestions, (Function<CompletionItem, LookupElement>) item -> LookupElementBuilder.create(item, item.getOption()).withTypeText(item.getDescription(), true).withInsertHandler(INSERT_HANDLER).withBoldness(item.getStyleClass().equals("keyword"))));
} catch (Exception ignored) {
//noinspection InstanceofCatchParameter
if (ignored instanceof TimeoutException) {
LOG.debug(String.format("YouTrack request took more than %d ms to complete", TIMEOUT));
}
LOG.debug(ignored);
}
}
use of com.intellij.util.Function in project intellij-community by JetBrains.
the class TestsPattern method createSearchingForTestsTask.
@Override
public SearchForTestsTask createSearchingForTestsTask() {
final JUnitConfiguration.Data data = getConfiguration().getPersistentData();
final Project project = getConfiguration().getProject();
final Set<String> classNames = new LinkedHashSet<>();
for (String className : data.getPatterns()) {
final PsiClass psiClass = getTestClass(project, className);
if (psiClass != null && JUnitUtil.isTestClass(psiClass)) {
classNames.add(className);
}
}
if (classNames.size() == data.getPatterns().size()) {
return new SearchForTestsTask(project, myServerSocket) {
@Override
protected void search() throws ExecutionException {
final Function<String, String> nameFunction = StringUtil.isEmpty(data.METHOD_NAME) ? FunctionUtil.<String>id() : (Function<String, String>) className -> className;
addClassesListToJavaParameters(classNames, nameFunction, "", false, getJavaParameters());
}
@Override
protected void onFound() {
}
};
}
return super.createSearchingForTestsTask();
}
use of com.intellij.util.Function in project kotlin by JetBrains.
the class ExpressionCodegen method generateBlock.
private StackValueWithLeaveTask generateBlock(@NotNull List<KtExpression> statements, boolean isStatement, @Nullable Label labelBeforeLastExpression, @Nullable final Label labelBlockEnd) {
final Label blockEnd = labelBlockEnd != null ? labelBlockEnd : new Label();
final List<Function<StackValue, Void>> leaveTasks = Lists.newArrayList();
@Nullable StackValue blockResult = null;
for (Iterator<KtExpression> iterator = statements.iterator(); iterator.hasNext(); ) {
KtExpression possiblyLabeledStatement = iterator.next();
KtElement statement = KtPsiUtil.safeDeparenthesize(possiblyLabeledStatement);
if (statement instanceof KtNamedDeclaration) {
KtNamedDeclaration declaration = (KtNamedDeclaration) statement;
if (KtPsiUtil.isScriptDeclaration(declaration)) {
continue;
}
}
putDescriptorIntoFrameMap(statement);
boolean isExpression = !iterator.hasNext() && !isStatement;
if (isExpression && labelBeforeLastExpression != null) {
v.mark(labelBeforeLastExpression);
}
// Note that this statementResult value is potentially unused (in case of handleResult coroutine call)
// It's supposed here that no bytecode is emitted until 'put' call on relevant StackValue object
StackValue statementResult = isExpression ? gen(possiblyLabeledStatement) : genStatement(possiblyLabeledStatement);
if (!iterator.hasNext()) {
blockResult = statementResult;
} else {
statementResult.put(Type.VOID_TYPE, v);
}
addLeaveTaskToRemoveDescriptorFromFrameMap(statement, blockEnd, leaveTasks);
}
if (statements.isEmpty()) {
blockResult = StackValue.none();
}
assert blockResult != null : "Block result should be initialized in the loop or the condition above";
return new StackValueWithLeaveTask(blockResult, new Function1<StackValue, Unit>() {
@Override
public Unit invoke(StackValue value) {
if (labelBlockEnd == null) {
v.mark(blockEnd);
}
for (Function<StackValue, Void> task : Lists.reverse(leaveTasks)) {
task.fun(value);
}
return Unit.INSTANCE;
}
});
}
Aggregations