use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class JavaI18nUtil method isPropertyRef.
static boolean isPropertyRef(final PsiExpression expression, final String key, final String resourceBundleName) {
if (resourceBundleName == null) {
return !PropertiesImplUtil.findPropertiesByKey(expression.getProject(), key).isEmpty();
} else {
final List<PropertiesFile> propertiesFiles = propertiesFilesByBundleName(resourceBundleName, expression);
boolean containedInPropertiesFile = false;
for (PropertiesFile propertiesFile : propertiesFiles) {
containedInPropertiesFile |= propertiesFile.findPropertyByKey(key) != null;
}
return containedInPropertiesFile;
}
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class InconsistentResourceBundleInspection method checkFile.
@Override
public void checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, @NotNull ProblemsHolder problemsHolder, @NotNull GlobalInspectionContext globalContext, @NotNull ProblemDescriptionsProcessor problemDescriptionsProcessor) {
Set<ResourceBundle> visitedBundles = globalContext.getUserData(VISITED_BUNDLES_KEY);
if (!(file instanceof PropertiesFile))
return;
final PropertiesFile propertiesFile = (PropertiesFile) file;
ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
assert visitedBundles != null;
if (!visitedBundles.add(resourceBundle))
return;
List<PropertiesFile> files = resourceBundle.getPropertiesFiles();
if (files.size() < 2)
return;
BidirectionalMap<PropertiesFile, PropertiesFile> parents = new BidirectionalMap<>();
for (PropertiesFile f : files) {
PropertiesFile parent = PropertiesUtil.getParent(f, files);
if (parent != null) {
parents.put(f, parent);
}
}
final FactoryMap<PropertiesFile, Map<String, String>> propertiesFilesNamesMaps = new FactoryMap<PropertiesFile, Map<String, String>>() {
@Nullable
@Override
protected Map<String, String> create(PropertiesFile key) {
return key.getNamesMap();
}
};
Map<PropertiesFile, Set<String>> keysUpToParent = new THashMap<>();
for (PropertiesFile f : files) {
Set<String> keys = new THashSet<>(propertiesFilesNamesMaps.get(f).keySet());
PropertiesFile parent = parents.get(f);
while (parent != null) {
keys.addAll(propertiesFilesNamesMaps.get(parent).keySet());
parent = parents.get(parent);
}
keysUpToParent.put(f, keys);
}
for (final InconsistentResourceBundleInspectionProvider provider : myInspectionProviders.getValue()) {
if (isProviderEnabled(provider.getName())) {
provider.check(parents, files, keysUpToParent, propertiesFilesNamesMaps, manager, globalContext.getRefManager(), problemDescriptionsProcessor);
}
}
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class SuspiciousLocalesLanguagesInspection method checkFile.
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
if (propertiesFile == null) {
return null;
}
final ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
final List<PropertiesFile> files = resourceBundle.getPropertiesFiles();
if (!(resourceBundle instanceof ResourceBundleImpl) || files.size() < 2) {
return null;
}
List<Locale> bundleLocales = ContainerUtil.mapNotNull(files, propertiesFile1 -> {
final Locale locale = propertiesFile1.getLocale();
return locale == PropertiesUtil.DEFAULT_LOCALE ? null : locale;
});
bundleLocales = ContainerUtil.filter(bundleLocales, locale -> !JAVA_LOCALES.getValue().contains(locale.getLanguage()) && !myAdditionalLanguages.contains(locale.getLanguage()));
if (bundleLocales.isEmpty()) {
return null;
}
final ProblemDescriptor descriptor = manager.createProblemDescriptor(file, PropertiesBundle.message("resource.bundle.contains.locales.with.suspicious.locale.languages.desciptor"), new DissociateResourceBundleQuickFix(resourceBundle), ProblemHighlightType.WEAK_WARNING, true);
return new ProblemDescriptor[] { descriptor };
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class I18nizeAction method doI18nSelectedString.
public static void doI18nSelectedString(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile psiFile, @NotNull final I18nQuickFixHandler handler) {
try {
handler.checkApplicability(psiFile, editor);
} catch (IncorrectOperationException ex) {
CommonRefactoringUtil.showErrorHint(project, editor, ex.getMessage(), CodeInsightBundle.message("i18nize.error.title"), null);
return;
}
if (!ApplicationManager.getApplication().isUnitTestMode()) {
JavaI18nizeQuickFixDialog.isAvailable(psiFile);
}
try {
ResourceBundleManager.getManager(psiFile);
} catch (ResourceBundleManager.ResourceBundleNotFoundException e) {
return;
}
final JavaI18nizeQuickFixDialog dialog = handler.createDialog(project, editor, psiFile);
if (dialog == null)
return;
if (!dialog.showAndGet()) {
return;
}
if (!FileModificationService.getInstance().prepareFileForWrite(psiFile))
return;
final Collection<PropertiesFile> propertiesFiles = dialog.getAllPropertiesFiles();
for (PropertiesFile file : propertiesFiles) {
if (!FileModificationService.getInstance().prepareFileForWrite(file.getContainingFile()))
return;
}
ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().executeCommand(project, () -> {
try {
handler.performI18nization(psiFile, editor, dialog.getLiteralExpression(), propertiesFiles, dialog.getKey(), StringUtil.unescapeStringCharacters(dialog.getValue()), dialog.getI18nizedText(), dialog.getParameters(), dialog.getPropertyCreationHandler());
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}, CodeInsightBundle.message("quickfix.i18n.command.name"), project));
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class InvalidPropertyKeyFormInspection method checkDescriptor.
@Nullable
private static String checkDescriptor(final StringDescriptor descriptor, final Module module) {
final String bundleName = descriptor.getDottedBundleName();
final String key = descriptor.getKey();
if (bundleName == null && key == null)
return null;
if (bundleName == null) {
return UIDesignerBundle.message("inspection.invalid.property.in.form.quickfix.error.bundle.not.specified");
}
if (key == null) {
return UIDesignerBundle.message("inspection.invalid.property.in.form.quickfix.error.property.key.not.specified");
}
PropertiesReferenceManager manager = PropertiesReferenceManager.getInstance(module.getProject());
List<PropertiesFile> propFiles = manager.findPropertiesFiles(module, bundleName);
if (propFiles.size() == 0) {
return UIDesignerBundle.message("inspection.invalid.property.in.form.quickfix.error.bundle.not.found", bundleName);
}
for (PropertiesFile propFile : propFiles) {
final com.intellij.lang.properties.IProperty property = propFile.findPropertyByKey(key);
if (property == null) {
return UIDesignerBundle.message("inspection.invalid.property.in.form.quickfix.error.key.not.found", key, bundleName, propFile.getLocale().getDisplayName());
}
}
return null;
}
Aggregations