use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class ResourceBundleFileStructureViewElement method getChildrenIdShowOnlyIncomplete.
private static MultiMap<String, IProperty> getChildrenIdShowOnlyIncomplete(ResourceBundle resourceBundle) {
final MultiMap<String, IProperty> propertyNames = MultiMap.createLinked();
TObjectIntHashMap<String> occurrences = new TObjectIntHashMap<>();
for (PropertiesFile file : resourceBundle.getPropertiesFiles()) {
MultiMap<String, IProperty> currentFilePropertyNames = MultiMap.createLinked();
for (IProperty property : file.getProperties()) {
String name = property.getKey();
currentFilePropertyNames.putValue(name, property);
}
propertyNames.putAllValues(currentFilePropertyNames);
for (String propertyName : currentFilePropertyNames.keySet()) {
if (occurrences.contains(propertyName)) {
occurrences.adjustValue(propertyName, 1);
} else {
occurrences.put(propertyName, 1);
}
}
}
final int targetOccurrences = resourceBundle.getPropertiesFiles().size();
occurrences.forEachEntry(new TObjectIntProcedure<String>() {
@Override
public boolean execute(String propertyName, int occurrences) {
if (occurrences == targetOccurrences) {
propertyNames.remove(propertyName);
}
return true;
}
});
return propertyNames;
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class PropertiesSeparatorManager method guessSeparator.
//returns most probable separator in properties files
private static String guessSeparator(final ResourceBundleImpl resourceBundle) {
final TIntLongHashMap charCounts = new TIntLongHashMap();
for (PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
if (propertiesFile == null)
continue;
List<IProperty> properties = propertiesFile.getProperties();
for (IProperty property : properties) {
String key = property.getUnescapedKey();
if (key == null)
continue;
for (int i = 0; i < key.length(); i++) {
char c = key.charAt(i);
if (!Character.isLetterOrDigit(c)) {
charCounts.put(c, charCounts.get(c) + 1);
}
}
}
}
final char[] mostProbableChar = new char[] { '.' };
charCounts.forEachKey(new TIntProcedure() {
long count = -1;
public boolean execute(int ch) {
long charCount = charCounts.get(ch);
if (charCount > count) {
count = charCount;
mostProbableChar[0] = (char) ch;
}
return true;
}
});
if (mostProbableChar[0] == 0) {
mostProbableChar[0] = '.';
}
return Character.toString(mostProbableChar[0]);
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class XmlPropertiesFileImpl method addProperty.
@NotNull
@Override
public IProperty addProperty(String key, String value) {
final XmlTag entry = createPropertyTag(key, value);
synchronized (myLock) {
ensurePropertiesLoaded();
if (myAlphaSorted) {
final XmlProperty dummyProperty = new XmlProperty(entry, this);
final int insertIndex = Collections.binarySearch(myProperties, dummyProperty, (p1, p2) -> {
final String k1 = p1.getKey();
final String k2 = p2.getKey();
return k1.compareTo(k2);
});
final IProperty insertPosition;
final IProperty inserted;
if (insertIndex == -1) {
inserted = addPropertyAfter(key, value, null, false);
myProperties.add(0, inserted);
} else {
final int position = insertIndex < 0 ? -insertIndex - 2 : insertIndex;
insertPosition = myProperties.get(position);
inserted = addPropertyAfter(key, value, insertPosition, false);
myProperties.add(position + 1, inserted);
}
return inserted;
} else {
return addPropertyAfter(key, value, null, true);
}
}
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class I18nUtil method createProperty.
public static void createProperty(final Project project, final Collection<PropertiesFile> propertiesFiles, final String key, final String value) throws IncorrectOperationException {
for (PropertiesFile file : propertiesFiles) {
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
documentManager.commitDocument(documentManager.getDocument(file.getContainingFile()));
IProperty existingProperty = file.findPropertyByKey(key);
if (existingProperty == null) {
file.addProperty(key, value);
}
}
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class PropertyReferenceBase method getResolveResults.
protected static ResolveResult[] getResolveResults(List<IProperty> properties) {
if (properties.isEmpty())
return ResolveResult.EMPTY_ARRAY;
final ResolveResult[] results = new ResolveResult[properties.size()];
for (int i = 0; i < properties.size(); i++) {
IProperty property = properties.get(i);
results[i] = new PsiElementResolveResult(property instanceof PsiElement ? (PsiElement) property : PomService.convertToPsi((PsiTarget) property));
}
return results;
}
Aggregations