use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class PropertiesPlaceholdersInspectionProvider method check.
@Override
public void check(BidirectionalMap<PropertiesFile, PropertiesFile> parents, List<PropertiesFile> files, Map<PropertiesFile, Set<String>> keysUpToParent, Map<PropertiesFile, Map<String, String>> propertiesFilesNamesMaps, InspectionManager manager, RefManager refManager, ProblemDescriptionsProcessor processor) {
for (PropertiesFile file : files) {
final Set<String> filePropertyKeys = new THashSet<>(propertiesFilesNamesMaps.get(file).keySet());
PropertiesFile parent = parents.get(file);
while (parent != null) {
final Collection<String> commonKeys = ContainerUtil.intersection(propertiesFilesNamesMaps.get(parent).keySet(), filePropertyKeys);
for (final String commonKey : commonKeys) {
final IProperty property = file.findPropertyByKey(commonKey);
assert property != null;
final String propertyValue = property.getValue();
if (propertyValue == null) {
continue;
}
final String parentPropertyValue = propertiesFilesNamesMaps.get(parent).get(commonKey);
if (parentPropertyValue == null) {
continue;
}
final int occurrences = JavaI18nUtil.getPropertyValuePlaceholdersCount(propertyValue);
final int parentOccurrences = JavaI18nUtil.getPropertyValuePlaceholdersCount(parentPropertyValue);
if (occurrences != parentOccurrences) {
final String problemDescriptorString = InspectionsBundle.message("inconsistent.bundle.property.inconsistent.placeholders", parentOccurrences, parent.getName());
final PsiElement propertyPsiElement = property.getPsiElement();
processor.addProblemElement(refManager.getReference(file.getContainingFile()), manager.createProblemDescriptor(propertyPsiElement, problemDescriptorString, true, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
}
}
filePropertyKeys.removeAll(commonKeys);
parent = parents.get(parent);
}
}
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class MavenPropertyCompletionAndResolutionTest method testUpperCaseEnvPropertiesOnWindows.
public void testUpperCaseEnvPropertiesOnWindows() throws Exception {
if (!SystemInfo.isWindows)
return;
createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<name>${<caret>env.PATH}</name>");
PsiReference ref = getReferenceAtCaret(myProjectPom);
assertNotNull(ref);
PsiElement resolved = ref.resolve();
assertEquals(System.getenv("Path").replaceAll("[^A-Za-z]", ""), ((IProperty) resolved).getValue().replaceAll("[^A-Za-z]", ""));
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class StringEditorDialog method saveModifiedPropertyValue.
@Nullable
public static String saveModifiedPropertyValue(final Module module, final StringDescriptor descriptor, final Locale locale, final String editedValue, final PsiFile formFile) {
final PropertiesReferenceManager manager = PropertiesReferenceManager.getInstance(module.getProject());
final PropertiesFile propFile = manager.findPropertiesFile(module, descriptor.getDottedBundleName(), locale);
if (propFile != null) {
final IProperty propertyByKey = propFile.findPropertyByKey(descriptor.getKey());
if (propertyByKey instanceof Property && !editedValue.equals(propertyByKey.getValue())) {
final Collection<PsiReference> references = findPropertyReferences((Property) propertyByKey, module);
String newKeyName = null;
if (references.size() > 1) {
final int rc = Messages.showYesNoCancelDialog(module.getProject(), UIDesignerBundle.message("edit.text.multiple.usages", propertyByKey.getUnescapedKey(), references.size()), UIDesignerBundle.message("edit.text.multiple.usages.title"), UIDesignerBundle.message("edit.text.change.all"), UIDesignerBundle.message("edit.text.make.unique"), CommonBundle.getCancelButtonText(), Messages.getWarningIcon());
if (rc == Messages.CANCEL) {
return null;
}
if (rc == Messages.NO) {
newKeyName = promptNewKeyName(module.getProject(), propFile, descriptor.getKey());
if (newKeyName == null)
return null;
}
}
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(module.getProject()).ensureFilesWritable(propFile.getVirtualFile());
if (operationStatus.hasReadonlyFiles()) {
return null;
}
final String newKeyName1 = newKeyName;
CommandProcessor.getInstance().executeCommand(module.getProject(), () -> {
UndoUtil.markPsiFileForUndo(formFile);
ApplicationManager.getApplication().runWriteAction(() -> {
PsiDocumentManager.getInstance(module.getProject()).commitAllDocuments();
try {
if (newKeyName1 != null) {
propFile.addProperty(newKeyName1, editedValue);
} else {
final IProperty propertyByKey1 = propFile.findPropertyByKey(descriptor.getKey());
if (propertyByKey1 != null) {
propertyByKey1.setValue(editedValue);
}
}
} catch (IncorrectOperationException e) {
LOG.error(e);
}
});
}, UIDesignerBundle.message("command.update.property"), null);
return newKeyName;
}
}
return null;
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class PropertyFoldingBuilder method getI18nProperty.
@Nullable
public static IProperty getI18nProperty(PsiLiteralExpression literal) {
final Property property = (Property) literal.getUserData(CACHE);
if (property == NULL)
return null;
if (property != null && isValid(property, literal))
return property;
if (isI18nProperty(literal)) {
final PsiReference[] references = literal.getReferences();
for (PsiReference reference : references) {
if (reference instanceof PsiPolyVariantReference) {
final ResolveResult[] results = ((PsiPolyVariantReference) reference).multiResolve(false);
for (ResolveResult result : results) {
final PsiElement element = result.getElement();
if (element instanceof IProperty) {
IProperty p = (IProperty) element;
literal.putUserData(CACHE, p);
return p;
}
}
} else {
final PsiElement element = reference.resolve();
if (element instanceof IProperty) {
IProperty p = (IProperty) element;
literal.putUserData(CACHE, p);
return p;
}
}
}
}
return null;
}
use of com.intellij.lang.properties.IProperty in project intellij-community by JetBrains.
the class DuplicatedPropertiesInspectionProvider method check.
@Override
public void check(BidirectionalMap<PropertiesFile, PropertiesFile> parents, List<PropertiesFile> files, Map<PropertiesFile, Set<String>> keysUpToParent, Map<PropertiesFile, Map<String, String>> propertiesFilesNamesMaps, InspectionManager manager, RefManager refManager, ProblemDescriptionsProcessor processor) {
for (PropertiesFile file : files) {
PropertiesFile parent = parents.get(file);
if (parent == null)
continue;
Set<String> parentKeys = keysUpToParent.get(parent);
Set<String> overriddenKeys = new THashSet<>(propertiesFilesNamesMaps.get(file).keySet());
overriddenKeys.retainAll(parentKeys);
for (String overriddenKey : overriddenKeys) {
IProperty property = file.findPropertyByKey(overriddenKey);
assert property != null;
while (parent != null) {
IProperty parentProperty = parent.findPropertyByKey(overriddenKey);
if (parentProperty != null && Comparing.strEqual(property.getValue(), parentProperty.getValue())) {
String message = InspectionsBundle.message("inconsistent.bundle.property.inherited.with.the.same.value", parent.getName());
ProblemDescriptor descriptor = manager.createProblemDescriptor(property.getPsiElement(), message, RemovePropertyLocalFix.INSTANCE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false);
processor.addProblemElement(refManager.getReference(file.getContainingFile()), descriptor);
}
parent = parents.get(parent);
}
}
}
}
Aggregations