Search in sources :

Example 1 with PropertiesFileProcessor

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

the class I18nUtil method defaultSuggestPropertiesFiles.

public static List<String> defaultSuggestPropertiesFiles(Project project) {
    final List<String> paths = new ArrayList<>();
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    PropertiesReferenceManager.getInstance(project).processAllPropertiesFiles(new PropertiesFileProcessor() {

        @Override
        public boolean process(String baseName, PropertiesFile propertiesFile) {
            if (propertiesFile instanceof XmlPropertiesFile) {
                return true;
            }
            VirtualFile virtualFile = propertiesFile.getVirtualFile();
            if (projectFileIndex.isInContent(virtualFile)) {
                String path = FileUtil.toSystemDependentName(virtualFile.getPath());
                paths.add(path);
            }
            return true;
        }
    });
    return paths;
}
Also used : XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PropertiesFileProcessor(com.intellij.lang.properties.PropertiesFileProcessor) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) ArrayList(java.util.ArrayList) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile)

Example 2 with PropertiesFileProcessor

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

the class PropertiesPsiCompletionUtil method getPropertiesKeys.

static Set<Object> getPropertiesKeys(final PropertyReferenceBase propertyReference) {
    final Set<Object> variants = new THashSet<>(new TObjectHashingStrategy<Object>() {

        public int computeHashCode(final Object object) {
            if (object instanceof IProperty) {
                final String key = ((IProperty) object).getKey();
                return key == null ? 0 : key.hashCode();
            } else {
                return 0;
            }
        }

        public boolean equals(final Object o1, final Object o2) {
            return o1 instanceof IProperty && o2 instanceof IProperty && Comparing.equal(((IProperty) o1).getKey(), ((IProperty) o2).getKey(), true);
        }
    });
    List<PropertiesFile> propertiesFileList = propertyReference.getPropertiesFiles();
    if (propertiesFileList == null) {
        PropertiesReferenceManager.getInstance(propertyReference.getElement().getProject()).processAllPropertiesFiles(new PropertiesFileProcessor() {

            @Override
            public boolean process(String baseName, PropertiesFile propertiesFile) {
                addVariantsFromFile(propertyReference, propertiesFile, variants);
                return true;
            }
        });
    } else {
        for (PropertiesFile propFile : propertiesFileList) {
            addVariantsFromFile(propertyReference, propFile, variants);
        }
    }
    return variants;
}
Also used : PropertiesFileProcessor(com.intellij.lang.properties.PropertiesFileProcessor) IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) THashSet(gnu.trove.THashSet)

Aggregations

PropertiesFileProcessor (com.intellij.lang.properties.PropertiesFileProcessor)2 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)2 IProperty (com.intellij.lang.properties.IProperty)1 XmlPropertiesFile (com.intellij.lang.properties.xml.XmlPropertiesFile)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 THashSet (gnu.trove.THashSet)1 ArrayList (java.util.ArrayList)1