protected static void collectPropertiesFileVariants( @Nullable PropertiesFile file, @Nullable String prefix, List<Object> result) { if (file == null) return; for (IProperty each : file.getProperties()) { String name = each.getKey(); if (name != null) { if (prefix != null) name = prefix + name; result.add(createLookupElement(each, name, PlatformIcons.PROPERTY_ICON)); } } }
@Override public void findCollisions( PsiElement element, final String newName, Map<? extends PsiElement, String> allRenames, List<UsageInfo> result) { for (final Map.Entry<? extends PsiElement, String> e : allRenames.entrySet()) { for (IProperty property : ((PropertiesFile) e.getKey().getContainingFile()).getProperties()) { if (Comparing.strEqual(e.getValue(), property.getKey())) { result.add( new UnresolvableCollisionUsageInfo(property.getPsiElement(), e.getKey()) { @Override public String getDescription() { return "New property name \'" + e.getValue() + "\' hides existing property"; } }); } } } }
private static void sortPropertiesFile(final PropertiesFile file) { final List<IProperty> properties = new ArrayList<IProperty>(file.getProperties()); Collections.sort( properties, new Comparator<IProperty>() { @Override public int compare(IProperty p1, IProperty p2) { return Comparing.compare(p1.getKey(), p2.getKey()); } }); final char delimiter = PropertiesCodeStyleSettings.getInstance(file.getProject()).KEY_VALUE_DELIMITER; final StringBuilder rawText = new StringBuilder(); for (int i = 0; i < properties.size(); i++) { IProperty property = properties.get(i); final String value = property.getUnescapedValue(); rawText.append( PropertiesElementFactory.getPropertyText( property.getKey(), value != null ? value : "", delimiter, null)); if (i != properties.size() - 1) { rawText.append("\n"); } } final PropertiesFile fakeFile = PropertiesElementFactory.createPropertiesFile(file.getProject(), rawText.toString()); final PropertiesList propertiesList = PsiTreeUtil.findChildOfType(file.getContainingFile(), PropertiesList.class); LOG.assertTrue(propertiesList != null); final PropertiesList fakePropertiesList = PsiTreeUtil.findChildOfType(fakeFile.getContainingFile(), PropertiesList.class); LOG.assertTrue(fakePropertiesList != null); propertiesList.replace(fakePropertiesList); }