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); }
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 Change create(ICompilationUnit cu, NLSSubstitution[] substitutions) throws CoreException { Map<String, NLSSubstitution> newKeyToSubstMap= NLSPropertyFileModifier.getNewKeyToSubstitutionMap(substitutions); Map<String, NLSSubstitution> oldKeyToSubstMap= NLSPropertyFileModifier.getOldKeyToSubstitutionMap(substitutions); if (NLSPropertyFileModifier.doRemove(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { sourceModification.removeKey(substitution, change); if (substitution.isKeyRename() && NLSPropertyFileModifier.doReplace(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { sourceModification.renameKey(substitution, change); if (NLSPropertyFileModifier.doInsert(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { sourceModification.addKey(substitution, change);
public static Change create(NLSSubstitution[] nlsSubstitutions, IPath propertyFilePath) throws CoreException { String name= Messages.format(NLSMessages.NLSPropertyFileModifier_change_name, propertyFilePath.toString()); TextChange textChange= null; if (!Checks.resourceExists(propertyFilePath)) { IProject project= getFileHandle(propertyFilePath).getProject(); String lineDelimiter= StubUtility.getLineDelimiterPreference(project); Document document= new Document(); document.setInitialLineDelimiter(lineDelimiter); textChange= new DocumentChange(name, document); addChanges(textChange, nlsSubstitutions); textChange.perform(new NullProgressMonitor()); String encoding= null; IContentType javaPropertiesContentType= Platform.getContentTypeManager().getContentType("org.eclipse.jdt.core.javaProperties"); //$NON-NLS-1$ IContentType[] contentTypes= Platform.getContentTypeManager().findContentTypesFor(propertyFilePath.lastSegment()); if (contentTypes.length == 0 || contentTypes.length > 1 || !contentTypes[0].equals(javaPropertiesContentType)) { if (javaPropertiesContentType != null) encoding= javaPropertiesContentType.getDefaultCharset(); if (encoding == null) encoding= "ISO-8859-1"; //$NON-NLS-1$ } return new CreateTextFileChange(propertyFilePath, textChange.getCurrentContent(new NullProgressMonitor()), encoding, "properties"); //$NON-NLS-1$ } textChange= new TextFileChange(name, getPropertyFile(propertyFilePath)); textChange.setTextType("properties"); //$NON-NLS-1$ addChanges(textChange, nlsSubstitutions); return textChange; }
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 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); } } } }
result.add(NLSPropertyFileModifier.create(fSubstitutions, getPropertyFilePath())); if (isEclipseNLS() && !createAccessorClass) { Change change= AccessorClassModifier.create(getAccessorCu(), fSubstitutions);
public static Change create(ICompilationUnit cu, NLSSubstitution[] substitutions) throws CoreException { Map newKeyToSubstMap= NLSPropertyFileModifier.getNewKeyToSubstitutionMap(substitutions); Map oldKeyToSubstMap= NLSPropertyFileModifier.getOldKeyToSubstitutionMap(substitutions); if (NLSPropertyFileModifier.doRemove(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { sourceModification.removeKey(substitution, change); if (substitution.isKeyRename() && NLSPropertyFileModifier.doReplace(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { sourceModification.renameKey(substitution, change); if (NLSPropertyFileModifier.doInsert(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { sourceModification.addKey(substitution, change);
public static Change create(NLSSubstitution[] nlsSubstitutions, IPath propertyFilePath) throws CoreException { String name= Messages.format(NLSMessages.NLSPropertyFileModifier_change_name, BasicElementLabels.getPathLabel(propertyFilePath, false)); TextChange textChange= null; if (!Checks.resourceExists(propertyFilePath)) { IProject project= getFileHandle(propertyFilePath).getProject(); String lineDelimiter= StubUtility.getLineDelimiterPreference(project); Document document= new Document(); document.setInitialLineDelimiter(lineDelimiter); textChange= new DocumentChange(name, document); addChanges(textChange, nlsSubstitutions); textChange.perform(new NullProgressMonitor()); String encoding= null; IContentType javaPropertiesContentType= Platform.getContentTypeManager().getContentType("org.eclipse.jdt.core.javaProperties"); //$NON-NLS-1$ IContentType[] contentTypes= Platform.getContentTypeManager().findContentTypesFor(propertyFilePath.lastSegment()); if (contentTypes.length == 0 || contentTypes.length > 1 || !contentTypes[0].equals(javaPropertiesContentType)) { if (javaPropertiesContentType != null) encoding= javaPropertiesContentType.getDefaultCharset(); if (encoding == null) encoding= "ISO-8859-1"; //$NON-NLS-1$ } return new CreateTextFileChange(propertyFilePath, textChange.getCurrentContent(new NullProgressMonitor()), encoding, "properties"); //$NON-NLS-1$ } textChange= new TextFileChange(name, getPropertyFile(propertyFilePath)); textChange.setTextType("properties"); //$NON-NLS-1$ addChanges(textChange, nlsSubstitutions); return textChange; }
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); } } } }
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); } } } }
result.add(NLSPropertyFileModifier.create(fSubstitutions, getPropertyFilePath())); if (isEclipseNLS() && !createAccessorClass) { Change change= AccessorClassModifier.create(getAccessorCu(), fSubstitutions);
private static void addChanges(TextChange textChange, NLSSubstitution[] substitutions) throws CoreException { PropertyFileDocumentModel model= new PropertyFileDocumentModel(textChange.getCurrentDocument(new NullProgressMonitor())); Map newKeyToSubstMap= getNewKeyToSubstitutionMap(substitutions); Map oldKeyToSubstMap= getOldKeyToSubstitutionMap(substitutions); addInsertEdits(textChange, substitutions, newKeyToSubstMap, oldKeyToSubstMap, model); addRemoveEdits(textChange, substitutions, newKeyToSubstMap, oldKeyToSubstMap, model); addReplaceEdits(textChange, substitutions, newKeyToSubstMap, oldKeyToSubstMap, model); }
public static Change create(ICompilationUnit cu, NLSSubstitution[] substitutions) throws CoreException { Map<String, NLSSubstitution> newKeyToSubstMap= NLSPropertyFileModifier.getNewKeyToSubstitutionMap(substitutions); Map<String, NLSSubstitution> oldKeyToSubstMap= NLSPropertyFileModifier.getOldKeyToSubstitutionMap(substitutions); if (NLSPropertyFileModifier.doRemove(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { sourceModification.removeKey(substitution, change); if (substitution.isKeyRename() && NLSPropertyFileModifier.doReplace(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { sourceModification.renameKey(substitution, change); if (NLSPropertyFileModifier.doInsert(substitution, newKeyToSubstMap, oldKeyToSubstMap)) { sourceModification.addKey(substitution, change);
public static Change create(NLSSubstitution[] nlsSubstitutions, IPath propertyFilePath) throws CoreException { String name= Messages.format(NLSMessages.NLSPropertyFileModifier_change_name, BasicElementLabels.getPathLabel(propertyFilePath, false)); TextChange textChange= null; if (!Checks.resourceExists(propertyFilePath)) { IProject project= getFileHandle(propertyFilePath).getProject(); String lineDelimiter= StubUtility.getLineDelimiterPreference(project); Document document= new Document(); document.setInitialLineDelimiter(lineDelimiter); textChange= new DocumentChange(name, document); addChanges(textChange, nlsSubstitutions); textChange.perform(new NullProgressMonitor()); String encoding= null; IContentType javaPropertiesContentType= Platform.getContentTypeManager().getContentType("org.eclipse.jdt.core.javaProperties"); //$NON-NLS-1$ IContentType[] contentTypes= Platform.getContentTypeManager().findContentTypesFor(propertyFilePath.lastSegment()); if (contentTypes.length == 0 || contentTypes.length > 1 || !contentTypes[0].equals(javaPropertiesContentType)) { if (javaPropertiesContentType != null) encoding= javaPropertiesContentType.getDefaultCharset(); if (encoding == null) encoding= "ISO-8859-1"; //$NON-NLS-1$ } return new CreateTextFileChange(propertyFilePath, textChange.getCurrentContent(new NullProgressMonitor()), encoding, "properties"); //$NON-NLS-1$ } textChange= new TextFileChange(name, getPropertyFile(propertyFilePath)); textChange.setTextType("properties"); //$NON-NLS-1$ addChanges(textChange, nlsSubstitutions); return textChange; }
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); } } } }
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); } }
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); } } } }
result.add(NLSPropertyFileModifier.create(fSubstitutions, getPropertyFilePath())); if (isEclipseNLS() && !createAccessorClass) { Change change= AccessorClassModifier.create(getAccessorCu(), fSubstitutions);
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); }