public static String unwindValue(String value) { return escapeLeadingWhiteSpaces(escapeCommentChars(unwindEscapeChars(value))); }
private static String escapeLeadingWhiteSpaces(String str) { int firstNonWhiteSpace= findFirstNonWhiteSpace(str); StringBuilder buf= new StringBuilder(firstNonWhiteSpace); for (int i = 0; i < firstNonWhiteSpace; i++) { buf.append('\\'); buf.append(str.charAt(i)); } buf.append(str.substring(firstNonWhiteSpace)); return buf.toString(); }
private static void addInsertEdits(TextChange textChange, NLSSubstitution[] substitutions, Map<String, NLSSubstitution> newKeyToSubstMap, Map<String, NLSSubstitution> oldKeyToSubstMap, PropertyFileDocumentModel model) { ArrayList<KeyValuePair> keyValuePairsToAdd= new ArrayList<>(); for (int i= 0; i < substitutions.length; i++) { NLSSubstitution substitution= substitutions[i]; if (doInsert(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { String value= PropertyFileDocumentModel.escape(substitution.getValueNonEmpty(), true) + model.getLineDelimiter(); String key= PropertyFileDocumentModel.escape(substitution.getKey(), false); keyValuePairsToAdd.add(new KeyValuePair(key, value)); } } if (keyValuePairsToAdd.size() > 0) { model.insert(keyValuePairsToAdd.toArray(new KeyValuePair[keyValuePairsToAdd.size()]), textChange); } }
public static String escape(String s, boolean escapeCommentCharsAndLeadingWhitespaces) { StringBuilder sb= new StringBuilder(s.length()); int length= s.length(); for (int i= 0; i < length; i++){ char c= s.charAt(i); sb.append(PropertiesFileEscapes.escape(c)); } if(!escapeCommentCharsAndLeadingWhitespaces) return sb.toString(); return escapeLeadingWhiteSpaces(escapeCommentChars(sb.toString())); }
PropertyFileDocumentModel model= new PropertyFileDocumentModel(document); KeyValuePair oldPair= model.getKeyValuePair(fField.getElementName()); if (oldPair == null) return null; ReplaceEdit edit= model.replace(oldPair, newPair); if (edit == null) return null;
private static void addReplaceEdits(TextChange textChange, NLSSubstitution[] substitutions, Map<String, NLSSubstitution> newKeyToSubstMap, Map<String, NLSSubstitution> oldKeyToSubstMap, PropertyFileDocumentModel model) { for (int i= 0; i < substitutions.length; i++) { NLSSubstitution substitution= substitutions[i]; if (doReplace(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { KeyValuePair initialPair= new KeyValuePair(substitution.getInitialKey(), substitution.getInitialValue()); String key= PropertyFileDocumentModel.escape(substitution.getKey(), false); String value= PropertyFileDocumentModel.escape(substitution.getValue(), true) + model.getLineDelimiter(); KeyValuePair newPair= new KeyValuePair(key, value); TextEdit edit= model.replace(initialPair, newPair); if (edit != null) { TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_replace_entry, BasicElementLabels.getJavaElementName(substitution.getKey())), edit); } } } }
public static Change removeKeys(IPath propertyFilePath, List<String> keys) throws CoreException { String name= Messages.format(NLSMessages.NLSPropertyFileModifier_remove_from_property_file, BasicElementLabels.getPathLabel(propertyFilePath, false)); TextChange textChange= new TextFileChange(name, getPropertyFile(propertyFilePath)); textChange.setTextType("properties"); //$NON-NLS-1$ PropertyFileDocumentModel model= new PropertyFileDocumentModel(textChange.getCurrentDocument(new NullProgressMonitor())); for (Iterator<String> iterator= keys.iterator(); iterator.hasNext();) { String key= iterator.next(); TextEdit edit= model.remove(key); if (edit != null) { TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_remove_entry, BasicElementLabels.getJavaElementName(key)), edit); } } return textChange; }
public InsertEdit[] insert(KeyValuePair[] keyValuePairs) { InsertEdit[] inserts = new InsertEdit[keyValuePairs.length]; for (int i = 0; i < keyValuePairs.length; i++) { inserts[i] = insert(keyValuePairs[i]); } return inserts; }
private static void addRemoveEdits(TextChange textChange, NLSSubstitution[] substitutions, Map newKeyToSubstMap, Map oldKeyToSubstMap, PropertyFileDocumentModel model) { for (int i= 0; i < substitutions.length; i++) { NLSSubstitution substitution= substitutions[i]; if (doRemove(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { TextEdit edit= model.remove(substitution.getInitialKey()); if (edit != null) { TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_remove_entry, substitution.getInitialKey()), edit); } } } }
private static void addChanges(TextChange textChange, NLSSubstitution[] substitutions) throws CoreException { PropertyFileDocumentModel model= new PropertyFileDocumentModel(textChange.getCurrentDocument(new NullProgressMonitor())); Map<String, NLSSubstitution> newKeyToSubstMap= getNewKeyToSubstitutionMap(substitutions); Map<String, NLSSubstitution> oldKeyToSubstMap= getOldKeyToSubstitutionMap(substitutions); addInsertEdits(textChange, substitutions, newKeyToSubstMap, oldKeyToSubstMap, model); addRemoveEdits(textChange, substitutions, newKeyToSubstMap, oldKeyToSubstMap, model); addReplaceEdits(textChange, substitutions, newKeyToSubstMap, oldKeyToSubstMap, model); }
public InsertEdit insert(KeyValuePair keyValuePair) { KeyValuePairModell keyValuePairModell = new KeyValuePairModell(keyValuePair); int index = findInsertPosition(keyValuePairModell); KeyValuePairModell insertHere = (KeyValuePairModell) fKeyValuePairs.get(index); int offset = insertHere.fOffset - insertHere.fLeadingWhiteSpaces; String extra= ""; //$NON-NLS-1$ if (insertHere instanceof LastKeyValuePair && ((LastKeyValuePair)insertHere).needsNewLine()) { extra= fLineDelimiter; ((LastKeyValuePair)insertHere).resetNeedsNewLine(); } return new InsertEdit(offset, extra + keyValuePairModell.getEncodedText(fLineDelimiter)); }
public PropertyFileDocumentModel(IDocument document) { parsePropertyDocument(document); fLineDelimiter= TextUtilities.getDefaultLineDelimiter(document); }
while (line != null) { if (!SimpleLineReader.isCommentOrWhiteSpace(line)) { int idx = getIndexOfSeparationCharacter(line); if (idx != -1) { String key= line.substring(0, idx);
private static void addReplaceEdits(TextChange textChange, NLSSubstitution[] substitutions, Map newKeyToSubstMap, Map oldKeyToSubstMap, PropertyFileDocumentModel model) { for (int i= 0; i < substitutions.length; i++) { NLSSubstitution substitution= substitutions[i]; if (doReplace(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { KeyValuePair initialPair= new KeyValuePair(substitution.getInitialKey(), substitution.getInitialValue()); KeyValuePair newPair= new KeyValuePair(substitution.getKey(), substitution.getValueNonEmpty()); TextEdit edit= model.replace(initialPair, newPair); if (edit != null) { TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_replace_entry, substitution.getKey()), edit); } } } }
PropertyFileDocumentModel model= new PropertyFileDocumentModel(document); KeyValuePair oldPair= model.getKeyValuePair(fField.getElementName()); if (oldPair == null) return null; ReplaceEdit edit= model.replace(oldPair, newPair); if (edit == null) return null;
private static void addReplaceEdits(TextChange textChange, NLSSubstitution[] substitutions, Map<String, NLSSubstitution> newKeyToSubstMap, Map<String, NLSSubstitution> oldKeyToSubstMap, PropertyFileDocumentModel model) { for (int i= 0; i < substitutions.length; i++) { NLSSubstitution substitution= substitutions[i]; if (doReplace(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { KeyValuePair initialPair= new KeyValuePair(substitution.getInitialKey(), substitution.getInitialValue()); String key= PropertyFileDocumentModel.escape(substitution.getKey(), false); String value= PropertyFileDocumentModel.escape(substitution.getValue(), true) + model.getLineDelimiter(); KeyValuePair newPair= new KeyValuePair(key, value); TextEdit edit= model.replace(initialPair, newPair); if (edit != null) { TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_replace_entry, BasicElementLabels.getJavaElementName(substitution.getKey())), edit); } } } }
public static String escape(String s, boolean escapeCommentCharsAndLeadingWhitespaces) { StringBuffer sb= new StringBuffer(s.length()); int length= s.length(); for (int i= 0; i < length; i++){ char c= s.charAt(i); sb.append(PropertiesFileEscapes.escape(c)); } if(!escapeCommentCharsAndLeadingWhitespaces) return sb.toString(); return escapeLeadingWhiteSpaces(escapeCommentChars(sb.toString())); }
public static Change removeKeys(IPath propertyFilePath, List<String> keys) throws CoreException { String name= Messages.format(NLSMessages.NLSPropertyFileModifier_remove_from_property_file, BasicElementLabels.getPathLabel(propertyFilePath, false)); TextChange textChange= new TextFileChange(name, getPropertyFile(propertyFilePath)); textChange.setTextType("properties"); //$NON-NLS-1$ PropertyFileDocumentModel model= new PropertyFileDocumentModel(textChange.getCurrentDocument(new NullProgressMonitor())); for (Iterator<String> iterator= keys.iterator(); iterator.hasNext();) { String key= iterator.next(); TextEdit edit= model.remove(key); if (edit != null) { TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_remove_entry, BasicElementLabels.getJavaElementName(key)), edit); } } return textChange; }
public InsertEdit insert(String key, String value) { return insert(new KeyValuePair(key, value)); }
private static void addRemoveEdits(TextChange textChange, NLSSubstitution[] substitutions, Map<String, NLSSubstitution> newKeyToSubstMap, Map<String, NLSSubstitution> oldKeyToSubstMap, PropertyFileDocumentModel model) { for (int i= 0; i < substitutions.length; i++) { NLSSubstitution substitution= substitutions[i]; if (doRemove(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { TextEdit edit= model.remove(substitution.getInitialKey()); if (edit != null) { TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_remove_entry, BasicElementLabels.getJavaElementName(substitution.getInitialKey())), edit); } } } }