Search in sources :

Example 71 with IProperty

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

the class ResourceBundleFileStructureViewElement method getPropertiesMap.

public static MultiMap<String, IProperty> getPropertiesMap(ResourceBundle resourceBundle, boolean onlyIncomplete) {
    List<PropertiesFile> propertiesFiles = resourceBundle.getPropertiesFiles();
    final MultiMap<String, IProperty> propertyNames;
    if (onlyIncomplete) {
        propertyNames = getChildrenIdShowOnlyIncomplete(resourceBundle);
    } else {
        propertyNames = MultiMap.createLinked();
        for (PropertiesFile propertiesFile : propertiesFiles) {
            List<IProperty> properties = propertiesFile.getProperties();
            for (IProperty property : properties) {
                String name = property.getKey();
                propertyNames.putValue(name, property);
            }
        }
    }
    return propertyNames;
}
Also used : IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 72 with IProperty

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

the class PropertiesPrefixGroup method getChildren.

@NotNull
public Collection<TreeElement> getChildren() {
    Collection<TreeElement> result = new ArrayList<>();
    List<String> prefixWords = StringUtil.split(myPrefix, mySeparator);
    for (TreeElement treeElement : myProperties) {
        if (!(treeElement instanceof StructureViewTreeElement)) {
            continue;
        }
        Object value = ((StructureViewTreeElement) treeElement).getValue();
        if (!(value instanceof IProperty)) {
            continue;
        }
        final String key = ((IProperty) value).getUnescapedKey();
        if (key == null) {
            continue;
        }
        boolean startsWith;
        if (!key.equals(myPrefix)) {
            List<String> keyWords = StringUtil.split(key, mySeparator);
            startsWith = prefixWords.size() < keyWords.size();
            if (startsWith) {
                for (int i = 0; i < prefixWords.size(); i++) {
                    String prefixWord = prefixWords.get(i);
                    String keyWord = keyWords.get(i);
                    if (!Comparing.strEqual(keyWord, prefixWord)) {
                        startsWith = false;
                        break;
                    }
                }
            }
        } else {
            startsWith = true;
        }
        if (startsWith) {
            result.add(treeElement);
            String presentableName = key.substring(myPrefix.length());
            presentableName = StringUtil.trimStart(presentableName, mySeparator);
            if (treeElement instanceof PropertiesStructureViewElement) {
                ((PropertiesStructureViewElement) treeElement).setPresentableName(presentableName);
            }
            if (treeElement instanceof ResourceBundlePropertyStructureViewElement) {
                ((ResourceBundlePropertyStructureViewElement) treeElement).setPresentableName(presentableName);
            }
        }
    }
    return result;
}
Also used : IProperty(com.intellij.lang.properties.IProperty) ArrayList(java.util.ArrayList) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) ResourceBundlePropertyStructureViewElement(com.intellij.lang.properties.editor.ResourceBundlePropertyStructureViewElement) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) NotNull(org.jetbrains.annotations.NotNull)

Example 73 with IProperty

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

the class XmlPropertiesFileImpl method ensurePropertiesLoaded.

private void ensurePropertiesLoaded() {
    while (myFileModificationStamp != myFile.getModificationStamp() || myPropertiesMap == null) {
        myFileModificationStamp = myFile.getModificationStamp();
        MostlySingularMultiMap<String, IProperty> propertiesMap = new MostlySingularMultiMap<>();
        XmlTag rootTag = myFile.getRootTag();
        final List<IProperty> propertiesOrder = new ArrayList<>();
        if (rootTag != null) {
            XmlTag[] entries = rootTag.findSubTags(ENTRY_TAG_NAME);
            for (XmlTag entry : entries) {
                XmlProperty property = new XmlProperty(entry, this);
                propertiesOrder.add(property);
                final String key = property.getKey();
                if (key != null) {
                    propertiesMap.add(key, property);
                }
            }
        }
        myAlphaSorted = PropertiesImplUtil.isAlphaSorted(propertiesOrder);
        myProperties = propertiesOrder;
        myPropertiesMap = propertiesMap;
    }
}
Also used : IProperty(com.intellij.lang.properties.IProperty) MostlySingularMultiMap(com.intellij.util.containers.MostlySingularMultiMap) XmlTag(com.intellij.psi.xml.XmlTag)

Example 74 with IProperty

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

the class ResourceBundleKeyReference method resolve.

public PsiElement resolve() {
    final Project project = myFile.getProject();
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final VirtualFile formVirtualFile = myFile.getVirtualFile();
    if (formVirtualFile == null) {
        return null;
    }
    final Module module = fileIndex.getModuleForFile(formVirtualFile);
    if (module == null) {
        return null;
    }
    final PropertiesFile propertiesFile = PropertiesUtilBase.getPropertiesFile(myBundleName, module, null);
    if (propertiesFile == null) {
        return null;
    }
    IProperty property = propertiesFile.findPropertyByKey(getRangeText());
    return property == null ? null : property.getPsiElement();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Module(com.intellij.openapi.module.Module)

Example 75 with IProperty

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

the class FormReferencesSearcher method execute.

@Override
public boolean execute(@NotNull final ReferencesSearch.SearchParameters p, @NotNull final Processor<PsiReference> consumer) {
    SearchScope userScope = p.getScopeDeterminedByUser();
    if (!scopeCanContainForms(userScope))
        return true;
    final PsiElement refElement = p.getElementToSearch();
    final PsiFile psiFile = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() {

        @Override
        public PsiFile compute() {
            if (!refElement.isValid())
                return null;
            return refElement.getContainingFile();
        }
    });
    if (psiFile == null)
        return true;
    final VirtualFile virtualFile = psiFile.getVirtualFile();
    if (virtualFile == null)
        return true;
    final GlobalSearchScope[] scope = new GlobalSearchScope[1];
    Project project = ApplicationManager.getApplication().runReadAction(new Computable<Project>() {

        @Override
        public Project compute() {
            Project project = psiFile.getProject();
            Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(virtualFile);
            if (module != null) {
                scope[0] = GlobalSearchScope.moduleWithDependenciesScope(module);
            }
            return project;
        }
    });
    if (scope[0] == null) {
        return true;
    }
    final LocalSearchScope filterScope = userScope instanceof LocalSearchScope ? (LocalSearchScope) userScope : null;
    PsiManager psiManager = PsiManager.getInstance(project);
    if (refElement instanceof PsiPackage) {
    //no need to do anything
    //if (!UIFormUtil.processReferencesInUIForms(consumer, (PsiPackage)refElement, scope)) return false;
    } else if (refElement instanceof PsiClass) {
        if (!processReferencesInUIForms(consumer, psiManager, (PsiClass) refElement, scope[0], filterScope))
            return false;
    } else if (refElement instanceof PsiEnumConstant) {
        if (!processEnumReferencesInUIForms(consumer, psiManager, (PsiEnumConstant) refElement, scope[0], filterScope))
            return false;
    } else if (refElement instanceof PsiField) {
        if (!processReferencesInUIForms(consumer, psiManager, (PsiField) refElement, scope[0], filterScope))
            return false;
    } else if (refElement instanceof IProperty) {
        if (!processReferencesInUIForms(consumer, psiManager, (Property) refElement, scope[0], filterScope))
            return false;
    } else if (refElement instanceof PropertiesFile) {
        if (!processReferencesInUIForms(consumer, psiManager, (PropertiesFile) refElement, scope[0], filterScope))
            return false;
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Module(com.intellij.openapi.module.Module) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty)

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