Search in sources :

Example 1 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 2 with Property

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

the class GotoPropertyParentDeclarationHandler method getGotoDeclarationTarget.

@Nullable
@Override
public PsiElement getGotoDeclarationTarget(@Nullable PsiElement sourceElement, Editor editor) {
    Property property = findProperty(sourceElement);
    if (property == null)
        return null;
    final String key = property.getKey();
    if (key == null)
        return null;
    PropertiesFile currentFile = PropertiesImplUtil.getPropertiesFile(property.getContainingFile());
    if (currentFile == null)
        return null;
    do {
        currentFile = PropertiesUtil.getParent(currentFile, currentFile.getResourceBundle().getPropertiesFiles());
        if (currentFile != null) {
            final IProperty parent = currentFile.findPropertyByKey(key);
            if (parent != null)
                return parent.getPsiElement();
        } else {
            return null;
        }
    } while (true);
}
Also used : IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty) Nullable(org.jetbrains.annotations.Nullable)

Example 3 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 4 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 5 with Property

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

the class PropertiesInspectionSuppressor method isSuppressedFor.

@Override
public boolean isSuppressedFor(@NotNull PsiElement element, @NotNull String toolId) {
    Property property = PsiTreeUtil.getParentOfType(element, Property.class, false);
    PropertiesFile file;
    if (property == null) {
        PsiFile containingFile = element.getContainingFile();
        if (containingFile instanceof PropertiesFile) {
            file = (PropertiesFile) containingFile;
        } else {
            return false;
        }
    } else {
        PsiElement prev = property.getPrevSibling();
        while (prev instanceof PsiWhiteSpace || prev instanceof PsiComment) {
            if (prev instanceof PsiComment) {
                @NonNls String text = prev.getText();
                if (text.contains("suppress") && text.contains("\"" + toolId + "\""))
                    return true;
            }
            prev = prev.getPrevSibling();
        }
        file = property.getPropertiesFile();
    }
    PsiElement leaf = file.getContainingFile().findElementAt(0);
    while (leaf instanceof PsiWhiteSpace) leaf = leaf.getNextSibling();
    while (leaf instanceof PsiComment) {
        @NonNls String text = leaf.getText();
        if (text.contains("suppress") && text.contains("\"" + toolId + "\"") && text.contains("file")) {
            return true;
        }
        leaf = leaf.getNextSibling();
        if (leaf instanceof PsiWhiteSpace)
            leaf = leaf.getNextSibling();
        // comment before first property get bound to the file, not property
        if (leaf instanceof PropertiesList && leaf.getFirstChild() == property && text.contains("suppress") && text.contains("\"" + toolId + "\"")) {
            return true;
        }
    }
    return false;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) PropertiesList(com.intellij.lang.properties.psi.PropertiesList) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Property(com.intellij.lang.properties.psi.Property)

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