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);
});
});
}
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);
}
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;
}
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);
}
});
}
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();
}
}
});
}
Aggregations