Search in sources :

Example 21 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 22 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 23 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)

Example 24 with ResourceBundle

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 25 with ResourceBundle

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;
}
Also used : ResourceBundleNode(com.intellij.lang.properties.projectView.ResourceBundleNode) Project(com.intellij.openapi.project.Project) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ResourceBundle(com.intellij.lang.properties.ResourceBundle)

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