Search in sources :

Example 11 with Property

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

the class TitleCapitalizationInspection method getTitleValue.

@Nullable
private static String getTitleValue(@Nullable PsiExpression arg, Set<PsiElement> processed) {
    if (arg instanceof PsiLiteralExpression) {
        Object value = ((PsiLiteralExpression) arg).getValue();
        if (value instanceof String) {
            return (String) value;
        }
    }
    if (arg instanceof PsiMethodCallExpression) {
        PsiMethod psiMethod = ((PsiMethodCallExpression) arg).resolveMethod();
        PsiExpression returnValue = PropertyUtil.getGetterReturnExpression(psiMethod);
        if (arg == returnValue) {
            return null;
        }
        if (returnValue != null && processed.add(returnValue)) {
            return getTitleValue(returnValue, processed);
        }
        Property propertyArgument = getPropertyArgument((PsiMethodCallExpression) arg);
        if (propertyArgument != null) {
            return propertyArgument.getUnescapedValue();
        }
    }
    if (arg instanceof PsiReferenceExpression) {
        PsiElement result = ((PsiReferenceExpression) arg).resolve();
        if (result instanceof PsiVariable && ((PsiVariable) result).hasModifierProperty(PsiModifier.FINAL)) {
            PsiExpression initializer = ((PsiVariable) result).getInitializer();
            if (processed.add(initializer)) {
                return getTitleValue(initializer, processed);
            }
        }
    }
    return null;
}
Also used : Property(com.intellij.lang.properties.psi.Property) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with Property

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

the class ResourceBundlePropertiesUpdateManager method insertOrUpdateTranslation.

public void insertOrUpdateTranslation(String key, String value, final PropertiesFile propertiesFile) throws IncorrectOperationException {
    final IProperty property = propertiesFile.findPropertyByKey(key);
    if (property != null) {
        final String oldValue = property.getValue();
        if (!Comparing.equal(oldValue, value)) {
            property.setValue(value);
            myCodeStyleManager.reformat(property.getPsiElement());
        }
        return;
    }
    if (myOrdered) {
        if (myAlphaSorted) {
            myCodeStyleManager.reformat(propertiesFile.addProperty(key, value).getPsiElement());
            return;
        }
        final Pair<IProperty, Integer> propertyAndPosition = findExistedPrevSiblingProperty(key, propertiesFile);
        myCodeStyleManager.reformat(propertiesFile.addPropertyAfter(key, value, propertyAndPosition == null ? null : (Property) propertyAndPosition.getFirst()).getPsiElement());
    } else {
        insertPropertyLast(key, value, propertiesFile);
    }
}
Also used : IProperty(com.intellij.lang.properties.IProperty) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty) XmlProperty(com.intellij.lang.properties.xml.XmlProperty)

Example 13 with Property

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

the class PropertiesFileTest method testDeletePropertyWhitespaceAround.

public void testDeletePropertyWhitespaceAround() throws Exception {
    PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "xxx=yyy\nxxx2=tyrt\nxxx3=ttt\n\n");
    final Property property = (Property) propertiesFile.findPropertyByKey("xxx2");
    WriteCommandAction.runWriteCommandAction(null, property::delete);
    assertEquals("xxx=yyy\nxxx3=ttt\n\n", propertiesFile.getContainingFile().getText());
}
Also used : PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Property(com.intellij.lang.properties.psi.Property)

Example 14 with Property

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

the class PropertiesFileTest method testDeletePropertyWhitespaceAhead.

public void testDeletePropertyWhitespaceAhead() throws Exception {
    PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "xxx=yyy\nxxx2=tyrt\nxxx3=ttt\n\n");
    final Property property = (Property) propertiesFile.findPropertyByKey("xxx");
    WriteCommandAction.runWriteCommandAction(null, property::delete);
    assertEquals("xxx2=tyrt\nxxx3=ttt\n\n", propertiesFile.getText());
}
Also used : PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Property(com.intellij.lang.properties.psi.Property)

Example 15 with Property

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

the class PropertiesFileTest method testAddPropertyAfterLast.

public void testAddPropertyAfterLast() throws IncorrectOperationException {
    final PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "a=b\nc=d\ne=f");
    final Property p = (Property) propertiesFile.findPropertyByKey("e");
    WriteCommandAction.runWriteCommandAction(null, () -> {
        propertiesFile.addPropertyAfter(myPropertyToAdd, p);
    });
    assertEquals("a=b\nc=d\ne=f\nkkk=vvv", propertiesFile.getText());
}
Also used : 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