Search in sources :

Example 1 with ResourceBundleEditorProblemDescriptor

use of com.intellij.lang.properties.editor.inspections.ResourceBundleEditorProblemDescriptor in project intellij-community by JetBrains.

the class UnusedPropertyInspection method buildPropertyGroupVisitor.

@NotNull
@Override
public Function<IProperty[], ResourceBundleEditorProblemDescriptor[]> buildPropertyGroupVisitor(@NotNull ResourceBundle resourceBundle) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(resourceBundle.getDefaultPropertiesFile().getContainingFile());
    if (module == null)
        return x -> null;
    final UnusedPropertiesSearchHelper helper = new UnusedPropertiesSearchHelper(module);
    return properties -> !isPropertyUsed((Property) properties[0], helper, true) ? new ResourceBundleEditorProblemDescriptor[] { new ResourceBundleEditorProblemDescriptor(ProblemHighlightType.LIKE_UNUSED_SYMBOL, PropertiesBundle.message("unused.property.problem.descriptor.name"), new RemovePropertiesFromAllLocalesFix((Property) properties[0])) } : null;
}
Also used : PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ContainerUtil(com.intellij.util.containers.ContainerUtil) Function(java.util.function.Function) ResourceBundleEditorProblemDescriptor(com.intellij.lang.properties.editor.inspections.ResourceBundleEditorProblemDescriptor) Nls(org.jetbrains.annotations.Nls) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) Extensions(com.intellij.openapi.extensions.Extensions) ProgressManager(com.intellij.openapi.progress.ProgressManager) ReferencesSearch(com.intellij.psi.search.searches.ReferencesSearch) Property(com.intellij.lang.properties.psi.Property) PsiSearchHelper(com.intellij.psi.search.PsiSearchHelper) FileModificationService(com.intellij.codeInsight.FileModificationService) PropertySearcher(com.intellij.lang.properties.findUsages.PropertySearcher) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) com.intellij.codeInspection(com.intellij.codeInspection) com.intellij.lang.properties(com.intellij.lang.properties) Objects(java.util.Objects) ASTNode(com.intellij.lang.ASTNode) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) com.intellij.psi(com.intellij.psi) ResourceBundleEditorInspection(com.intellij.lang.properties.editor.inspections.ResourceBundleEditorInspection) NotNull(org.jetbrains.annotations.NotNull) FilteringIterator(com.intellij.util.containers.FilteringIterator) ResourceBundleEditorProblemDescriptor(com.intellij.lang.properties.editor.inspections.ResourceBundleEditorProblemDescriptor) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ResourceBundleEditorProblemDescriptor

use of com.intellij.lang.properties.editor.inspections.ResourceBundleEditorProblemDescriptor in project intellij-community by JetBrains.

the class ResourceBundleEditorShowQuickFixesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final ResourceBundleEditor editor = getEditor(e);
    LOG.assertTrue(editor != null);
    final ResourceBundlePropertyStructureViewElement element = (ResourceBundlePropertyStructureViewElement) editor.getSelectedElementIfOnlyOne();
    LOG.assertTrue(element != null);
    final PsiFile file = editor.getResourceBundle().getDefaultPropertiesFile().getContainingFile();
    final ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo();
    boolean isQuickFixListEmpty = true;
    Pair<ResourceBundleEditorProblemDescriptor, HighlightDisplayKey>[] descriptorsAndSources = element.getProblemDescriptors();
    for (Pair<ResourceBundleEditorProblemDescriptor, HighlightDisplayKey> p : descriptorsAndSources) {
        final ResourceBundleEditorProblemDescriptor d = p.getFirst();
        final HighlightDisplayKey sourceKey = p.getSecond();
        QuickFix[] fixes = d.getFixes();
        if (fixes != null) {
            for (int i = 0; i < fixes.length; i++) {
                intentions.inspectionFixesToShow.add(new HighlightInfo.IntentionActionDescriptor(new RBEQuickFixWrapper(d, i), null, null, AllIcons.Actions.IntentionBulb, sourceKey, null, null));
                isQuickFixListEmpty = false;
            }
        }
    }
    if (isQuickFixListEmpty) {
        return;
    }
    final Project project = e.getProject();
    LOG.assertTrue(project != null);
    JBPopupFactory.getInstance().createListPopup(new IntentionListStep(null, intentions, null, file, project)).showInBestPositionFor(e.getDataContext());
}
Also used : QuickFix(com.intellij.codeInspection.QuickFix) IntentionListStep(com.intellij.codeInsight.intention.impl.IntentionListStep) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) ResourceBundleEditorProblemDescriptor(com.intellij.lang.properties.editor.inspections.ResourceBundleEditorProblemDescriptor) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) Project(com.intellij.openapi.project.Project) ShowIntentionsPass(com.intellij.codeInsight.daemon.impl.ShowIntentionsPass) PsiFile(com.intellij.psi.PsiFile) Pair(com.intellij.openapi.util.Pair)

Aggregations

ResourceBundleEditorProblemDescriptor (com.intellij.lang.properties.editor.inspections.ResourceBundleEditorProblemDescriptor)2 Project (com.intellij.openapi.project.Project)2 FileModificationService (com.intellij.codeInsight.FileModificationService)1 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)1 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 ShowIntentionsPass (com.intellij.codeInsight.daemon.impl.ShowIntentionsPass)1 IntentionListStep (com.intellij.codeInsight.intention.impl.IntentionListStep)1 com.intellij.codeInspection (com.intellij.codeInspection)1 QuickFix (com.intellij.codeInspection.QuickFix)1 ASTNode (com.intellij.lang.ASTNode)1 com.intellij.lang.properties (com.intellij.lang.properties)1 ResourceBundleEditorInspection (com.intellij.lang.properties.editor.inspections.ResourceBundleEditorInspection)1 PropertySearcher (com.intellij.lang.properties.findUsages.PropertySearcher)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 Property (com.intellij.lang.properties.psi.Property)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Extensions (com.intellij.openapi.extensions.Extensions)1 Module (com.intellij.openapi.module.Module)1 ModuleUtilCore (com.intellij.openapi.module.ModuleUtilCore)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1