use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class XmlPropertiesTest method testAddProperty2.
public void testAddProperty2() {
final PsiFile psiFile = myFixture.configureByFile("foo.xml");
final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(psiFile);
assertNotNull(propertiesFile);
WriteCommandAction.runWriteCommandAction(getProject(), () -> {
propertiesFile.addProperty("kkk", "vvv");
});
final IProperty property = propertiesFile.findPropertyByKey("kkk");
assertNotNull(property);
assertEquals("vvv", property.getValue());
WriteCommandAction.runWriteCommandAction(getProject(), () -> {
propertiesFile.addProperty("kkk2", "vvv");
});
final IProperty property2 = propertiesFile.findPropertyByKey("kkk2");
assertNotNull(property2);
assertEquals("vvv", property2.getValue());
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class ResourceBundleRenamerFactory method isApplicable.
@Override
public boolean isApplicable(@NotNull final PsiElement element) {
if (!(element instanceof PsiFile)) {
return false;
}
final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(element);
if (file == null) {
return false;
}
final ResourceBundle resourceBundle = file.getResourceBundle();
return resourceBundle.getBaseDirectory() != null && resourceBundle.getPropertiesFiles().size() != 1;
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class I18nizeQuickFixDialog method getExistingValueKeys.
@NotNull
protected List<String> getExistingValueKeys(String value) {
if (!myCustomization.suggestExistingProperties) {
return Collections.emptyList();
}
final ArrayList<String> result = new ArrayList<>();
// check if property value already exists among properties file values and suggest corresponding key
PropertiesFile propertiesFile = getPropertiesFile();
if (propertiesFile != null) {
for (IProperty property : propertiesFile.getProperties()) {
if (Comparing.strEqual(property.getValue(), value)) {
result.add(0, property.getUnescapedKey());
}
}
}
return result;
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class I18nizeQuickFixDialog method propertiesFileChanged.
private void propertiesFileChanged() {
PropertiesFile propertiesFile = getPropertiesFile();
boolean hasResourceBundle = propertiesFile != null && propertiesFile.getResourceBundle().getPropertiesFiles().size() > 1;
myUseResourceBundle.setEnabled(hasResourceBundle);
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class I18nizeQuickFixDialog method suggestPropertyKey.
protected String suggestPropertyKey(String value) {
if (myCustomization.suggestedName != null) {
return myCustomization.suggestedName;
}
// suggest property key not existing in this file
String key = defaultSuggestPropertyKey(value);
value = PATTERN.matcher(Normalizer.normalize(value, Normalizer.Form.NFD)).replaceAll("");
if (key == null) {
final StringBuilder result = new StringBuilder();
boolean insertDotBeforeNextWord = false;
for (int i = 0; i < value.length(); i++) {
final char c = value.charAt(i);
if (Character.isLetterOrDigit(c)) {
if (insertDotBeforeNextWord) {
result.append('.');
}
result.append(Character.toLowerCase(c));
insertDotBeforeNextWord = false;
} else if (c == '&') {
//do not insert dot if there is letter after the amp
if (insertDotBeforeNextWord)
continue;
if (i == value.length() - 1) {
continue;
}
if (Character.isLetter(value.charAt(i + 1))) {
continue;
}
insertDotBeforeNextWord = true;
} else {
if (result.length() > 0) {
insertDotBeforeNextWord = true;
}
}
}
key = result.toString();
}
PropertiesFile propertiesFile = getPropertiesFile();
if (propertiesFile != null) {
if (propertiesFile.findPropertyByKey(key) == null)
return key;
int suffix = 1;
while (propertiesFile.findPropertyByKey(key + suffix) != null) {
suffix++;
}
return key + suffix;
} else {
return key;
}
}
Aggregations