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;
}
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);
}
}
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());
}
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());
}
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());
}
Aggregations