Search in sources :

Example 6 with IProperty

use of com.intellij.lang.properties.IProperty 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 7 with IProperty

use of com.intellij.lang.properties.IProperty 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 8 with IProperty

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

the class XmlPropertiesFileImpl method addProperty.

@NotNull
@Override
public IProperty addProperty(String key, String value) {
    final XmlTag entry = createPropertyTag(key, value);
    synchronized (myLock) {
        ensurePropertiesLoaded();
        if (myAlphaSorted) {
            final XmlProperty dummyProperty = new XmlProperty(entry, this);
            final int insertIndex = Collections.binarySearch(myProperties, dummyProperty, (p1, p2) -> {
                final String k1 = p1.getKey();
                final String k2 = p2.getKey();
                return k1.compareTo(k2);
            });
            final IProperty insertPosition;
            final IProperty inserted;
            if (insertIndex == -1) {
                inserted = addPropertyAfter(key, value, null, false);
                myProperties.add(0, inserted);
            } else {
                final int position = insertIndex < 0 ? -insertIndex - 2 : insertIndex;
                insertPosition = myProperties.get(position);
                inserted = addPropertyAfter(key, value, insertPosition, false);
                myProperties.add(position + 1, inserted);
            }
            return inserted;
        } else {
            return addPropertyAfter(key, value, null, true);
        }
    }
}
Also used : IProperty(com.intellij.lang.properties.IProperty) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with IProperty

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

the class I18nUtil method createProperty.

public static void createProperty(final Project project, final Collection<PropertiesFile> propertiesFiles, final String key, final String value) throws IncorrectOperationException {
    for (PropertiesFile file : propertiesFiles) {
        PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
        documentManager.commitDocument(documentManager.getDocument(file.getContainingFile()));
        IProperty existingProperty = file.findPropertyByKey(key);
        if (existingProperty == null) {
            file.addProperty(key, value);
        }
    }
}
Also used : IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 10 with IProperty

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

the class PropertyReferenceBase method getResolveResults.

protected static ResolveResult[] getResolveResults(List<IProperty> properties) {
    if (properties.isEmpty())
        return ResolveResult.EMPTY_ARRAY;
    final ResolveResult[] results = new ResolveResult[properties.size()];
    for (int i = 0; i < properties.size(); i++) {
        IProperty property = properties.get(i);
        results[i] = new PsiElementResolveResult(property instanceof PsiElement ? (PsiElement) property : PomService.convertToPsi((PsiTarget) property));
    }
    return results;
}
Also used : IProperty(com.intellij.lang.properties.IProperty) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement)

Aggregations

IProperty (com.intellij.lang.properties.IProperty)75 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)45 PsiElement (com.intellij.psi.PsiElement)17 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 PsiFile (com.intellij.psi.PsiFile)13 NotNull (org.jetbrains.annotations.NotNull)13 Property (com.intellij.lang.properties.psi.Property)11 Project (com.intellij.openapi.project.Project)7 ArrayList (java.util.ArrayList)7 Nullable (org.jetbrains.annotations.Nullable)7 ResourceBundle (com.intellij.lang.properties.ResourceBundle)6 THashSet (gnu.trove.THashSet)6 XmlPropertiesFile (com.intellij.lang.properties.xml.XmlPropertiesFile)4 Module (com.intellij.openapi.module.Module)4 Collections (java.util.Collections)4 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)3 PropertiesImplUtil (com.intellij.lang.properties.PropertiesImplUtil)3 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)2 XmlProperty (com.intellij.lang.properties.xml.XmlProperty)2 Logger (com.intellij.openapi.diagnostic.Logger)2