use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class CombinePropertiesFilesAction method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent e) {
final List<PropertiesFile> initialPropertiesFiles = getPropertiesFiles(e);
final List<PropertiesFile> propertiesFiles = initialPropertiesFiles == null ? new ArrayList<>() : new ArrayList<>(initialPropertiesFiles);
final List<ResourceBundle> resourceBundles = getResourceBundles(e);
if (resourceBundles != null) {
for (ResourceBundle bundle : resourceBundles) {
propertiesFiles.addAll(bundle.getPropertiesFiles());
}
}
final String newBaseName = Messages.showInputDialog(propertiesFiles.get(0).getProject(), PropertiesBundle.message("combine.properties.files.prompt.text"), PropertiesBundle.message("combine.properties.files.title"), Messages.getQuestionIcon(), PropertiesUtil.getDefaultBaseName(propertiesFiles), new MyInputValidator(propertiesFiles));
if (newBaseName != null) {
final Project project = propertiesFiles.get(0).getProject();
final Set<ResourceBundle> uniqueBundlesToDissociate = new HashSet<>();
for (PropertiesFile file : propertiesFiles) {
final ResourceBundle resourceBundle = file.getResourceBundle();
if (resourceBundle.getPropertiesFiles().size() != 1) {
uniqueBundlesToDissociate.add(resourceBundle);
}
}
final ResourceBundleManager resourceBundleManager = ResourceBundleManager.getInstance(project);
for (ResourceBundle resourceBundle : uniqueBundlesToDissociate) {
resourceBundleManager.dissociateResourceBundle(resourceBundle);
}
final ResourceBundle resourceBundle = resourceBundleManager.combineToResourceBundleAndGet(propertiesFiles, newBaseName);
FileEditorManager.getInstance(project).openFile(new ResourceBundleAsVirtualFile(resourceBundle), true);
ProjectView.getInstance(project).refresh();
}
}
use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class DissociateResourceBundleAction method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent e) {
final Project project = e.getProject();
if (project == null) {
return;
}
final Collection<ResourceBundle> resourceBundles = extractResourceBundles(e);
assert resourceBundles.size() > 0;
dissociate(resourceBundles, project);
}
use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class GotoPropertyDeclarationsProvider method getItems.
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull DataContext context) {
final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
if (!(editor instanceof ResourceBundleEditor)) {
return Collections.emptyList();
}
final ResourceBundleEditor resourceBundleEditor = (ResourceBundleEditor) editor;
final Collection<ResourceBundleEditorViewElement> elements = resourceBundleEditor.getSelectedElements();
if (elements.size() != 1) {
return Collections.emptyList();
}
final IProperty[] properties = ContainerUtil.getFirstItem(elements).getProperties();
if (properties == null || properties.length != 1 || !(properties[0] instanceof Property)) {
return Collections.emptyList();
}
final IProperty property = properties[0];
final String propertyKey = property.getKey();
final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(property.getPsiElement().getContainingFile());
assert file != null;
final ResourceBundle resourceBundle = file.getResourceBundle();
return ContainerUtil.mapNotNull(resourceBundle.getPropertiesFiles(), (NullableFunction<PropertiesFile, GotoRelatedItem>) f -> {
final IProperty foundProperty = f.findPropertyByKey(propertyKey);
return foundProperty == null ? null : new GotoRelatedItem(foundProperty.getPsiElement(), "Property Declarations");
});
}
use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class GotoResourceBundleLocalizationsProvider method getItems.
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull final DataContext context) {
final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
if (editor instanceof ResourceBundleEditor) {
return Collections.emptyList();
}
final PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(context);
if (psiFile == null || !(psiFile instanceof PropertiesFile)) {
return Collections.emptyList();
}
final ResourceBundle resourceBundle = ((PropertiesFile) psiFile).getResourceBundle();
final List<PropertiesFile> bundlePropertiesFiles = resourceBundle.getPropertiesFiles();
assert bundlePropertiesFiles.size() != 0;
if (bundlePropertiesFiles.size() != 1) {
final ArrayList<PropertiesFile> propertiesFilesWithoutCurrent = ContainerUtil.newArrayList(bundlePropertiesFiles);
propertiesFilesWithoutCurrent.remove(psiFile);
return ContainerUtil.map(propertiesFilesWithoutCurrent, propertiesFile -> new GotoRelatedItem((PsiElement) propertiesFile, "Other Localizations"));
} else {
return Collections.emptyList();
}
}
use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class AlphaUnsortedPropertiesFileInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new PsiElementVisitor() {
@Override
public void visitFile(PsiFile file) {
final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
if (!(propertiesFile instanceof PropertiesFileImpl)) {
return;
}
for (AlphaUnsortedPropertiesFileInspectionSuppressor filter : AlphaUnsortedPropertiesFileInspectionSuppressor.EP_NAME.getExtensions()) {
if (filter.suppressInspectionFor(propertiesFile)) {
return;
}
}
final ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
final String resourceBundleBaseName = resourceBundle.getBaseName();
if (!isResourceBundleAlphaSortedExceptOneFile(resourceBundle, propertiesFile)) {
final List<PropertiesFile> allFiles = resourceBundle.getPropertiesFiles();
holder.registerProblem(file, String.format(MESSAGE_TEMPLATE_WHOLE_RESOURCE_BUNDLE, resourceBundleBaseName), ProblemHighlightType.INFO, new PropertiesSorterQuickFix(true, allFiles.toArray(new PropertiesFile[allFiles.size()])));
return;
}
if (!propertiesFile.isAlphaSorted()) {
holder.registerProblem(file, "Properties file is alphabetically unsorted", ProblemHighlightType.INFO, new PropertiesSorterQuickFix(true, propertiesFile));
}
}
};
}
Aggregations