Search in sources :

Example 26 with ResourceBundle

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();
    }
}
Also used : Project(com.intellij.openapi.project.Project) ResourceBundleManager(com.intellij.lang.properties.ResourceBundleManager) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle) ResourceBundleAsVirtualFile(com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)

Example 27 with ResourceBundle

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);
}
Also used : Project(com.intellij.openapi.project.Project) ResourceBundle(com.intellij.lang.properties.ResourceBundle)

Example 28 with ResourceBundle

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");
    });
}
Also used : Property(com.intellij.lang.properties.psi.Property) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) DataContext(com.intellij.openapi.actionSystem.DataContext) Collection(java.util.Collection) NullableFunction(com.intellij.util.NullableFunction) ContainerUtil(com.intellij.util.containers.ContainerUtil) FileEditor(com.intellij.openapi.fileEditor.FileEditor) GotoRelatedProvider(com.intellij.navigation.GotoRelatedProvider) List(java.util.List) IProperty(com.intellij.lang.properties.IProperty) PlatformDataKeys(com.intellij.openapi.actionSystem.PlatformDataKeys) PropertiesImplUtil(com.intellij.lang.properties.PropertiesImplUtil) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) ResourceBundle(com.intellij.lang.properties.ResourceBundle) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) FileEditor(com.intellij.openapi.fileEditor.FileEditor) IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with ResourceBundle

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();
    }
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with ResourceBundle

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));
            }
        }
    };
}
Also used : PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) PropertiesFileImpl(com.intellij.lang.properties.psi.impl.PropertiesFileImpl) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ResourceBundle (com.intellij.lang.properties.ResourceBundle)32 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)20 Project (com.intellij.openapi.project.Project)11 NotNull (org.jetbrains.annotations.NotNull)10 PsiFile (com.intellij.psi.PsiFile)9 PsiElement (com.intellij.psi.PsiElement)7 IProperty (com.intellij.lang.properties.IProperty)6 FileEditor (com.intellij.openapi.fileEditor.FileEditor)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ContainerUtil (com.intellij.util.containers.ContainerUtil)4 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)3 ResourceBundleAsVirtualFile (com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)3 HashSet (com.intellij.util.containers.HashSet)3 com.intellij.lang.properties (com.intellij.lang.properties)2 PropertiesImplUtil (com.intellij.lang.properties.PropertiesImplUtil)2 ResourceBundleNode (com.intellij.lang.properties.projectView.ResourceBundleNode)2 XmlPropertiesFile (com.intellij.lang.properties.xml.XmlPropertiesFile)2 GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)2 Logger (com.intellij.openapi.diagnostic.Logger)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2