Search in sources :

Example 46 with Processor

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()]);
}
Also used : JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) ImplementationsProvider(com.intellij.diagram.extras.providers.ImplementationsProvider) Processor(com.intellij.util.Processor) Collection(java.util.Collection) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) THashSet(gnu.trove.THashSet) Comparator(java.util.Comparator) Collections(java.util.Collections) JSClassSearch(com.intellij.lang.javascript.search.JSClassSearch) JSBundle(com.intellij.lang.javascript.JSBundle) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 47 with Processor

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;
}
Also used : StringWriter(com.intellij.flex.uiDesigner.io.StringRegistry.StringWriter) InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) Application(com.intellij.openapi.application.Application) JavaScriptSupportLoader(com.intellij.lang.javascript.JavaScriptSupportLoader) XmlFile(com.intellij.psi.xml.XmlFile) FlexPredefinedTagNames(com.intellij.javascript.flex.FlexPredefinedTagNames) VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashMap(gnu.trove.THashMap) FlexCommonTypeNames(com.intellij.javascript.flex.mxml.FlexCommonTypeNames) ActionScriptClassResolver(com.intellij.javascript.flex.resolve.ActionScriptClassResolver) JSClassSearch(com.intellij.lang.javascript.search.JSClassSearch) ReadAction(com.intellij.openapi.application.ReadAction) ArrayList(java.util.ArrayList) AccessToken(com.intellij.openapi.application.AccessToken) MxmlUtil(com.intellij.flex.uiDesigner.mxml.MxmlUtil) Semaphore(com.intellij.util.concurrency.Semaphore) LocalCssWriter(com.intellij.flex.uiDesigner.css.LocalCssWriter) Project(com.intellij.openapi.project.Project) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) Module(com.intellij.openapi.module.Module) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) StylesheetFile(com.intellij.psi.css.StylesheetFile) XmlTag(com.intellij.psi.xml.XmlTag) DumbService(com.intellij.openapi.project.DumbService) XmlAttribute(com.intellij.psi.xml.XmlAttribute) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Library(com.intellij.flex.uiDesigner.libraries.Library) ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) Collections(java.util.Collections) VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalCssWriter(com.intellij.flex.uiDesigner.css.LocalCssWriter) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 48 with Processor

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;
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) Processor(com.intellij.util.Processor) PsiClass(com.intellij.psi.PsiClass) NotNull(org.jetbrains.annotations.NotNull) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) StringSearcher(com.intellij.util.text.StringSearcher)

Example 49 with Processor

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()]);
}
Also used : Project(com.intellij.openapi.project.Project) Processor(com.intellij.util.Processor) ExcludesConfiguration(com.intellij.openapi.compiler.options.ExcludesConfiguration) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 50 with Processor

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);
}
Also used : Project(com.intellij.openapi.project.Project) Processor(com.intellij.util.Processor) Query(com.intellij.util.Query) PsiClass(com.intellij.psi.PsiClass) ComponentDefinition(com.android.tools.idea.editors.theme.preview.ThemePreviewBuilder.ComponentDefinition)

Aggregations

Processor (com.intellij.util.Processor)83 NotNull (org.jetbrains.annotations.NotNull)65 Project (com.intellij.openapi.project.Project)49 Nullable (org.jetbrains.annotations.Nullable)49 ContainerUtil (com.intellij.util.containers.ContainerUtil)42 com.intellij.psi (com.intellij.psi)31 List (java.util.List)28 ApplicationManager (com.intellij.openapi.application.ApplicationManager)25 StringUtil (com.intellij.openapi.util.text.StringUtil)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)25 java.util (java.util)25 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)24 ProgressManager (com.intellij.openapi.progress.ProgressManager)21 Logger (com.intellij.openapi.diagnostic.Logger)20 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)20 NonNls (org.jetbrains.annotations.NonNls)18 Ref (com.intellij.openapi.util.Ref)16 Collection (java.util.Collection)16 SmartList (com.intellij.util.SmartList)14 Document (com.intellij.openapi.editor.Document)13