Search in sources :

Example 6 with Property

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

the class PropertiesInheritorsSearcher method processQuery.

@Override
public void processQuery(@NotNull DefinitionsScopedSearch.SearchParameters queryParameters, @NotNull Processor<PsiElement> consumer) {
    final PsiElement element = queryParameters.getElement();
    Property prop = ReadAction.compute(() -> GotoPropertyParentDeclarationHandler.findProperty(element));
    if (prop == null || !(queryParameters.getScope() instanceof GlobalSearchScope)) {
        return;
    }
    ReadAction.run(() -> {
        final String key = prop.getKey();
        if (!prop.isValid() || key == null)
            return;
        final PropertiesFile currentFile = PropertiesImplUtil.getPropertiesFile(prop.getContainingFile());
        LOG.assertTrue(currentFile != null);
        final GlobalSearchScope scope = (GlobalSearchScope) queryParameters.getScope();
        currentFile.getResourceBundle().getPropertiesFiles().stream().filter(f -> f.equals(currentFile)).filter(f -> scope.contains(f.getVirtualFile())).filter(f -> PropertiesUtil.getParent(f, Collections.singleton(currentFile)) == currentFile).map(f -> f.findPropertyByKey(key)).filter(Objects::nonNull).map(IProperty::getPsiElement).anyMatch(psiElement -> {
            ProgressManager.checkCanceled();
            return !consumer.process(psiElement);
        });
    });
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) Property(com.intellij.lang.properties.psi.Property) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DefinitionsScopedSearch(com.intellij.psi.search.searches.DefinitionsScopedSearch) ReadAction(com.intellij.openapi.application.ReadAction) QueryExecutorBase(com.intellij.openapi.application.QueryExecutorBase) Objects(java.util.Objects) IProperty(com.intellij.lang.properties.IProperty) PropertiesImplUtil(com.intellij.lang.properties.PropertiesImplUtil) Processor(com.intellij.util.Processor) PsiElement(com.intellij.psi.PsiElement) PropertiesUtil(com.intellij.lang.properties.PropertiesUtil) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Objects(java.util.Objects) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty) PsiElement(com.intellij.psi.PsiElement)

Example 7 with Property

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

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

the class FormPropertyUsageTest method doPropertyUsageTest.

private void doPropertyUsageTest(final String propertyFileName) {
    PropertiesFile propFile = (PropertiesFile) myPsiManager.findFile(myTestProjectRoot.findChild(propertyFileName));
    assertNotNull(propFile);
    final Property prop = (Property) propFile.findPropertyByKey("key");
    assertNotNull(prop);
    final Query<PsiReference> query = ReferencesSearch.search(prop);
    final Collection<PsiReference> result = query.findAll();
    assertEquals(1, result.size());
    verifyReference(result, 0, "form.form", 960);
}
Also used : PsiReference(com.intellij.psi.PsiReference) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Property(com.intellij.lang.properties.psi.Property)

Example 9 with Property

use of com.intellij.lang.properties.psi.Property in project android by JetBrains.

the class GradleImplicitPropertyUsageProviderTest method testGradleWrapper.

public void testGradleWrapper() {
    VirtualFile vFile = myFixture.copyFileToProject("projects/projectWithAppandLib/gradle/wrapper/gradle-wrapper.properties", "gradle/wrapper/gradle-wrapper.properties");
    PsiFile file = PsiManager.getInstance(getProject()).findFile(vFile);
    assertNotNull(file);
    PropertiesFile propertiesFile = (PropertiesFile) file;
    GradleImplicitPropertyUsageProvider provider = new GradleImplicitPropertyUsageProvider();
    for (IProperty property : propertiesFile.getProperties()) {
        // All properties are considered used in this file
        String name = property.getName();
        assertTrue(name, provider.isUsed((Property) property));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IProperty(com.intellij.lang.properties.IProperty) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty)

Example 10 with Property

use of com.intellij.lang.properties.psi.Property in project android by JetBrains.

the class GradleImplicitPropertyUsageProviderTest method testLocalProperties.

public void testLocalProperties() {
    VirtualFile vFile = myFixture.copyFileToProject("test.properties", "local.properties");
    PsiFile file = PsiManager.getInstance(getProject()).findFile(vFile);
    assertNotNull(file);
    PropertiesFile propertiesFile = (PropertiesFile) file;
    GradleImplicitPropertyUsageProvider provider = new GradleImplicitPropertyUsageProvider();
    for (IProperty property : propertiesFile.getProperties()) {
        Property p = (Property) property;
        // Only but the property with "unused" in its name are considered used
        String name = property.getName();
        if (name.contains("unused")) {
            assertFalse(name, provider.isUsed(p));
        } else {
            assertTrue(name, provider.isUsed(p));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IProperty(com.intellij.lang.properties.IProperty) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty)

Aggregations

Property (com.intellij.lang.properties.psi.Property)23 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)16 IProperty (com.intellij.lang.properties.IProperty)12 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)5 Module (com.intellij.openapi.module.Module)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiElement (com.intellij.psi.PsiElement)4 PsiFile (com.intellij.psi.PsiFile)4 ASTNode (com.intellij.lang.ASTNode)3 Logger (com.intellij.openapi.diagnostic.Logger)3 ProgressManager (com.intellij.openapi.progress.ProgressManager)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 com.intellij.codeInspection (com.intellij.codeInspection)2 PropertiesImplUtil (com.intellij.lang.properties.PropertiesImplUtil)2 ModuleUtilCore (com.intellij.openapi.module.ModuleUtilCore)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Project (com.intellij.openapi.project.Project)2 PsiSearchHelper (com.intellij.psi.search.PsiSearchHelper)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2