use of com.intellij.util.Processor in project intellij-plugins by JetBrains.
the class FlashUmlImplementationsProvider method getElements.
public Object[] getElements(Object element, Project project) {
JSClass clazz = (JSClass) element;
final Collection<PsiElement> inheritors = Collections.synchronizedSet(new THashSet<PsiElement>());
final Processor<JSClass> p = aClass -> {
final PsiElement navigationElement = aClass.getNavigationElement();
inheritors.add(navigationElement instanceof JSClass ? navigationElement : aClass);
return true;
};
JSClassSearch.searchClassInheritors(clazz, true).forEach(p);
if (clazz.isInterface()) {
JSClassSearch.searchInterfaceImplementations(clazz, true).forEach(p);
}
return inheritors.toArray(new PsiElement[inheritors.size()]);
}
use of com.intellij.util.Processor in project intellij-plugins by JetBrains.
the class ModuleInfoUtil method collectApplicationLocalStyle.
@Nullable
private static List<LocalStyleHolder> collectApplicationLocalStyle(final Module module, String flexSdkVersion, final ProblemsHolder problemsHolder, StringWriter stringWriter, ProjectComponentReferenceCounter projectComponentReferenceCounter, final AssetCounter assetCounter) {
GlobalSearchScope moduleWithDependenciesAndLibrariesScope = module.getModuleWithDependenciesAndLibrariesScope(false);
final List<JSClass> holders = new ArrayList<>(2);
if (flexSdkVersion.charAt(0) > '3') {
JSClass clazz = ((JSClass) ActionScriptClassResolver.findClassByQNameStatic(FlexCommonTypeNames.SPARK_APPLICATION, moduleWithDependenciesAndLibrariesScope));
// it is not legal case, but user can use patched/modified Flex SDK
if (clazz != null) {
holders.add(clazz);
}
}
JSClass mxApplicationClass = ((JSClass) ActionScriptClassResolver.findClassByQNameStatic(FlexCommonTypeNames.MX_APPLICATION, moduleWithDependenciesAndLibrariesScope));
// if null, mx.swc is not added to module dependencies
if (mxApplicationClass != null) {
holders.add(mxApplicationClass);
}
if (holders.isEmpty()) {
return null;
}
final StyleTagWriter styleTagWriter = new StyleTagWriter(new LocalCssWriter(stringWriter, problemsHolder, projectComponentReferenceCounter, assetCounter));
final List<LocalStyleHolder> result = new ArrayList<>();
final Processor<JSClass> processor = jsClass -> {
PsiFile psiFile = jsClass.getNavigationElement().getContainingFile();
if (!(psiFile instanceof XmlFile)) {
return true;
}
XmlTag rootTag = ((XmlFile) psiFile).getRootTag();
if (rootTag == null) {
return true;
}
final VirtualFile virtualFile = psiFile.getVirtualFile();
problemsHolder.setCurrentFile(virtualFile);
try {
for (final XmlTag subTag : rootTag.getSubTags()) {
if (subTag.getNamespace().equals(JavaScriptSupportLoader.MXML_URI3) && subTag.getLocalName().equals(FlexPredefinedTagNames.STYLE)) {
try {
LocalStyleHolder localStyleHolder = styleTagWriter.write(subTag, module, virtualFile);
if (localStyleHolder != null) {
result.add(localStyleHolder);
}
} catch (InvalidPropertyException e) {
problemsHolder.add(e);
}
}
}
} finally {
problemsHolder.setCurrentFile(null);
}
return true;
};
final GlobalSearchScope moduleScope = module.getModuleScope(false);
for (JSClass holder : holders) {
JSClassSearch.searchClassInheritors(holder, true, moduleScope).forEach(processor);
}
return result;
}
use of com.intellij.util.Processor in project smali by JesusFreke.
the class SmaliClassReferenceSearcher method processQuery.
@Override
public void processQuery(final SearchParameters queryParameters, final Processor<PsiReference> consumer) {
final PsiElement element = queryParameters.getElementToSearch();
if (!(element instanceof PsiClass)) {
return;
}
String smaliType = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
String qualifiedName = ((PsiClass) element).getQualifiedName();
if (qualifiedName != null) {
return NameUtils.javaToSmaliType((PsiClass) element);
}
return null;
}
});
if (smaliType == null) {
return;
}
final StringSearcher stringSearcher = new StringSearcher(smaliType, true, true, false, false);
final SingleTargetRequestResultProcessor processor = new SingleTargetRequestResultProcessor(element);
SearchScope querySearchScope = ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {
@Override
public SearchScope compute() {
return queryParameters.getEffectiveSearchScope();
}
});
if (querySearchScope instanceof LocalSearchScope) {
for (final PsiElement scopeElement : ((LocalSearchScope) querySearchScope).getScope()) {
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
LowLevelSearchUtil.processElementsContainingWordInElement(new TextOccurenceProcessor() {
@Override
public boolean execute(@NotNull PsiElement element, int offsetInElement) {
return processor.processTextOccurrence(element, offsetInElement, consumer);
}
}, scopeElement, stringSearcher, true, new EmptyProgressIndicator());
}
});
}
} else if (querySearchScope instanceof GlobalSearchScope) {
PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(element.getProject());
// TODO: limit search scope to only smali files. See, e.g. AnnotatedPackagesSearcher.PackageInfoFilesOnly
helper.processAllFilesWithWord(smaliType, (GlobalSearchScope) querySearchScope, new Processor<PsiFile>() {
@Override
public boolean process(PsiFile file) {
LowLevelSearchUtil.processElementsContainingWordInElement(new TextOccurenceProcessor() {
@Override
public boolean execute(@NotNull PsiElement element, int offsetInElement) {
return processor.processTextOccurrence(element, offsetInElement, consumer);
}
}, file, stringSearcher, true, new EmptyProgressIndicator());
return true;
}
}, true);
} else {
assert false;
return;
}
}
use of com.intellij.util.Processor in project intellij-community by JetBrains.
the class InspectionValidatorWrapper method getProcessingItems.
@Override
@NotNull
public ProcessingItem[] getProcessingItems(final CompileContext context) {
final Project project = context.getProject();
if (project.isDefault() || !ValidationConfiguration.shouldValidate(this, context)) {
return ProcessingItem.EMPTY_ARRAY;
}
final ExcludesConfiguration excludesConfiguration = ValidationConfiguration.getExcludedEntriesConfiguration(project);
final List<ProcessingItem> items = DumbService.getInstance(project).runReadActionInSmartMode((Computable<List<ProcessingItem>>) () -> {
final CompileScope compileScope = context.getCompileScope();
if (!myValidator.isAvailableOnScope(compileScope))
return null;
final ArrayList<ProcessingItem> items1 = new ArrayList<>();
final Processor<VirtualFile> processor = file -> {
if (!file.isValid()) {
return true;
}
if (myCompilerManager.isExcludedFromCompilation(file) || excludesConfiguration.isExcluded(file)) {
return true;
}
final Module module = context.getModuleByFile(file);
if (module != null) {
final PsiFile psiFile = myPsiManager.findFile(file);
if (psiFile != null) {
items1.add(new MyValidatorProcessingItem(psiFile));
}
}
return true;
};
ContainerUtil.process(myValidator.getFilesToProcess(myPsiManager.getProject(), context), processor);
return items1;
});
if (items == null)
return ProcessingItem.EMPTY_ARRAY;
return items.toArray(new ProcessingItem[items.size()]);
}
use of com.intellij.util.Processor in project android by JetBrains.
the class AndroidThemePreviewPanel method reloadComponents.
/**
* Searches the PSI for both custom components and support library classes. Call this method when you
* want to refresh the components displayed on the preview.
*/
public void reloadComponents() {
myDumbService.runWhenSmart(new Runnable() {
@Override
public void run() {
Project project = myContext.getProject();
if (!project.isOpen()) {
return;
}
PsiClass viewClass = JavaPsiFacade.getInstance(project).findClass("android.view.View", GlobalSearchScope.allScope(project));
if (viewClass == null) {
// There is probably no SDK
LOG.debug("Unable to find 'android.view.View'");
return;
}
Query<PsiClass> viewClasses = ClassInheritorsSearch.search(viewClass, ProjectScope.getProjectScope(project), true);
final ArrayList<ComponentDefinition> customComponents = new ArrayList<ComponentDefinition>();
viewClasses.forEach(new Processor<PsiClass>() {
@Override
public boolean process(PsiClass psiClass) {
// We use the "simple" name as description on the preview.
String description = psiClass.getName();
String className = psiClass.getQualifiedName();
if (description == null || className == null) {
// Currently we ignore anonymous views
return false;
}
customComponents.add(new ComponentDefinition(description, ThemePreviewBuilder.ComponentGroup.CUSTOM, className));
return true;
}
});
// Now search for support library components. We use a HashSet to avoid adding duplicate components from source and jar files.
myDisabledComponents.clear();
final HashSet<ComponentDefinition> supportLibraryComponents = new HashSet<ComponentDefinition>();
viewClasses = ClassInheritorsSearch.search(viewClass, ProjectScope.getLibrariesScope(project), true);
viewClasses.forEach(new Processor<PsiClass>() {
@Override
public boolean process(PsiClass psiClass) {
String className = psiClass.getQualifiedName();
ComponentDefinition component = SUPPORT_LIBRARY_COMPONENTS.get(className);
if (component != null) {
supportLibraryComponents.add(component);
String replaces = SUPPORT_LIBRARY_REPLACEMENTS.get(className);
if (replaces != null) {
myDisabledComponents.add(replaces);
}
}
return true;
}
});
myCustomComponents = Collections.unmodifiableList(customComponents);
mySupportLibraryComponents = ImmutableList.copyOf(supportLibraryComponents);
if (!myCustomComponents.isEmpty() || !mySupportLibraryComponents.isEmpty()) {
rebuild();
}
}
});
rebuild(false);
}
Aggregations