Search in sources :

Example 21 with PropertiesFile

use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.

the class FormEditingUtil method collectUsedLocales.

public static Locale[] collectUsedLocales(final Module module, final IRootContainer rootContainer) {
    final Set<Locale> locales = new HashSet<>();
    final PropertiesReferenceManager propManager = PropertiesReferenceManager.getInstance(module.getProject());
    for (String bundleName : collectUsedBundleNames(rootContainer)) {
        List<PropertiesFile> propFiles = propManager.findPropertiesFiles(module, bundleName.replace('/', '.'));
        for (PropertiesFile propFile : propFiles) {
            locales.add(propFile.getLocale());
        }
    }
    return locales.toArray(new Locale[locales.size()]);
}
Also used : PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PropertiesReferenceManager(com.intellij.lang.properties.PropertiesReferenceManager) HashSet(com.intellij.util.containers.HashSet)

Example 22 with PropertiesFile

use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.

the class StringDescriptorManager method resolveToProperty.

public IProperty resolveToProperty(@NotNull StringDescriptor descriptor, @Nullable Locale locale) {
    String propFileName = descriptor.getDottedBundleName();
    Pair<Locale, String> cacheKey = Pair.create(locale, propFileName);
    PropertiesFile propertiesFile;
    synchronized (myPropertiesFileCache) {
        propertiesFile = myPropertiesFileCache.get(cacheKey);
    }
    if (propertiesFile == null || !propertiesFile.getContainingFile().isValid()) {
        propertiesFile = PropertiesUtilBase.getPropertiesFile(propFileName, myModule, locale);
        synchronized (myPropertiesFileCache) {
            myPropertiesFileCache.put(cacheKey, propertiesFile);
        }
    }
    if (propertiesFile != null) {
        final IProperty propertyByKey = propertiesFile.findPropertyByKey(descriptor.getKey());
        if (propertyByKey != null) {
            return propertyByKey;
        }
    }
    return null;
}
Also used : Locale(java.util.Locale) IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 23 with PropertiesFile

use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.

the class ResourceBundleReference method getVariants.

@Override
@NotNull
public Object[] getVariants() {
    final ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(getElement().getProject());
    final PropertiesReferenceManager referenceManager = PropertiesReferenceManager.getInstance(getElement().getProject());
    final Set<String> bundleNames = new HashSet<>();
    final List<LookupElement> variants = new SmartList<>();
    PropertiesFileProcessor processor = new PropertiesFileProcessor() {

        @Override
        public boolean process(String baseName, PropertiesFile propertiesFile) {
            if (!bundleNames.add(baseName))
                return true;
            final LookupElementBuilder builder = LookupElementBuilder.create(baseName).withIcon(AllIcons.Nodes.ResourceBundle);
            boolean isInContent = projectFileIndex.isInContent(propertiesFile.getVirtualFile());
            variants.add(isInContent ? PrioritizedLookupElement.withPriority(builder, Double.MAX_VALUE) : builder);
            return true;
        }
    };
    referenceManager.processPropertiesFiles(myElement.getResolveScope(), processor, this);
    return variants.toArray(new LookupElement[variants.size()]);
}
Also used : ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) SmartList(com.intellij.util.SmartList) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PrioritizedLookupElement(com.intellij.codeInsight.completion.PrioritizedLookupElement) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with PropertiesFile

use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.

the class CreateResourceBundleDialogComponent method canCreateAllFilesForAllLocales.

private String canCreateAllFilesForAllLocales() {
    final String name = getBaseName();
    if (name.isEmpty()) {
        return "Base name is empty";
    }
    final Set<String> files = getFileNamesToCreate();
    if (files.isEmpty()) {
        return "No locales added";
    }
    for (PsiElement element : myDirectory.getChildren()) {
        if (element instanceof PsiFile) {
            if (element instanceof PropertiesFile) {
                PropertiesFile propertiesFile = (PropertiesFile) element;
                final String propertiesFileName = propertiesFile.getName();
                if (files.contains(propertiesFileName)) {
                    return "Some of files already exist";
                }
            }
        }
    }
    return null;
}
Also used : PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) PsiElement(com.intellij.psi.PsiElement)

Example 25 with PropertiesFile

use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.

the class CreateResourceBundleDialogComponent method combineToResourceBundleIfNeed.

private void combineToResourceBundleIfNeed(Collection<PsiFile> files) {
    Collection<PropertiesFile> createdFiles = ContainerUtil.map(files, (NotNullFunction<PsiFile, PropertiesFile>) dom -> {
        final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(dom);
        LOG.assertTrue(file != null, dom.getName());
        return file;
    });
    ResourceBundle mainBundle = myResourceBundle;
    final Set<ResourceBundle> allBundles = new HashSet<>();
    if (mainBundle != null) {
        allBundles.add(mainBundle);
    }
    boolean needCombining = false;
    for (PropertiesFile file : createdFiles) {
        final ResourceBundle rb = file.getResourceBundle();
        if (mainBundle == null) {
            mainBundle = rb;
        } else if (!mainBundle.equals(rb)) {
            needCombining = true;
        }
        allBundles.add(rb);
    }
    if (needCombining) {
        final List<PropertiesFile> toCombine = new ArrayList<>(createdFiles);
        final String baseName = getBaseName();
        if (myResourceBundle != null) {
            toCombine.addAll(myResourceBundle.getPropertiesFiles());
        }
        ResourceBundleManager manager = ResourceBundleManager.getInstance(mainBundle.getProject());
        for (ResourceBundle bundle : allBundles) {
            manager.dissociateResourceBundle(bundle);
        }
        manager.combineToResourceBundle(toCombine, baseName);
    }
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) java.util(java.util) AllIcons(com.intellij.icons.AllIcons) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Computable(com.intellij.openapi.util.Computable) ContainerUtil(com.intellij.util.containers.ContainerUtil) ReadAction(com.intellij.openapi.application.ReadAction) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) ListSelectionEvent(javax.swing.event.ListSelectionEvent) InputValidatorEx(com.intellij.openapi.ui.InputValidatorEx) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) JBList(com.intellij.ui.components.JBList) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) NotNullFunction(com.intellij.util.NotNullFunction) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) com.intellij.ui(com.intellij.ui) com.intellij.lang.properties(com.intellij.lang.properties) Nullable(org.jetbrains.annotations.Nullable) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) java.awt.event(java.awt.event) FileTemplateUtil(com.intellij.ide.fileTemplates.FileTemplateUtil) PsiDirectory(com.intellij.psi.PsiDirectory) PathUtil(com.intellij.util.PathUtil) NotNull(org.jetbrains.annotations.NotNull) ListSelectionListener(javax.swing.event.ListSelectionListener) javax.swing(javax.swing) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle)

Aggregations

PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)143 IProperty (com.intellij.lang.properties.IProperty)44 PsiFile (com.intellij.psi.PsiFile)42 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 ResourceBundle (com.intellij.lang.properties.ResourceBundle)19 PsiElement (com.intellij.psi.PsiElement)19 NotNull (org.jetbrains.annotations.NotNull)19 Nullable (org.jetbrains.annotations.Nullable)18 Property (com.intellij.lang.properties.psi.Property)15 Project (com.intellij.openapi.project.Project)10 XmlPropertiesFile (com.intellij.lang.properties.xml.XmlPropertiesFile)9 PsiDirectory (com.intellij.psi.PsiDirectory)8 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 THashSet (gnu.trove.THashSet)8 ArrayList (java.util.ArrayList)7 Module (com.intellij.openapi.module.Module)6 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)6 HashSet (com.intellij.util.containers.HashSet)6 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)5 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)5