use of com.intellij.util.Processor in project android by JetBrains.
the class ThemeAttributeResolverTest method createNewStyle.
public boolean createNewStyle(@NotNull final VirtualFile resourceDir, @NotNull final String newStyleName, @NotNull final String parentStyleName, @Nullable final String colorPrimaryValue, @NotNull final List<String> folders) {
return new WriteCommandAction<Boolean>(getProject(), "Create new style " + newStyleName) {
@Override
protected void run(@NotNull Result<Boolean> result) {
result.setResult(AndroidResourceUtil.createValueResource(getProject(), resourceDir, newStyleName, null, ResourceType.STYLE, "styles.xml", folders, new Processor<ResourceElement>() {
@Override
public boolean process(ResourceElement element) {
assert element instanceof Style;
final Style style = (Style) element;
style.getParentStyle().setStringValue(parentStyleName);
if (colorPrimaryValue != null) {
StyleItem styleItem = style.addItem();
styleItem.getName().setStringValue("colorPrimary");
styleItem.setStringValue(colorPrimaryValue);
}
return true;
}
}));
}
}.execute().getResultObject();
}
use of com.intellij.util.Processor in project intellij-plugins by JetBrains.
the class FlexResolveHelper method findClassByQName.
@Nullable
public PsiElement findClassByQName(final String link, final Project project, final String className, final GlobalSearchScope scope) {
final Ref<JSClass> result = new Ref<>();
final String expectedPackage = link.equals(className) ? "" : link.substring(0, link.length() - className.length() - 1);
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final PsiManager manager = PsiManager.getInstance(project);
final Processor<VirtualFile> processor = file -> {
VirtualFile rootForFile = projectFileIndex.getSourceRootForFile(file);
if (rootForFile == null)
return true;
if (expectedPackage.equals(VfsUtilCore.getRelativePath(file.getParent(), rootForFile, '.'))) {
PsiFile psiFile = manager.findFile(file);
final JSClass clazz = psiFile instanceof XmlFile ? XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) psiFile) : null;
if (clazz != null) {
result.set(clazz);
return false;
}
}
return true;
};
Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(project, className + JavaScriptSupportLoader.MXML_FILE_EXTENSION_DOT, scope);
ContainerUtil.process(files, processor);
if (result.isNull()) {
files = FilenameIndex.getVirtualFilesByName(project, className + JavaScriptSupportLoader.FXG_FILE_EXTENSION_DOT, scope);
ContainerUtil.process(files, processor);
}
return result.get();
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class GotoActionItemProvider method processActions.
private boolean processActions(String pattern, boolean everywhere, Processor<MatchedValue> consumer, DataContext dataContext) {
JBIterable<AnAction> actions;
if (everywhere) {
Set<String> ids = ((ActionManagerImpl) myActionManager).getActionIds();
actions = JBIterable.from(ids).transform(myActionManager::getAction).filter(Condition.NOT_NULL);
} else {
actions = JBIterable.from(myModel.myActionGroups.keySet());
}
MinusculeMatcher matcher = NameUtil.buildMatcher("*" + pattern, NameUtil.MatchingCaseSensitivity.NONE);
JBIterable<ActionWrapper> actionWrappers = actions.transform(action -> {
MatchMode mode = myModel.actionMatches(pattern, matcher, action);
if (mode == MatchMode.NONE)
return null;
return new ActionWrapper(action, myModel.myActionGroups.get(action), mode, dataContext);
}).filter(Condition.NOT_NULL);
return processItems(pattern, actionWrappers, consumer);
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class JobUtilTest method testTasksRunEvenWhenReadActionIsHardToGet_Performance.
public void testTasksRunEvenWhenReadActionIsHardToGet_Performance() throws ExecutionException, InterruptedException {
AtomicInteger processorCalled = new AtomicInteger();
final Processor<String> processor = s -> {
busySleep(1);
processorCalled.incrementAndGet();
return true;
};
for (int i = 0; i < 10; /*0*/
i++) {
System.out.println("i = " + i);
processorCalled.set(0);
final ProgressIndicator indicator = new EmptyProgressIndicator();
int N = 10000;
Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(() -> {
JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(N, ""), indicator, true, false, processor);
assertFalse(indicator.isCanceled());
});
for (int k = 0; k < 10000; k++) {
ApplicationManager.getApplication().runWriteAction(() -> {
busySleep(1);
});
}
future.get();
assertEquals(N, processorCalled.get());
}
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class SafeDeleteJavaCallerChooser method isTheOnlyOneParameterUsage.
/**
* @return parameter if it is used inside method only as argument in nodeMethod call at parameterIndex
*/
static PsiParameter isTheOnlyOneParameterUsage(PsiElement call, final int parameterIndex, final PsiMethod nodeMethod) {
if (call instanceof PsiCallExpression) {
final PsiExpressionList argumentList = ((PsiCallExpression) call).getArgumentList();
if (argumentList != null) {
final PsiExpression[] expressions = argumentList.getExpressions();
if (expressions.length > parameterIndex) {
final PsiExpression expression = PsiUtil.deparenthesizeExpression(expressions[parameterIndex]);
if (expression != null) {
final Set<PsiParameter> paramRefs = new HashSet<>();
expression.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
super.visitReferenceExpression(expression);
final PsiElement resolve = expression.resolve();
if (resolve instanceof PsiParameter) {
paramRefs.add((PsiParameter) resolve);
}
}
});
final PsiParameter parameter = ContainerUtil.getFirstItem(paramRefs);
if (parameter != null && !parameter.isVarArgs()) {
final PsiElement scope = parameter.getDeclarationScope();
if (scope instanceof PsiMethod && ((PsiMethod) scope).findDeepestSuperMethods().length == 0 && OverridingMethodsSearch.search((PsiMethod) scope).findFirst() == null) {
final int scopeParamIdx = ((PsiMethod) scope).getParameterList().getParameterIndex(parameter);
final Ref<Boolean> ref = new Ref<>(false);
if (ReferencesSearch.search(parameter, new LocalSearchScope(scope)).forEach(new Processor<PsiReference>() {
@Override
public boolean process(PsiReference reference) {
final PsiElement element = reference.getElement();
if (element instanceof PsiReferenceExpression) {
PsiCallExpression parent = PsiTreeUtil.getParentOfType(element, PsiCallExpression.class);
while (parent != null) {
final PsiMethod resolved = parent.resolveMethod();
if (scope.equals(resolved)) {
if (usedInQualifier(element, parent, scopeParamIdx))
return false;
return true;
}
if (nodeMethod.equals(resolved)) {
if (usedInQualifier(element, parent, parameterIndex))
return false;
ref.set(true);
return true;
}
parent = PsiTreeUtil.getParentOfType(parent, PsiCallExpression.class, true);
}
return false;
}
return true;
}
private boolean usedInQualifier(PsiElement element, PsiCallExpression parent, int parameterIndex) {
PsiExpression qualifier = null;
if (parent instanceof PsiMethodCallExpression) {
qualifier = ((PsiMethodCallExpression) parent).getMethodExpression();
} else if (parent instanceof PsiNewExpression) {
qualifier = ((PsiNewExpression) parent).getQualifier();
}
if (PsiTreeUtil.isAncestor(qualifier, element, true)) {
return true;
}
final PsiExpressionList list = parent.getArgumentList();
return list != null && !PsiTreeUtil.isAncestor(list.getExpressions()[parameterIndex], element, false);
}
}) && ref.get()) {
return parameter;
}
}
}
}
}
}
}
return null;
}
Aggregations