Search in sources :

Example 16 with IProperty

use of com.intellij.lang.properties.IProperty 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);
        });
    });
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) Property(com.intellij.lang.properties.psi.Property) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DefinitionsScopedSearch(com.intellij.psi.search.searches.DefinitionsScopedSearch) ReadAction(com.intellij.openapi.application.ReadAction) QueryExecutorBase(com.intellij.openapi.application.QueryExecutorBase) Objects(java.util.Objects) IProperty(com.intellij.lang.properties.IProperty) PropertiesImplUtil(com.intellij.lang.properties.PropertiesImplUtil) Processor(com.intellij.util.Processor) PsiElement(com.intellij.psi.PsiElement) PropertiesUtil(com.intellij.lang.properties.PropertiesUtil) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Objects(java.util.Objects) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty) PsiElement(com.intellij.psi.PsiElement)

Example 17 with IProperty

use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.

the class PropertiesFilesSafeDeleteProcessor method findUsages.

@Override
public NonCodeUsageSearchInfo findUsages(@NotNull final PsiElement element, @NotNull final PsiElement[] allElementsToDelete, @NotNull final List<UsageInfo> result) {
    PropertiesFile file = (PropertiesFile) element;
    List<PsiElement> elements = new ArrayList<>();
    elements.add(file.getContainingFile());
    for (IProperty property : file.getProperties()) {
        elements.add(property.getPsiElement());
    }
    for (PsiElement psiElement : elements) {
        SafeDeleteProcessor.findGenericElementUsages(psiElement, result, allElementsToDelete);
    }
    return new NonCodeUsageSearchInfo(SafeDeleteProcessor.getDefaultInsideDeletedCondition(allElementsToDelete), elements);
}
Also used : IProperty(com.intellij.lang.properties.IProperty) ArrayList(java.util.ArrayList) NonCodeUsageSearchInfo(com.intellij.refactoring.safeDelete.NonCodeUsageSearchInfo) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PsiElement(com.intellij.psi.PsiElement)

Example 18 with IProperty

use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.

the class PropertyKeysSafeDeleteProcessor method getAdditionalElementsToDelete.

@Nullable
@Override
public Collection<PsiElement> getAdditionalElementsToDelete(@NotNull PsiElement element, @NotNull Collection<PsiElement> allElementsToDelete, boolean askUser) {
    final IProperty property = (IProperty) element;
    final String key = property.getKey();
    if (key == null) {
        return null;
    }
    final PropertiesFile file = property.getPropertiesFile();
    if (file == null) {
        return null;
    }
    final List<PsiElement> result = new ArrayList<>();
    for (PropertiesFile propertiesFile : file.getResourceBundle().getPropertiesFiles()) {
        for (IProperty p : propertiesFile.findPropertiesByKey(key)) {
            final PsiElement propertyElement = p.getPsiElement();
            if (!allElementsToDelete.contains(propertyElement)) {
                result.add(propertyElement);
            }
        }
    }
    return result;
}
Also used : IProperty(com.intellij.lang.properties.IProperty) ArrayList(java.util.ArrayList) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with IProperty

use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.

the class RenamePropertyProcessor method prepareRenaming.

@Override
public void prepareRenaming(final PsiElement element, final String newName, final Map<PsiElement, String> allRenames) {
    ResourceBundle resourceBundle = PropertiesImplUtil.getProperty(element).getPropertiesFile().getResourceBundle();
    final Map<PsiElement, String> allRenamesCopy = new LinkedHashMap<>(allRenames);
    allRenames.clear();
    allRenamesCopy.forEach((key, value) -> {
        final IProperty property = PropertiesImplUtil.getProperty(key);
        final List<IProperty> properties = PropertiesUtil.findAllProperties(resourceBundle, property.getUnescapedKey());
        for (final IProperty toRename : properties) {
            allRenames.put(toRename.getPsiElement(), value);
        }
    });
}
Also used : IProperty(com.intellij.lang.properties.IProperty) ResourceBundle(com.intellij.lang.properties.ResourceBundle) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PsiElement(com.intellij.psi.PsiElement) LinkedHashMap(java.util.LinkedHashMap)

Example 20 with IProperty

use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.

the class ResourceBundleEditor method reinitSettings.

private void reinitSettings(final EditorEx editor) {
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    editor.setColorsScheme(scheme);
    editor.setBorder(BorderFactory.createLineBorder(JBColor.border(), 1));
    EditorSettings settings = editor.getSettings();
    settings.setLineNumbersShown(false);
    settings.setWhitespacesShown(false);
    settings.setLineMarkerAreaShown(false);
    settings.setIndentGuidesShown(false);
    settings.setFoldingOutlineShown(false);
    settings.setAdditionalColumnsCount(0);
    settings.setAdditionalLinesCount(0);
    settings.setRightMarginShown(true);
    settings.setRightMargin(60);
    settings.setVirtualSpace(false);
    editor.setHighlighter(new LexerEditorHighlighter(new PropertiesValueHighlighter(), scheme));
    editor.setVerticalScrollbarVisible(true);
    // disabling default context menu
    editor.setContextMenuGroupId(null);
    editor.addEditorMouseListener(new EditorPopupHandler() {

        @Override
        public void invokePopup(EditorMouseEvent event) {
            if (!event.isConsumed() && event.getArea() == EditorMouseEventArea.EDITING_AREA) {
                DefaultActionGroup group = new DefaultActionGroup();
                group.add(CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_CUT_COPY_PASTE));
                group.add(CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.ACTION_EDIT_SOURCE));
                group.addSeparator();
                group.add(new AnAction("Propagate Value Across of Resource Bundle") {

                    @Override
                    public void actionPerformed(AnActionEvent e) {
                        final String valueToPropagate = editor.getDocument().getText();
                        final String currentSelectedProperty = getSelectedPropertyName();
                        if (currentSelectedProperty == null) {
                            return;
                        }
                        ApplicationManager.getApplication().runWriteAction(() -> WriteCommandAction.runWriteCommandAction(myProject, () -> {
                            try {
                                final PropertiesFile[] propertiesFiles = myResourceBundle.getPropertiesFiles().stream().filter(f -> {
                                    final IProperty property = f.findPropertyByKey(currentSelectedProperty);
                                    return property == null || !valueToPropagate.equals(property.getValue());
                                }).toArray(PropertiesFile[]::new);
                                final PsiFile[] filesToPrepare = Arrays.stream(propertiesFiles).map(PropertiesFile::getContainingFile).toArray(PsiFile[]::new);
                                if (FileModificationService.getInstance().preparePsiElementsForWrite(filesToPrepare)) {
                                    for (PropertiesFile file : propertiesFiles) {
                                        myPropertiesInsertDeleteManager.insertOrUpdateTranslation(currentSelectedProperty, valueToPropagate, file);
                                    }
                                    recreateEditorsPanel();
                                }
                            } catch (final IncorrectOperationException e1) {
                                LOG.error(e1);
                            }
                        }));
                    }
                });
                EditorPopupHandler handler = EditorActionUtil.createEditorPopupHandler(group);
                handler.invokePopup(event);
                event.consume();
            }
        }
    });
}
Also used : EditorPopupHandler(com.intellij.util.EditorPopupHandler) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) IProperty(com.intellij.lang.properties.IProperty) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Aggregations

IProperty (com.intellij.lang.properties.IProperty)75 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)45 PsiElement (com.intellij.psi.PsiElement)17 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 PsiFile (com.intellij.psi.PsiFile)13 NotNull (org.jetbrains.annotations.NotNull)13 Property (com.intellij.lang.properties.psi.Property)11 Project (com.intellij.openapi.project.Project)7 ArrayList (java.util.ArrayList)7 Nullable (org.jetbrains.annotations.Nullable)7 ResourceBundle (com.intellij.lang.properties.ResourceBundle)6 THashSet (gnu.trove.THashSet)6 XmlPropertiesFile (com.intellij.lang.properties.xml.XmlPropertiesFile)4 Module (com.intellij.openapi.module.Module)4 Collections (java.util.Collections)4 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)3 PropertiesImplUtil (com.intellij.lang.properties.PropertiesImplUtil)3 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)2 XmlProperty (com.intellij.lang.properties.xml.XmlProperty)2 Logger (com.intellij.openapi.diagnostic.Logger)2