Search in sources :

Example 31 with PropertiesFile

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

the class IgnoredPropertiesFilesSuffixesTest method testPropertyIsComplete2.

public void testPropertyIsComplete2() {
    myFixture.addFileToProject("p.properties", "key=value");
    myFixture.addFileToProject("p_en.properties", "key=value eng");
    final PsiFile file = myFixture.addFileToProject("p_ru.properties", "key=value rus");
    final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
    assertNotNull(propertiesFile);
    final ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
    assertSize(3, resourceBundle.getPropertiesFiles());
    final IncompletePropertyInspection incompletePropertyInspection = IncompletePropertyInspection.getInstance(propertiesFile.getContainingFile());
    assertTrue(incompletePropertyInspection.isPropertyComplete("key", resourceBundle));
}
Also used : IncompletePropertyInspection(com.intellij.lang.properties.editor.inspections.incomplete.IncompletePropertyInspection) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 32 with PropertiesFile

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

the class IgnoredPropertiesFilesSuffixesTest method testPropertyIsIncomplete.

public void testPropertyIsIncomplete() {
    myFixture.addFileToProject("p.properties", "key=value");
    myFixture.addFileToProject("p_en.properties", "key=value eng");
    myFixture.addFileToProject("p_fr.properties", "");
    final PsiFile file = myFixture.addFileToProject("p_ru.properties", "");
    final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
    assertNotNull(propertiesFile);
    final ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
    assertSize(4, resourceBundle.getPropertiesFiles());
    final IncompletePropertyInspection incompletePropertyInspection = IncompletePropertyInspection.getInstance(propertiesFile.getContainingFile());
    incompletePropertyInspection.addSuffixes(Collections.singleton("ru"));
    assertFalse(incompletePropertyInspection.isPropertyComplete("key", resourceBundle));
}
Also used : IncompletePropertyInspection(com.intellij.lang.properties.editor.inspections.incomplete.IncompletePropertyInspection) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 33 with PropertiesFile

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

the class PropertiesFileTest method testAddPropertyAfter.

public void testAddPropertyAfter() throws IncorrectOperationException {
    final PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "a=b\nc=d\ne=f");
    final Property c = (Property) propertiesFile.findPropertyByKey("c");
    WriteCommandAction.runWriteCommandAction(null, () -> {
        propertiesFile.addPropertyAfter(myPropertyToAdd, c);
    });
    assertEquals("a=b\nc=d\nkkk=vvv\ne=f", propertiesFile.getText());
}
Also used : PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Property(com.intellij.lang.properties.psi.Property)

Example 34 with PropertiesFile

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

the class ResourceBundleTest method testDefaultPropertyFile.

public void testDefaultPropertyFile() {
    final PsiFile rawDefault = myFixture.addFileToProject("p.properties", "");
    myFixture.addFileToProject("p_en.properties", "");
    final PropertiesFile defaultFile = PropertiesImplUtil.getPropertiesFile(rawDefault);
    assertNotNull(defaultFile);
    final PropertiesFile file = defaultFile.getResourceBundle().getDefaultPropertiesFile();
    assertTrue(file.getContainingFile().isEquivalentTo(defaultFile.getContainingFile()));
}
Also used : PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 35 with PropertiesFile

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

the class ResourceBundleTest method testDifferentPropertiesDontCombinedToResourceBundle.

public void testDifferentPropertiesDontCombinedToResourceBundle() {
    final PsiFile xmlFile = myFixture.addFileToProject("p.xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE properties SYSTEM \"http://java.sun.com/dtd/properties.dtd\">\n" + "<properties>\n" + "</properties>");
    final PsiFile propFile = myFixture.addFileToProject("p.properties", "");
    final PropertiesFile xmlPropFile = PropertiesImplUtil.getPropertiesFile(xmlFile);
    final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(propFile);
    assertNotNull(xmlPropFile);
    assertNotNull(propertiesFile);
    assertEquals(xmlPropFile, assertOneElement(xmlPropFile.getResourceBundle().getPropertiesFiles()));
    assertEquals(propertiesFile, assertOneElement(propertiesFile.getResourceBundle().getPropertiesFiles()));
}
Also used : PsiFile(com.intellij.psi.PsiFile) 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