use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class FormEditingUtil method collectUsedLocales.
public static Locale[] collectUsedLocales(final Module module, final IRootContainer rootContainer) {
final Set<Locale> locales = new HashSet<>();
final PropertiesReferenceManager propManager = PropertiesReferenceManager.getInstance(module.getProject());
for (String bundleName : collectUsedBundleNames(rootContainer)) {
List<PropertiesFile> propFiles = propManager.findPropertiesFiles(module, bundleName.replace('/', '.'));
for (PropertiesFile propFile : propFiles) {
locales.add(propFile.getLocale());
}
}
return locales.toArray(new Locale[locales.size()]);
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class StringDescriptorManager method resolveToProperty.
public IProperty resolveToProperty(@NotNull StringDescriptor descriptor, @Nullable Locale locale) {
String propFileName = descriptor.getDottedBundleName();
Pair<Locale, String> cacheKey = Pair.create(locale, propFileName);
PropertiesFile propertiesFile;
synchronized (myPropertiesFileCache) {
propertiesFile = myPropertiesFileCache.get(cacheKey);
}
if (propertiesFile == null || !propertiesFile.getContainingFile().isValid()) {
propertiesFile = PropertiesUtilBase.getPropertiesFile(propFileName, myModule, locale);
synchronized (myPropertiesFileCache) {
myPropertiesFileCache.put(cacheKey, propertiesFile);
}
}
if (propertiesFile != null) {
final IProperty propertyByKey = propertiesFile.findPropertyByKey(descriptor.getKey());
if (propertyByKey != null) {
return propertyByKey;
}
}
return null;
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class ResourceBundleReference method getVariants.
@Override
@NotNull
public Object[] getVariants() {
final ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(getElement().getProject());
final PropertiesReferenceManager referenceManager = PropertiesReferenceManager.getInstance(getElement().getProject());
final Set<String> bundleNames = new HashSet<>();
final List<LookupElement> variants = new SmartList<>();
PropertiesFileProcessor processor = new PropertiesFileProcessor() {
@Override
public boolean process(String baseName, PropertiesFile propertiesFile) {
if (!bundleNames.add(baseName))
return true;
final LookupElementBuilder builder = LookupElementBuilder.create(baseName).withIcon(AllIcons.Nodes.ResourceBundle);
boolean isInContent = projectFileIndex.isInContent(propertiesFile.getVirtualFile());
variants.add(isInContent ? PrioritizedLookupElement.withPriority(builder, Double.MAX_VALUE) : builder);
return true;
}
};
referenceManager.processPropertiesFiles(myElement.getResolveScope(), processor, this);
return variants.toArray(new LookupElement[variants.size()]);
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class CreateResourceBundleDialogComponent method canCreateAllFilesForAllLocales.
private String canCreateAllFilesForAllLocales() {
final String name = getBaseName();
if (name.isEmpty()) {
return "Base name is empty";
}
final Set<String> files = getFileNamesToCreate();
if (files.isEmpty()) {
return "No locales added";
}
for (PsiElement element : myDirectory.getChildren()) {
if (element instanceof PsiFile) {
if (element instanceof PropertiesFile) {
PropertiesFile propertiesFile = (PropertiesFile) element;
final String propertiesFileName = propertiesFile.getName();
if (files.contains(propertiesFileName)) {
return "Some of files already exist";
}
}
}
}
return null;
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class CreateResourceBundleDialogComponent method combineToResourceBundleIfNeed.
private void combineToResourceBundleIfNeed(Collection<PsiFile> files) {
Collection<PropertiesFile> createdFiles = ContainerUtil.map(files, (NotNullFunction<PsiFile, PropertiesFile>) dom -> {
final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(dom);
LOG.assertTrue(file != null, dom.getName());
return file;
});
ResourceBundle mainBundle = myResourceBundle;
final Set<ResourceBundle> allBundles = new HashSet<>();
if (mainBundle != null) {
allBundles.add(mainBundle);
}
boolean needCombining = false;
for (PropertiesFile file : createdFiles) {
final ResourceBundle rb = file.getResourceBundle();
if (mainBundle == null) {
mainBundle = rb;
} else if (!mainBundle.equals(rb)) {
needCombining = true;
}
allBundles.add(rb);
}
if (needCombining) {
final List<PropertiesFile> toCombine = new ArrayList<>(createdFiles);
final String baseName = getBaseName();
if (myResourceBundle != null) {
toCombine.addAll(myResourceBundle.getPropertiesFiles());
}
ResourceBundleManager manager = ResourceBundleManager.getInstance(mainBundle.getProject());
for (ResourceBundle bundle : allBundles) {
manager.dissociateResourceBundle(bundle);
}
manager.combineToResourceBundle(toCombine, baseName);
}
}
Aggregations