use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class ResourceBundleNode method extractPropertiesFileFromNode.
@Nullable
private static PropertiesFile extractPropertiesFileFromNode(TreeNode node) {
if (!(node instanceof DefaultMutableTreeNode))
return null;
final Object userObject = ((DefaultMutableTreeNode) node).getUserObject();
if (!(userObject instanceof PsiFileNode))
return null;
final PsiFile file = ((PsiFileNode) userObject).getValue();
final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
if (propertiesFile == null || !file.getManager().isInProject(file) || !file.isValid())
return null;
return propertiesFile;
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class ResourceBundleNode method drop.
@Override
public void drop(TreeNode[] sourceNodes, DataContext dataContext) {
MultiMap<ResourceBundle, PropertiesFile> bundleGrouping = new MultiMap<>();
for (TreeNode sourceNode : sourceNodes) {
final PropertiesFile propertiesFile = extractPropertiesFileFromNode(sourceNode);
if (propertiesFile == null)
return;
bundleGrouping.putValue(propertiesFile.getResourceBundle(), propertiesFile);
}
final ResourceBundle resourceBundle = ObjectUtils.notNull(getValue());
bundleGrouping.remove(resourceBundle);
final ResourceBundleManager resourceBundleManager = ResourceBundleManager.getInstance(myProject);
final List<PropertiesFile> toAddInResourceBundle = new ArrayList<>();
for (Map.Entry<ResourceBundle, Collection<PropertiesFile>> entry : bundleGrouping.entrySet()) {
toAddInResourceBundle.addAll(entry.getValue());
final ResourceBundle currentBundle = entry.getKey();
final Collection<PropertiesFile> propertiesFilesToMove = entry.getValue();
if (currentBundle.getPropertiesFiles().size() - propertiesFilesToMove.size() > 0) {
final String currentBundleBaseName = currentBundle.getBaseName();
final ArrayList<PropertiesFile> files = new ArrayList<>(currentBundle.getPropertiesFiles());
files.removeAll(propertiesFilesToMove);
resourceBundleManager.dissociateResourceBundle(currentBundle);
resourceBundleManager.combineToResourceBundle(files, currentBundleBaseName);
}
}
toAddInResourceBundle.addAll(resourceBundle.getPropertiesFiles());
final String baseName = resourceBundle.getBaseName();
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(getProject());
fileEditorManager.closeFile(new ResourceBundleAsVirtualFile(resourceBundle));
resourceBundleManager.dissociateResourceBundle(resourceBundle);
final ResourceBundle updatedBundle = resourceBundleManager.combineToResourceBundleAndGet(toAddInResourceBundle, baseName);
FileEditorManager.getInstance(getProject()).openFile(new ResourceBundleAsVirtualFile(updatedBundle), true);
ProjectView.getInstance(getProject()).refresh();
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class ResourceBundleNode method contains.
@Override
public boolean contains(@NotNull VirtualFile file) {
if (!file.isValid())
return false;
PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);
PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(psiFile);
return propertiesFile != null && ObjectUtils.notNull(getValue()).getPropertiesFiles().contains(propertiesFile);
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class CustomResourceBundleTest method testPropertiesFilesDefaultCombiningToResourceBundle.
public void testPropertiesFilesDefaultCombiningToResourceBundle() {
final PsiFile file = myFixture.addFileToProject("prop_core_en.properties", "");
final PsiFile file2 = myFixture.addFileToProject("prop_core_fi.properties", "");
final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
final PropertiesFile propertiesFile2 = PropertiesImplUtil.getPropertiesFile(file2);
assertNotNull(propertiesFile);
assertNotNull(propertiesFile2);
final ResourceBundle bundle = propertiesFile.getResourceBundle();
final ResourceBundle bundle2 = propertiesFile2.getResourceBundle();
assertTrue(bundle.equals(bundle2));
assertSize(2, bundle.getPropertiesFiles());
assertTrue(bundle.getDefaultPropertiesFile().equals(bundle2.getDefaultPropertiesFile()));
assertEquals("prop_core", bundle.getBaseName());
assertNotSame(propertiesFile.getLocale().getLanguage(), propertiesFile.getLocale().getDisplayLanguage());
assertNotSame(propertiesFile2.getLocale().getLanguage(), propertiesFile2.getLocale().getDisplayLanguage());
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class CustomResourceBundleTest method testCombineToCustomResourceBundleAndDissociateAfter.
public void testCombineToCustomResourceBundleAndDissociateAfter() {
final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(myFixture.addFileToProject("resources-dev/my-app-dev.properties", ""));
final PropertiesFile file2 = PropertiesImplUtil.getPropertiesFile(myFixture.addFileToProject("resources-prod/my-app-prod.properties", ""));
assertNotNull(file);
assertNotNull(file2);
assertOneElement(file.getResourceBundle().getPropertiesFiles());
assertOneElement(file2.getResourceBundle().getPropertiesFiles());
final ResourceBundleManager resourceBundleBaseNameManager = ResourceBundleManager.getInstance(getProject());
final String newBaseName = "my-app";
resourceBundleBaseNameManager.combineToResourceBundle(list(file, file2), newBaseName);
final ResourceBundle resourceBundle = file.getResourceBundle();
assertEquals(2, resourceBundle.getPropertiesFiles().size());
assertEquals(newBaseName, resourceBundle.getBaseName());
resourceBundleBaseNameManager.dissociateResourceBundle(resourceBundle);
assertOneElement(file.getResourceBundle().getPropertiesFiles());
assertOneElement(file2.getResourceBundle().getPropertiesFiles());
}
Aggregations