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));
}
}
};
}
use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class ResourcesFavoriteNodeProvider method elementContainsFile.
@Override
public boolean elementContainsFile(final Object element, final VirtualFile vFile) {
if (element instanceof ResourceBundle) {
ResourceBundle bundle = (ResourceBundle) element;
final List<PropertiesFile> propertiesFiles = bundle.getPropertiesFiles();
for (PropertiesFile file : propertiesFiles) {
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null)
continue;
if (vFile.getPath().equals(virtualFile.getPath())) {
return true;
}
}
}
return false;
}
use of com.intellij.lang.properties.ResourceBundle in project intellij-community by JetBrains.
the class ResourcesFavoriteNodeProvider method getFavoriteNodes.
@Override
public Collection<AbstractTreeNode> getFavoriteNodes(final DataContext context, final ViewSettings viewSettings) {
final Project project = CommonDataKeys.PROJECT.getData(context);
if (project == null) {
return null;
}
final ResourceBundle[] resourceBundles = ResourceBundle.ARRAY_DATA_KEY.getData(context);
//on bundles nodes
if (resourceBundles != null) {
final Collection<AbstractTreeNode> result = new ArrayList<>();
for (ResourceBundle bundle : resourceBundles) {
result.add(new ResourceBundleNode(project, bundle, viewSettings));
}
return result;
}
return null;
}
Aggregations