Search in sources :

Example 51 with IProperty

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

the class ResourceBundlePropertiesUpdateManager method deletePropertyIfExist.

public void deletePropertyIfExist(String key, PropertiesFile file) {
    final IProperty property = file.findPropertyByKey(key);
    if (property != null && myKeysOrder != null) {
        boolean keyExistInOtherPropertiesFiles = false;
        for (PropertiesFile propertiesFile : myResourceBundle.getPropertiesFiles()) {
            if (!propertiesFile.equals(file) && propertiesFile.findPropertyByKey(key) != null) {
                keyExistInOtherPropertiesFiles = true;
                break;
            }
        }
        if (!keyExistInOtherPropertiesFiles) {
            myKeysOrder.remove(key);
        }
    }
    if (property != null) {
        PsiElement anElement = property.getPsiElement();
        if (anElement instanceof PomTargetPsiElement) {
            final PomTarget xmlProperty = ((PomTargetPsiElement) anElement).getTarget();
            LOG.assertTrue(xmlProperty instanceof XmlProperty);
            anElement = ((XmlProperty) xmlProperty).getNavigationElement();
        }
        anElement.delete();
    }
}
Also used : PomTarget(com.intellij.pom.PomTarget) IProperty(com.intellij.lang.properties.IProperty) XmlProperty(com.intellij.lang.properties.xml.XmlProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 52 with IProperty

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

the class XmlPropertiesTest method testAddProperty2.

public void testAddProperty2() {
    final PsiFile psiFile = myFixture.configureByFile("foo.xml");
    final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(psiFile);
    assertNotNull(propertiesFile);
    WriteCommandAction.runWriteCommandAction(getProject(), () -> {
        propertiesFile.addProperty("kkk", "vvv");
    });
    final IProperty property = propertiesFile.findPropertyByKey("kkk");
    assertNotNull(property);
    assertEquals("vvv", property.getValue());
    WriteCommandAction.runWriteCommandAction(getProject(), () -> {
        propertiesFile.addProperty("kkk2", "vvv");
    });
    final IProperty property2 = propertiesFile.findPropertyByKey("kkk2");
    assertNotNull(property2);
    assertEquals("vvv", property2.getValue());
}
Also used : IProperty(com.intellij.lang.properties.IProperty) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 53 with IProperty

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

the class I18nizeQuickFixDialog method getExistingValueKeys.

@NotNull
protected List<String> getExistingValueKeys(String value) {
    if (!myCustomization.suggestExistingProperties) {
        return Collections.emptyList();
    }
    final ArrayList<String> result = new ArrayList<>();
    // check if property value already exists among properties file values and suggest corresponding key
    PropertiesFile propertiesFile = getPropertiesFile();
    if (propertiesFile != null) {
        for (IProperty property : propertiesFile.getProperties()) {
            if (Comparing.strEqual(property.getValue(), value)) {
                result.add(0, property.getUnescapedKey());
            }
        }
    }
    return result;
}
Also used : IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) NotNull(org.jetbrains.annotations.NotNull)

Example 54 with IProperty

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

the class MissingTranslationsInspectionProvider method check.

@Override
public void check(BidirectionalMap<PropertiesFile, PropertiesFile> parents, List<PropertiesFile> files, Map<PropertiesFile, Set<String>> keysUpToParent, Map<PropertiesFile, Map<String, String>> propertiesFilesNamesMaps, InspectionManager manager, RefManager refManager, ProblemDescriptionsProcessor processor) {
    for (PropertiesFile file : files) {
        PropertiesFile parent = parents.get(file);
        if (parent == null)
            continue;
        List<PropertiesFile> children = parents.getKeysByValue(file);
        boolean isLeaf = children == null || children.isEmpty();
        if (!isLeaf)
            continue;
        Set<String> keys = propertiesFilesNamesMaps.get(file).keySet();
        Set<String> parentKeys = new THashSet<>(keysUpToParent.get(parent));
        if (parent.getLocale().getLanguage().equals(file.getLocale().getLanguage())) {
            // properties can be left untranslated in the dialect files
            keys = new THashSet<>(keys);
            keys.addAll(propertiesFilesNamesMaps.get(parent).keySet());
            parent = parents.get(parent);
            if (parent == null)
                continue;
            parentKeys = new THashSet<>(keysUpToParent.get(parent));
        }
        parentKeys.removeAll(keys);
        for (String untranslatedKey : parentKeys) {
            IProperty untranslatedProperty = null;
            PropertiesFile untranslatedFile = parent;
            while (untranslatedFile != null) {
                untranslatedProperty = untranslatedFile.findPropertyByKey(untranslatedKey);
                if (untranslatedProperty != null)
                    break;
                untranslatedFile = parents.get(untranslatedFile);
            }
            assert untranslatedProperty != null;
            String message = InspectionsBundle.message("inconsistent.bundle.untranslated.property.error", untranslatedKey, file.getName());
            ProblemDescriptor descriptor = manager.createProblemDescriptor(untranslatedProperty.getPsiElement(), message, false, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
            processor.addProblemElement(refManager.getReference(untranslatedFile.getContainingFile()), descriptor);
        }
    }
}
Also used : IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) THashSet(gnu.trove.THashSet)

Example 55 with IProperty

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

the class PropertiesKeysConsistencyInspectionProvider method check.

@Override
public void check(BidirectionalMap<PropertiesFile, PropertiesFile> parents, List<PropertiesFile> files, Map<PropertiesFile, Set<String>> keysUpToParent, Map<PropertiesFile, Map<String, String>> propertiesFilesNamesMaps, InspectionManager manager, RefManager refManager, ProblemDescriptionsProcessor processor) {
    for (PropertiesFile file : files) {
        PropertiesFile parent = parents.get(file);
        Set<String> parentKeys = keysUpToParent.get(parent);
        if (parent == null) {
            parentKeys = new THashSet<>();
            for (PropertiesFile otherTopLevelFile : files) {
                if (otherTopLevelFile != file && parents.get(otherTopLevelFile) == null) {
                    parent = otherTopLevelFile;
                    parentKeys.addAll(propertiesFilesNamesMaps.get(otherTopLevelFile).keySet());
                }
            }
            if (parent == null)
                continue;
        }
        Set<String> keys = new THashSet<>(propertiesFilesNamesMaps.get(file).keySet());
        keys.removeAll(parentKeys);
        for (String inconsistentKey : keys) {
            IProperty property = file.findPropertyByKey(inconsistentKey);
            assert property != null;
            String message = InspectionsBundle.message("inconsistent.bundle.property.error", inconsistentKey, parent.getName());
            ProblemDescriptor descriptor = manager.createProblemDescriptor(property.getPsiElement(), message, false, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
            processor.addProblemElement(refManager.getReference(file.getContainingFile()), descriptor);
        }
    }
}
Also used : IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) THashSet(gnu.trove.THashSet)

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