Search in sources :

Example 1 with Query

use of com.intellij.util.Query in project intellij-community by JetBrains.

the class XsltImplicitUsagesProvider method isImplicitUsage.

public boolean isImplicitUsage(PsiElement element) {
    if (!(element instanceof XmlAttribute)) {
        return false;
    }
    final XmlAttribute attr = (XmlAttribute) element;
    if (!attr.isNamespaceDeclaration()) {
        return false;
    }
    final PsiFile file = attr.getContainingFile();
    if (!(file instanceof XmlFile)) {
        return false;
    }
    // ContextProvider.hasXPathInjections() is an optimization that avoids to run the references search on totally XPath-free XML files
    if (!ContextProvider.hasXPathInjections((XmlFile) file) && !XsltSupport.isXsltFile(file)) {
        return false;
    }
    // This need to catch both prefix references from injected XPathFiles and prefixes from mode declarations/references:
    // <xsl:template match="*" mode="prefix:name" />
    // BTW: Almost the same logic applies to other XML dialects (RELAX-NG).
    // Pull this class into the platform?
    final String prefix = attr.getLocalName();
    final SchemaPrefix target = new SchemaPrefix(attr, TextRange.from("xmlns:".length(), prefix.length()), prefix);
    final Query<PsiReference> q = ReferencesSearch.search(target, new LocalSearchScope(attr.getParent()));
    return !q.forEach(psiReference -> {
        if (psiReference.getElement() == attr) {
            return true;
        }
        return false;
    });
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) ReferencesSearch(com.intellij.psi.search.searches.ReferencesSearch) SchemaPrefix(com.intellij.psi.impl.source.xml.SchemaPrefix) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) XsltSupport(org.intellij.lang.xpath.xslt.XsltSupport) PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) Query(com.intellij.util.Query) Processor(com.intellij.util.Processor) PsiElement(com.intellij.psi.PsiElement) PsiFile(com.intellij.psi.PsiFile) ImplicitUsageProvider(com.intellij.codeInsight.daemon.ImplicitUsageProvider) ContextProvider(org.intellij.lang.xpath.context.ContextProvider) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) SchemaPrefix(com.intellij.psi.impl.source.xml.SchemaPrefix) PsiReference(com.intellij.psi.PsiReference) PsiFile(com.intellij.psi.PsiFile)

Example 2 with Query

use of com.intellij.util.Query in project intellij-community by JetBrains.

the class InlineLocalHandler method invoke.

/**
   * should be called in AtomicAction
   */
public static void invoke(@NotNull final Project project, final Editor editor, final PsiLocalVariable local, PsiReferenceExpression refExpr) {
    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, local))
        return;
    final HighlightManager highlightManager = HighlightManager.getInstance(project);
    final String localName = local.getName();
    final List<PsiElement> innerClassesWithUsages = Collections.synchronizedList(new ArrayList<PsiElement>());
    final List<PsiElement> innerClassUsages = Collections.synchronizedList(new ArrayList<PsiElement>());
    final PsiClass containingClass = PsiTreeUtil.getParentOfType(local, PsiClass.class);
    final Query<PsiReference> query = ReferencesSearch.search(local);
    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        if (query.findFirst() == null) {
            LOG.assertTrue(refExpr == null);
            ApplicationManager.getApplication().invokeLater(() -> {
                String message = RefactoringBundle.message("variable.is.never.used", localName);
                CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INLINE_VARIABLE);
            }, ModalityState.NON_MODAL);
            return;
        }
        query.forEach(psiReference -> {
            final PsiElement element = psiReference.getElement();
            PsiElement innerClass = PsiTreeUtil.getParentOfType(element, PsiClass.class, PsiLambdaExpression.class);
            while (innerClass != containingClass && innerClass != null) {
                final PsiElement parentPsiClass = PsiTreeUtil.getParentOfType(innerClass.getParent(), PsiClass.class, PsiLambdaExpression.class);
                if (parentPsiClass == containingClass) {
                    if (innerClass instanceof PsiLambdaExpression) {
                        if (PsiTreeUtil.isAncestor(innerClass, local, false)) {
                            innerClassesWithUsages.add(element);
                            innerClass = parentPsiClass;
                            continue;
                        }
                    }
                    innerClassesWithUsages.add(innerClass);
                    innerClassUsages.add(element);
                }
                innerClass = parentPsiClass;
            }
            return true;
        });
    }, "Find Usages", true, project)) {
        return;
    }
    final PsiCodeBlock containerBlock = PsiTreeUtil.getParentOfType(local, PsiCodeBlock.class);
    if (containerBlock == null) {
        final String message = RefactoringBundle.getCannotRefactorMessage("Variable is declared outside a code block");
        CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INLINE_VARIABLE);
        return;
    }
    final PsiExpression defToInline = getDefToInline(local, innerClassesWithUsages.isEmpty() ? refExpr : innerClassesWithUsages.get(0), containerBlock);
    if (defToInline == null) {
        final String key = refExpr == null ? "variable.has.no.initializer" : "variable.has.no.dominating.definition";
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message(key, localName));
        CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INLINE_VARIABLE);
        return;
    }
    List<PsiElement> refsToInlineList = new ArrayList<>();
    Collections.addAll(refsToInlineList, DefUseUtil.getRefs(containerBlock, local, defToInline));
    for (PsiElement innerClassUsage : innerClassUsages) {
        if (!refsToInlineList.contains(innerClassUsage)) {
            refsToInlineList.add(innerClassUsage);
        }
    }
    if (refsToInlineList.size() == 0) {
        String message = RefactoringBundle.message("variable.is.never.used.before.modification", localName);
        CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INLINE_VARIABLE);
        return;
    }
    final Ref<Boolean> inlineAll = new Ref<>(true);
    if (editor != null && !ApplicationManager.getApplication().isUnitTestMode()) {
        int occurrencesCount = refsToInlineList.size();
        if (refExpr != null && occurrencesCount > 1 || EditorSettingsExternalizable.getInstance().isShowInlineLocalDialog()) {
            final InlineLocalDialog inlineLocalDialog = new InlineLocalDialog(project, local, refExpr, occurrencesCount);
            if (!inlineLocalDialog.showAndGet()) {
                WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting"));
                return;
            }
            if (refExpr != null && inlineLocalDialog.isInlineThis()) {
                refsToInlineList = Collections.singletonList(refExpr);
                inlineAll.set(false);
            }
        }
    }
    final PsiElement[] refsToInline = PsiUtilCore.toPsiElementArray(refsToInlineList);
    final EditorColorsManager manager = EditorColorsManager.getInstance();
    final TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    final TextAttributes writeAttributes = manager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
    if (editor != null && !ApplicationManager.getApplication().isUnitTestMode()) {
        // TODO : check if initializer uses fieldNames that possibly will be hidden by other
        // locals with the same names after inlining
        highlightManager.addOccurrenceHighlights(editor, refsToInline, attributes, true, null);
    }
    if (refExpr != null && PsiUtil.isAccessedForReading(refExpr) && ArrayUtil.find(refsToInline, refExpr) < 0) {
        final PsiElement[] defs = DefUseUtil.getDefs(containerBlock, local, refExpr);
        LOG.assertTrue(defs.length > 0);
        highlightManager.addOccurrenceHighlights(editor, defs, attributes, true, null);
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("variable.is.accessed.for.writing", localName));
        CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INLINE_VARIABLE);
        WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting"));
        return;
    }
    PsiTryStatement tryStatement = PsiTreeUtil.getParentOfType(defToInline, PsiTryStatement.class);
    if (tryStatement != null) {
        if (ExceptionUtil.getThrownExceptions(defToInline).isEmpty()) {
            tryStatement = null;
        }
    }
    PsiFile workingFile = local.getContainingFile();
    for (PsiElement ref : refsToInline) {
        final PsiFile otherFile = ref.getContainingFile();
        if (!otherFile.equals(workingFile)) {
            String message = RefactoringBundle.message("variable.is.referenced.in.multiple.files", localName);
            CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INLINE_VARIABLE);
            return;
        }
        if (tryStatement != null && !PsiTreeUtil.isAncestor(tryStatement, ref, false)) {
            CommonRefactoringUtil.showErrorHint(project, editor, "Unable to inline outside try/catch statement", REFACTORING_NAME, HelpID.INLINE_VARIABLE);
            return;
        }
    }
    for (final PsiElement ref : refsToInline) {
        final PsiElement[] defs = DefUseUtil.getDefs(containerBlock, local, ref);
        boolean isSameDefinition = true;
        for (PsiElement def : defs) {
            isSameDefinition &= isSameDefinition(def, defToInline);
        }
        if (!isSameDefinition) {
            highlightManager.addOccurrenceHighlights(editor, defs, writeAttributes, true, null);
            highlightManager.addOccurrenceHighlights(editor, new PsiElement[] { ref }, attributes, true, null);
            String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("variable.is.accessed.for.writing.and.used.with.inlined", localName));
            CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INLINE_VARIABLE);
            WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting"));
            return;
        }
    }
    final PsiElement writeAccess = checkRefsInAugmentedAssignmentOrUnaryModified(refsToInline, defToInline);
    if (writeAccess != null) {
        HighlightManager.getInstance(project).addOccurrenceHighlights(editor, new PsiElement[] { writeAccess }, writeAttributes, true, null);
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("variable.is.accessed.for.writing", localName));
        CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INLINE_VARIABLE);
        WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting"));
        return;
    }
    final Runnable runnable = () -> {
        final String refactoringId = "refactoring.inline.local.variable";
        try {
            SmartPsiElementPointer<PsiExpression>[] exprs = new SmartPsiElementPointer[refsToInline.length];
            RefactoringEventData beforeData = new RefactoringEventData();
            beforeData.addElements(refsToInline);
            project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringStarted(refactoringId, beforeData);
            WriteAction.run(() -> {
                final SmartPointerManager pointerManager = SmartPointerManager.getInstance(project);
                for (int idx = 0; idx < refsToInline.length; idx++) {
                    PsiJavaCodeReferenceElement refElement = (PsiJavaCodeReferenceElement) refsToInline[idx];
                    exprs[idx] = pointerManager.createSmartPsiElementPointer(InlineUtil.inlineVariable(local, defToInline, refElement));
                }
                if (inlineAll.get()) {
                    if (!isInliningVariableInitializer(defToInline)) {
                        defToInline.getParent().delete();
                    } else {
                        defToInline.delete();
                    }
                }
            });
            if (inlineAll.get() && ReferencesSearch.search(local).findFirst() == null && editor != null) {
                QuickFixFactory.getInstance().createRemoveUnusedVariableFix(local).invoke(project, editor, local.getContainingFile());
            }
            if (editor != null && !ApplicationManager.getApplication().isUnitTestMode()) {
                highlightManager.addOccurrenceHighlights(editor, ContainerUtil.convert(exprs, new PsiExpression[refsToInline.length], pointer -> pointer.getElement()), attributes, true, null);
                WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting"));
            }
            WriteAction.run(() -> {
                for (SmartPsiElementPointer<PsiExpression> expr : exprs) {
                    InlineUtil.tryToInlineArrayCreationForVarargs(expr.getElement());
                }
            });
        } finally {
            final RefactoringEventData afterData = new RefactoringEventData();
            afterData.addElement(containingClass);
            project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(refactoringId, afterData);
        }
    };
    CommandProcessor.getInstance().executeCommand(project, () -> PostprocessReformattingAspect.getInstance(project).postponeFormattingInside(runnable), RefactoringBundle.message("inline.command", localName), null);
}
Also used : DefUseUtil(com.intellij.psi.controlFlow.DefUseUtil) WriteAction(com.intellij.openapi.application.WriteAction) ArrayUtil(com.intellij.util.ArrayUtil) ModalityState(com.intellij.openapi.application.ModalityState) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) RefactoringBundle(com.intellij.refactoring.RefactoringBundle) RefactoringEventListener(com.intellij.refactoring.listeners.RefactoringEventListener) ContainerUtil(com.intellij.util.containers.ContainerUtil) ArrayList(java.util.ArrayList) Query(com.intellij.util.Query) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) EditorSettingsExternalizable(com.intellij.openapi.editor.ex.EditorSettingsExternalizable) Project(com.intellij.openapi.project.Project) PsiUtil(com.intellij.psi.util.PsiUtil) RefactoringEventData(com.intellij.refactoring.listeners.RefactoringEventData) Logger(com.intellij.openapi.diagnostic.Logger) HelpID(com.intellij.refactoring.HelpID) ProgressManager(com.intellij.openapi.progress.ProgressManager) ReferencesSearch(com.intellij.psi.search.searches.ReferencesSearch) WindowManager(com.intellij.openapi.wm.WindowManager) QuickFixFactory(com.intellij.codeInsight.intention.QuickFixFactory) InlineUtil(com.intellij.refactoring.util.InlineUtil) Editor(com.intellij.openapi.editor.Editor) CommandProcessor(com.intellij.openapi.command.CommandProcessor) CommonRefactoringUtil(com.intellij.refactoring.util.CommonRefactoringUtil) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) EditorColors(com.intellij.openapi.editor.colors.EditorColors) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) RefactoringUtil(com.intellij.refactoring.util.RefactoringUtil) TargetElementUtil(com.intellij.codeInsight.TargetElementUtil) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) ExceptionUtil(com.intellij.codeInsight.ExceptionUtil) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) PostprocessReformattingAspect(com.intellij.psi.impl.source.PostprocessReformattingAspect) Collections(java.util.Collections) ArrayList(java.util.ArrayList) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) RefactoringEventData(com.intellij.refactoring.listeners.RefactoringEventData) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) Ref(com.intellij.openapi.util.Ref)

Example 3 with Query

use of com.intellij.util.Query in project intellij-community by JetBrains.

the class InheritanceUtil method hasImplementation.

public static boolean hasImplementation(@NotNull PsiClass aClass) {
    final SearchScope scope = GlobalSearchScope.projectScope(aClass.getProject());
    if (aClass.isInterface() && FunctionalExpressionSearch.search(aClass, scope).findFirst() != null)
        return true;
    for (ImplementedAtRuntimeCondition condition : ImplementedAtRuntimeCondition.EP_NAME.getExtensions()) {
        if (condition.isImplementedAtRuntime(aClass)) {
            return true;
        }
    }
    final Query<PsiClass> search = ClassInheritorsSearch.search(aClass, scope, true);
    return !search.forEach(inheritor -> inheritor.isInterface() || inheritor.isAnnotationType() || inheritor.hasModifierProperty(PsiModifier.ABSTRACT));
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) ImplementedAtRuntimeCondition(com.intellij.codeInspection.inheritance.ImplementedAtRuntimeCondition) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) PsiModifier(com.intellij.psi.PsiModifier) FunctionalExpressionSearch(com.intellij.psi.search.searches.FunctionalExpressionSearch) Query(com.intellij.util.Query) CommonClassNames(com.intellij.psi.CommonClassNames) PsiClass(com.intellij.psi.PsiClass) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Processor(com.intellij.util.Processor) ClassInheritorsSearch(com.intellij.psi.search.searches.ClassInheritorsSearch) PsiTypeParameter(com.intellij.psi.PsiTypeParameter) NotNull(org.jetbrains.annotations.NotNull) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) PsiClass(com.intellij.psi.PsiClass) ImplementedAtRuntimeCondition(com.intellij.codeInspection.inheritance.ImplementedAtRuntimeCondition)

Example 4 with Query

use of com.intellij.util.Query in project intellij-community by JetBrains.

the class StaticInheritanceFix method doFix.

@Override
public void doFix(final Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
    final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement) descriptor.getPsiElement();
    final PsiClass iface = (PsiClass) referenceElement.resolve();
    assert iface != null;
    final PsiField[] allFields = iface.getAllFields();
    final PsiClass implementingClass = ClassUtils.getContainingClass(referenceElement);
    final PsiManager manager = referenceElement.getManager();
    assert implementingClass != null;
    final PsiFile file = implementingClass.getContainingFile();
    ProgressManager.getInstance().run(new Task.Modal(project, "Replacing usages of " + iface.getName(), false) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            for (final PsiField field : allFields) {
                SearchScope scope = ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {

                    @Override
                    public SearchScope compute() {
                        return implementingClass.getUseScope();
                    }
                });
                final Query<PsiReference> search = ReferencesSearch.search(field, scope, false);
                for (PsiReference reference : search) {
                    if (!(reference instanceof PsiReferenceExpression)) {
                        continue;
                    }
                    final PsiReferenceExpression referenceExpression = (PsiReferenceExpression) reference;
                    if (!myReplaceInWholeProject) {
                        boolean isInheritor = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {

                            @Override
                            public Boolean compute() {
                                boolean isInheritor = false;
                                PsiClass aClass = PsiTreeUtil.getParentOfType(referenceExpression, PsiClass.class);
                                while (aClass != null) {
                                    isInheritor = InheritanceUtil.isInheritorOrSelf(aClass, implementingClass, true);
                                    if (isInheritor)
                                        break;
                                    aClass = PsiTreeUtil.getParentOfType(aClass, PsiClass.class);
                                }
                                return isInheritor;
                            }
                        });
                        if (!isInheritor)
                            continue;
                    }
                    final Runnable runnable = () -> {
                        if (!FileModificationService.getInstance().preparePsiElementsForWrite(referenceExpression)) {
                            return;
                        }
                        final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
                        final PsiReferenceExpression qualified = (PsiReferenceExpression) elementFactory.createExpressionFromText("xxx." + referenceExpression.getText(), referenceExpression);
                        final PsiReferenceExpression newReference = (PsiReferenceExpression) referenceExpression.replace(qualified);
                        final PsiReferenceExpression qualifier = (PsiReferenceExpression) newReference.getQualifierExpression();
                        assert qualifier != null : DebugUtil.psiToString(newReference, false);
                        final PsiClass containingClass = field.getContainingClass();
                        qualifier.bindToElement(containingClass);
                    };
                    invokeWriteAction(runnable, file);
                }
            }
            final Runnable runnable = () -> {
                PsiClassType classType = JavaPsiFacade.getInstance(project).getElementFactory().createType(iface);
                IntentionAction fix = QuickFixFactory.getInstance().createExtendsListFix(implementingClass, classType, false);
                fix.invoke(project, null, file);
            };
            invokeWriteAction(runnable, file);
        }
    });
}
Also used : Task(com.intellij.openapi.progress.Task) Query(com.intellij.util.Query) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) SearchScope(com.intellij.psi.search.SearchScope) Computable(com.intellij.openapi.util.Computable)

Example 5 with Query

use of com.intellij.util.Query 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

Query (com.intellij.util.Query)5 Processor (com.intellij.util.Processor)3 ProgressManager (com.intellij.openapi.progress.ProgressManager)2 Project (com.intellij.openapi.project.Project)2 PsiClass (com.intellij.psi.PsiClass)2 SearchScope (com.intellij.psi.search.SearchScope)2 ReferencesSearch (com.intellij.psi.search.searches.ReferencesSearch)2 NotNull (org.jetbrains.annotations.NotNull)2 ComponentDefinition (com.android.tools.idea.editors.theme.preview.ThemePreviewBuilder.ComponentDefinition)1 ExceptionUtil (com.intellij.codeInsight.ExceptionUtil)1 TargetElementUtil (com.intellij.codeInsight.TargetElementUtil)1 ImplicitUsageProvider (com.intellij.codeInsight.daemon.ImplicitUsageProvider)1 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 QuickFixFactory (com.intellij.codeInsight.intention.QuickFixFactory)1 ImplementedAtRuntimeCondition (com.intellij.codeInspection.inheritance.ImplementedAtRuntimeCondition)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ModalityState (com.intellij.openapi.application.ModalityState)1 WriteAction (com.intellij.openapi.application.WriteAction)1 CommandProcessor (com.intellij.openapi.command.CommandProcessor)1