Search in sources :

Example 51 with PropertiesFile

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

the class PropertiesReferenceManager method processFile.

private boolean processFile(VirtualFile file, BundleNameEvaluator evaluator, PropertiesFileProcessor processor) {
    final PsiFile psiFile = myPsiManager.findFile(file);
    PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(psiFile);
    if (propertiesFile != null) {
        final String qName = evaluator.evaluateBundleName(psiFile);
        if (qName != null) {
            if (!processor.process(qName, propertiesFile))
                return false;
        }
    }
    return true;
}
Also used : PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 52 with PropertiesFile

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

the class ResourceBundleManager method dissociateResourceBundle.

public void dissociateResourceBundle(@NotNull final ResourceBundle resourceBundle) {
    closeResourceBundleEditors(resourceBundle);
    if (resourceBundle instanceof CustomResourceBundle) {
        final CustomResourceBundleState state = getCustomResourceBundleState(resourceBundle.getDefaultPropertiesFile().getVirtualFile());
        LOG.assertTrue(state != null);
        myState.getCustomResourceBundles().remove(state);
    } else {
        if (EmptyResourceBundle.getInstance() != resourceBundle) {
            ((ResourceBundleImpl) resourceBundle).invalidate();
        }
        for (final PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
            final VirtualFile file = propertiesFile.getContainingFile().getVirtualFile();
            myState.getDissociatedFiles().add(file.getUrl());
        }
    }
}
Also used : ResourceBundleAsVirtualFile(com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 53 with PropertiesFile

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

the class ResourceBundleFileStructureViewElement method getChildrenIdShowOnlyIncomplete.

private static MultiMap<String, IProperty> getChildrenIdShowOnlyIncomplete(ResourceBundle resourceBundle) {
    final MultiMap<String, IProperty> propertyNames = MultiMap.createLinked();
    TObjectIntHashMap<String> occurrences = new TObjectIntHashMap<>();
    for (PropertiesFile file : resourceBundle.getPropertiesFiles()) {
        MultiMap<String, IProperty> currentFilePropertyNames = MultiMap.createLinked();
        for (IProperty property : file.getProperties()) {
            String name = property.getKey();
            currentFilePropertyNames.putValue(name, property);
        }
        propertyNames.putAllValues(currentFilePropertyNames);
        for (String propertyName : currentFilePropertyNames.keySet()) {
            if (occurrences.contains(propertyName)) {
                occurrences.adjustValue(propertyName, 1);
            } else {
                occurrences.put(propertyName, 1);
            }
        }
    }
    final int targetOccurrences = resourceBundle.getPropertiesFiles().size();
    occurrences.forEachEntry(new TObjectIntProcedure<String>() {

        @Override
        public boolean execute(String propertyName, int occurrences) {
            if (occurrences == targetOccurrences) {
                propertyNames.remove(propertyName);
            }
            return true;
        }
    });
    return propertyNames;
}
Also used : IProperty(com.intellij.lang.properties.IProperty) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 54 with PropertiesFile

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

the class PropertiesSeparatorManager method guessSeparator.

//returns most probable separator in properties files
private static String guessSeparator(final ResourceBundleImpl resourceBundle) {
    final TIntLongHashMap charCounts = new TIntLongHashMap();
    for (PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
        if (propertiesFile == null)
            continue;
        List<IProperty> properties = propertiesFile.getProperties();
        for (IProperty property : properties) {
            String key = property.getUnescapedKey();
            if (key == null)
                continue;
            for (int i = 0; i < key.length(); i++) {
                char c = key.charAt(i);
                if (!Character.isLetterOrDigit(c)) {
                    charCounts.put(c, charCounts.get(c) + 1);
                }
            }
        }
    }
    final char[] mostProbableChar = new char[] { '.' };
    charCounts.forEachKey(new TIntProcedure() {

        long count = -1;

        public boolean execute(int ch) {
            long charCount = charCounts.get(ch);
            if (charCount > count) {
                count = charCount;
                mostProbableChar[0] = (char) ch;
            }
            return true;
        }
    });
    if (mostProbableChar[0] == 0) {
        mostProbableChar[0] = '.';
    }
    return Character.toString(mostProbableChar[0]);
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) TIntLongHashMap(gnu.trove.TIntLongHashMap) IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 55 with PropertiesFile

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

the class ResourcesFavoriteNodeProvider method isInvalidElement.

@Override
public boolean isInvalidElement(final Object element) {
    if (element instanceof ResourceBundle) {
        ResourceBundle resourceBundle = (ResourceBundle) element;
        List<PropertiesFile> propertiesFiles = resourceBundle.getPropertiesFiles();
        if (propertiesFiles.size() == 1) {
            //todo result.add(new PsiFileNode(myProject, propertiesFiles.iterator().next(), this));
            return true;
        }
    }
    return false;
}
Also used : ResourceBundle(com.intellij.lang.properties.ResourceBundle) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

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