use of com.intellij.util.Processor in project scss-lint-plugin by idok.
the class TestUtils2 method addLibrary.
public static ModifiableRootModel addLibrary(ModifiableRootModel rootModel, ModuleRootManager rootManager, OrderEnumerator libs, List<Library.ModifiableModel> libModels, final String clojureLibraryName, String mockLib, String mockLibSrc) {
class CustomProcessor implements Processor<Library> {
private boolean result = true;
public boolean process(Library library) {
boolean res = library.getName().equals(clojureLibraryName);
if (res)
result = false;
return result;
}
}
CustomProcessor processor = new CustomProcessor();
libs.forEachLibrary(processor);
if (processor.result) {
if (rootModel == null) {
rootModel = rootManager.getModifiableModel();
}
final LibraryTable libraryTable = rootModel.getModuleLibraryTable();
final Library scalaLib = libraryTable.createLibrary(clojureLibraryName);
final Library.ModifiableModel libModel = scalaLib.getModifiableModel();
libModels.add(libModel);
addLibraryRoots(libModel, mockLib, mockLibSrc);
}
return rootModel;
}
use of com.intellij.util.Processor in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoTestFunctionCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
Project project = parameters.getPosition().getProject();
PsiFile file = parameters.getOriginalFile();
PsiDirectory containingDirectory = file.getContainingDirectory();
if (file instanceof GoFile && containingDirectory != null) {
CompletionResultSet resultSet = result.withPrefixMatcher(new CamelHumpMatcher(result.getPrefixMatcher().getPrefix(), false));
Collection<String> allPackageFunctionNames = collectAllFunctionNames(containingDirectory);
Set<String> allTestFunctionNames = collectAllTestNames(allPackageFunctionNames, project, (GoFile) file);
String fileNameWithoutTestPrefix = StringUtil.trimEnd(file.getName(), GoConstants.TEST_SUFFIX_WITH_EXTENSION) + ".go";
GlobalSearchScope packageScope = GoPackageUtil.packageScope(containingDirectory, ((GoFile) file).getCanonicalPackageName());
GlobalSearchScope scope = new GoUtil.ExceptTestsScope(packageScope);
IdFilter idFilter = GoIdFilter.getFilesFilter(scope);
for (String functionName : allPackageFunctionNames) {
GoFunctionIndex.process(functionName, project, scope, idFilter, declaration -> {
addVariants(declaration, functionName, fileNameWithoutTestPrefix, allTestFunctionNames, resultSet);
return false;
});
}
Collection<String> methodKeys = ContainerUtil.newTroveSet();
StubIndex.getInstance().processAllKeys(GoMethodIndex.KEY, new CancellableCollectProcessor<>(methodKeys), scope, idFilter);
for (String key : methodKeys) {
Processor<GoMethodDeclaration> processor = declaration -> {
GoMethodDeclarationStubElementType.calcTypeText(declaration);
String typeText = key.substring(Math.min(key.indexOf('.') + 1, key.length()));
String methodName = declaration.getName();
if (methodName != null) {
if (!declaration.isPublic() || declaration.isBlank()) {
return true;
}
String lookupString = !typeText.isEmpty() ? StringUtil.capitalize(typeText) + "_" + methodName : methodName;
addVariants(declaration, lookupString, fileNameWithoutTestPrefix, allTestFunctionNames, resultSet);
}
return true;
};
GoMethodIndex.process(key, project, scope, idFilter, processor);
}
}
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class SearchScope method iterateContent.
public void iterateContent(@NotNull final Project project, final Processor<VirtualFile> processor) {
switch(getScopeType()) {
case PROJECT:
//noinspection unchecked
ProjectRootManager.getInstance(project).getFileIndex().iterateContent(new MyFileIterator(processor, Conditions.<VirtualFile>alwaysTrue()));
break;
case MODULE:
final Module module = ModuleManager.getInstance(project).findModuleByName(getModuleName());
assert module != null;
ModuleRootManager.getInstance(module).getFileIndex().iterateContent(new MyFileIterator(processor, Conditions.<VirtualFile>alwaysTrue()));
break;
case DIRECTORY:
final String dirName = getPath();
assert dirName != null;
final VirtualFile virtualFile = findFile(dirName);
if (virtualFile != null) {
iterateRecursively(virtualFile, processor, isRecursive());
}
break;
case CUSTOM:
assert myCustomScope != null;
final ContentIterator iterator;
if (myCustomScope instanceof GlobalSearchScope) {
final GlobalSearchScope searchScope = (GlobalSearchScope) myCustomScope;
iterator = new MyFileIterator(processor, virtualFile13 -> searchScope.contains(virtualFile13));
if (searchScope.isSearchInLibraries()) {
final OrderEnumerator enumerator = OrderEnumerator.orderEntries(project).withoutModuleSourceEntries().withoutDepModules();
final Collection<VirtualFile> libraryFiles = new THashSet<>();
Collections.addAll(libraryFiles, enumerator.getClassesRoots());
Collections.addAll(libraryFiles, enumerator.getSourceRoots());
final Processor<VirtualFile> adapter = virtualFile1 -> iterator.processFile(virtualFile1);
for (final VirtualFile file : libraryFiles) {
iterateRecursively(file, adapter, true);
}
}
} else {
final PsiManager manager = PsiManager.getInstance(project);
iterator = new MyFileIterator(processor, virtualFile12 -> {
final PsiFile element = manager.findFile(virtualFile12);
return element != null && PsiSearchScopeUtil.isInScope(myCustomScope, element);
});
}
ProjectRootManager.getInstance(project).getFileIndex().iterateContent(iterator);
}
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class GrAliasImportIntention method findUsages.
private static List<UsageInfo> findUsages(PsiMember member, GroovyFileBase file) {
LocalSearchScope scope = new LocalSearchScope(file);
final ArrayList<UsageInfo> infos = new ArrayList<>();
final HashSet<Object> usedRefs = ContainerUtil.newHashSet();
final Processor<PsiReference> consumer = reference -> {
if (usedRefs.add(reference)) {
infos.add(new UsageInfo(reference));
}
return true;
};
if (member instanceof PsiMethod) {
MethodReferencesSearch.search((PsiMethod) member, scope, false).forEach(consumer);
} else {
ReferencesSearch.search(member, scope).forEach(consumer);
if (member instanceof PsiField) {
final PsiMethod getter = GroovyPropertyUtils.findGetterForField((PsiField) member);
if (getter != null) {
MethodReferencesSearch.search(getter, scope, false).forEach(consumer);
}
final PsiMethod setter = GroovyPropertyUtils.findSetterForField((PsiField) member);
if (setter != null) {
MethodReferencesSearch.search(setter, scope, false).forEach(consumer);
}
}
}
return infos;
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class PropertiesInheritorsSearcher method processQuery.
@Override
public void processQuery(@NotNull DefinitionsScopedSearch.SearchParameters queryParameters, @NotNull Processor<PsiElement> consumer) {
final PsiElement element = queryParameters.getElement();
Property prop = ReadAction.compute(() -> GotoPropertyParentDeclarationHandler.findProperty(element));
if (prop == null || !(queryParameters.getScope() instanceof GlobalSearchScope)) {
return;
}
ReadAction.run(() -> {
final String key = prop.getKey();
if (!prop.isValid() || key == null)
return;
final PropertiesFile currentFile = PropertiesImplUtil.getPropertiesFile(prop.getContainingFile());
LOG.assertTrue(currentFile != null);
final GlobalSearchScope scope = (GlobalSearchScope) queryParameters.getScope();
currentFile.getResourceBundle().getPropertiesFiles().stream().filter(f -> f.equals(currentFile)).filter(f -> scope.contains(f.getVirtualFile())).filter(f -> PropertiesUtil.getParent(f, Collections.singleton(currentFile)) == currentFile).map(f -> f.findPropertyByKey(key)).filter(Objects::nonNull).map(IProperty::getPsiElement).anyMatch(psiElement -> {
ProgressManager.checkCanceled();
return !consumer.process(psiElement);
});
});
}
Aggregations