use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class XmlPropertiesTest method testXmlProperties.
public void testXmlProperties() throws Exception {
myFixture.configureByFile("foo.xml");
List<PropertiesFile> files = PropertiesReferenceManager.getInstance(getProject()).findPropertiesFiles(myModule, "foo");
assertEquals(1, files.size());
PropertiesFile file = files.get(0);
assertEquals(1, file.findPropertiesByKey("foo").size());
List<IProperty> properties = PropertiesImplUtil.findPropertiesByKey(getProject(), "foo");
assertEquals(1, properties.size());
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class XmlPropertiesTest method testAddProperty.
public void testAddProperty() {
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());
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class DuplicatePropertyInspection method prepareDuplicateKeysByFile.
private void prepareDuplicateKeysByFile(final Map<String, Set<PsiFile>> keyToFiles, final InspectionManager manager, final Map<String, Set<String>> keyToValues, final List<ProblemDescriptor> problemDescriptors, final PsiFile psiFile, final ProgressIndicator progress) {
for (String key : keyToFiles.keySet()) {
if (progress != null) {
progress.setText2(InspectionsBundle.message("duplicate.property.key.progress.indicator.text", key));
if (progress.isCanceled())
throw new ProcessCanceledException();
}
final StringBuffer message = new StringBuffer();
int duplicatesCount = 0;
Set<PsiFile> psiFilesWithDuplicates = keyToFiles.get(key);
for (PsiFile file : psiFilesWithDuplicates) {
if (!(file instanceof PropertiesFile))
continue;
PropertiesFile propertiesFile = (PropertiesFile) file;
final List<IProperty> propertiesByKey = propertiesFile.findPropertiesByKey(key);
for (IProperty property : propertiesByKey) {
if (duplicatesCount == 0) {
message.append(InspectionsBundle.message("duplicate.property.key.problem.descriptor", key));
}
surroundWithHref(message, property.getPsiElement().getFirstChild(), false);
duplicatesCount++;
//prepare for filter same keys different values
Set<String> values = keyToValues.get(key);
if (values == null) {
values = new HashSet<>();
keyToValues.put(key, values);
}
values.add(property.getValue());
}
}
if (duplicatesCount > 1 && CHECK_DUPLICATE_KEYS) {
problemDescriptors.add(manager.createProblemDescriptor(psiFile, message.toString(), false, null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
}
}
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class DuplicatePropertyInspection method checkFile.
private void checkFile(final PsiFile file, final InspectionManager manager, GlobalInspectionContextBase context, final RefManager refManager, final ProblemDescriptionsProcessor processor) {
if (!(file instanceof PropertiesFile))
return;
if (!context.isToCheckFile(file, this) || SuppressionUtil.inspectionResultSuppressed(file, this))
return;
final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(file.getProject());
final PropertiesFile propertiesFile = (PropertiesFile) file;
final List<IProperty> properties = propertiesFile.getProperties();
Module module = ModuleUtilCore.findModuleForPsiElement(file);
if (module == null)
return;
final GlobalSearchScope scope = CURRENT_FILE ? GlobalSearchScope.fileScope(file) : MODULE_WITH_DEPENDENCIES ? GlobalSearchScope.moduleWithDependenciesScope(module) : GlobalSearchScope.projectScope(file.getProject());
final Map<String, Set<PsiFile>> processedValueToFiles = Collections.synchronizedMap(new HashMap<String, Set<PsiFile>>());
final Map<String, Set<PsiFile>> processedKeyToFiles = Collections.synchronizedMap(new HashMap<String, Set<PsiFile>>());
final ProgressIndicator original = ProgressManager.getInstance().getProgressIndicator();
final ProgressIndicator progress = ProgressWrapper.wrap(original);
ProgressManager.getInstance().runProcess(() -> {
if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(properties, progress, false, property -> {
if (original != null) {
if (original.isCanceled())
return false;
original.setText2(PropertiesBundle.message("searching.for.property.key.progress.text", property.getUnescapedKey()));
}
processTextUsages(processedValueToFiles, property.getValue(), processedKeyToFiles, searchHelper, scope);
processTextUsages(processedKeyToFiles, property.getUnescapedKey(), processedValueToFiles, searchHelper, scope);
return true;
}))
throw new ProcessCanceledException();
List<ProblemDescriptor> problemDescriptors = new ArrayList<>();
Map<String, Set<String>> keyToDifferentValues = new HashMap<>();
if (CHECK_DUPLICATE_KEYS || CHECK_DUPLICATE_KEYS_WITH_DIFFERENT_VALUES) {
prepareDuplicateKeysByFile(processedKeyToFiles, manager, keyToDifferentValues, problemDescriptors, file, original);
}
if (CHECK_DUPLICATE_VALUES)
prepareDuplicateValuesByFile(processedValueToFiles, manager, problemDescriptors, file, original);
if (CHECK_DUPLICATE_KEYS_WITH_DIFFERENT_VALUES) {
processDuplicateKeysWithDifferentValues(keyToDifferentValues, processedKeyToFiles, problemDescriptors, manager, file, original);
}
if (!problemDescriptors.isEmpty()) {
processor.addProblemElement(refManager.getReference(file), problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()]));
}
}, progress);
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class ResourceBundleFileStructureViewElement method getChildren.
@NotNull
public synchronized StructureViewTreeElement[] getChildren() {
final MultiMap<String, IProperty> propertyNames = getPropertiesMap(myResourceBundle, myShowOnlyIncomplete);
final HashSet<String> remains = new HashSet<>(myElements.keySet());
for (Map.Entry<String, Collection<IProperty>> entry : propertyNames.entrySet()) {
final String propKey = entry.getKey();
Collection<IProperty> properties = entry.getValue();
final ResourceBundlePropertyStructureViewElement oldPropertyNode = myElements.get(propKey);
if (oldPropertyNode != null && properties.contains(oldPropertyNode.getProperty())) {
remains.remove(propKey);
continue;
}
final IProperty representative = properties.iterator().next();
myElements.put(propKey, new ResourceBundlePropertyStructureViewElement(representative));
}
for (String remain : remains) {
myElements.remove(remain);
}
return myElements.values().toArray(StructureViewTreeElement.EMPTY_ARRAY);
}
Aggregations