use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class PropertiesReferenceManager method processFile.
private boolean processFile(VirtualFile file, BundleNameEvaluator evaluator, PropertiesFileProcessor processor) {
final PsiFile psiFile = myPsiManager.findFile(file);
PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(psiFile);
if (propertiesFile != null) {
final String qName = evaluator.evaluateBundleName(psiFile);
if (qName != null) {
if (!processor.process(qName, propertiesFile))
return false;
}
}
return true;
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class ResourceBundleManager method dissociateResourceBundle.
public void dissociateResourceBundle(@NotNull final ResourceBundle resourceBundle) {
closeResourceBundleEditors(resourceBundle);
if (resourceBundle instanceof CustomResourceBundle) {
final CustomResourceBundleState state = getCustomResourceBundleState(resourceBundle.getDefaultPropertiesFile().getVirtualFile());
LOG.assertTrue(state != null);
myState.getCustomResourceBundles().remove(state);
} else {
if (EmptyResourceBundle.getInstance() != resourceBundle) {
((ResourceBundleImpl) resourceBundle).invalidate();
}
for (final PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
final VirtualFile file = propertiesFile.getContainingFile().getVirtualFile();
myState.getDissociatedFiles().add(file.getUrl());
}
}
}
use of com.intellij.lang.properties.psi.PropertiesFile 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.psi.PropertiesFile 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.psi.PropertiesFile in project intellij-community by JetBrains.
the class ResourcesFavoriteNodeProvider method isInvalidElement.
@Override
public boolean isInvalidElement(final Object element) {
if (element instanceof ResourceBundle) {
ResourceBundle resourceBundle = (ResourceBundle) element;
List<PropertiesFile> propertiesFiles = resourceBundle.getPropertiesFiles();
if (propertiesFiles.size() == 1) {
//todo result.add(new PsiFileNode(myProject, propertiesFiles.iterator().next(), this));
return true;
}
}
return false;
}
Aggregations