View | Details | Raw Unified | Return to bug 328524 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java (+1 lines)
Lines 692-697 Link Here
692
	public static String PropertiesFileEditorPreferencePage_underline;
692
	public static String PropertiesFileEditorPreferencePage_underline;
693
	public static String PropertiesFileEditorPreferencePage_preview;
693
	public static String PropertiesFileEditorPreferencePage_preview;
694
	public static String PropertiesFileEditorPreferencePage_link;
694
	public static String PropertiesFileEditorPreferencePage_link;
695
	public static String PropertiesFileEditorPreferencePage_when_pasting_escape_backslash_if_required;
695
	public static String SmartTypingConfigurationBlock_autoclose_title;
696
	public static String SmartTypingConfigurationBlock_autoclose_title;
696
	public static String SmartTypingConfigurationBlock_automove_title;
697
	public static String SmartTypingConfigurationBlock_automove_title;
697
	public static String SmartTypingConfigurationBlock_tabs_message_tab_text;
698
	public static String SmartTypingConfigurationBlock_tabs_message_tab_text;
(-)ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties (+1 lines)
Lines 805-810 Link Here
805
805
806
# DO NOT TRANSLATE "org.eclipse.ui.preferencePages.GeneralTextEditor" and "org.eclipse.ui.preferencePages.ColorsAndFonts"
806
# DO NOT TRANSLATE "org.eclipse.ui.preferencePages.GeneralTextEditor" and "org.eclipse.ui.preferencePages.ColorsAndFonts"
807
PropertiesFileEditorPreferencePage_link= Properties file editor preferences. See <a href=\"org.eclipse.ui.preferencePages.GeneralTextEditor\">'Text Editors'</a> for general text editor preferences and <a href=\"org.eclipse.ui.preferencePages.ColorsAndFonts\">'Colors and Fonts'</a> to configure the font. 
807
PropertiesFileEditorPreferencePage_link= Properties file editor preferences. See <a href=\"org.eclipse.ui.preferencePages.GeneralTextEditor\">'Text Editors'</a> for general text editor preferences and <a href=\"org.eclipse.ui.preferencePages.ColorsAndFonts\">'Colors and Fonts'</a> to configure the font. 
808
PropertiesFileEditorPreferencePage_when_pasting_escape_backslash_if_required=When pasting, escape backslash if required
808
809
809
# smart typing block
810
# smart typing block
810
SmartTypingConfigurationBlock_autoclose_title=Automatically close
811
SmartTypingConfigurationBlock_autoclose_title=Automatically close
(-)ui/org/eclipse/jdt/internal/ui/preferences/PropertiesFileEditorPreferencePage.java (+31 lines)
Lines 358-363 Link Here
358
	 */
358
	 */
359
	private IColorManager fColorManager;
359
	private IColorManager fColorManager;
360
360
361
	/**
362
	 * Check box for preference that controls whether backslashes are escaped if required, when
363
	 * pasting in a properties file.
364
	 * 
365
	 * @since 3.7
366
	 */
367
	private Button fCheckboxEscapeBackslash;
361
368
362
	/**
369
	/**
363
	 * Creates a new preference page.
370
	 * Creates a new preference page.
Lines 382-387 Link Here
382
			overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, colorKey + UNDERLINE));
389
			overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, colorKey + UNDERLINE));
383
		}
390
		}
384
391
392
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.PROPERTIES_FILE_WHEN_PASTING_ESCAPE_BACKSLASH_IF_REQUIRED));
393
385
		OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
394
		OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
386
		overlayKeys.toArray(keys);
395
		overlayKeys.toArray(keys);
387
		return keys;
396
		return keys;
Lines 586-591 Link Here
586
595
587
		createSyntaxPage(contents);
596
		createSyntaxPage(contents);
588
597
598
		createTypingPreferences(contents);
599
589
		initialize();
600
		initialize();
590
601
591
		Dialog.applyDialogFont(contents);
602
		Dialog.applyDialogFont(contents);
Lines 622-630 Link Here
622
		filler.setLayoutData(gd);
633
		filler.setLayoutData(gd);
623
	}
634
	}
624
635
636
	private void createTypingPreferences(Composite contents) {
637
		fCheckboxEscapeBackslash= new Button(contents, SWT.CHECK);
638
		fCheckboxEscapeBackslash.setText(PreferencesMessages.PropertiesFileEditorPreferencePage_when_pasting_escape_backslash_if_required);
639
		GridData gd= new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
640
		gd.verticalIndent= 10;
641
		fCheckboxEscapeBackslash.setLayoutData(gd);
642
		fCheckboxEscapeBackslash.addSelectionListener(new SelectionAdapter() {
643
			public void widgetSelected(SelectionEvent e) {
644
				fOverlayStore.setValue(PreferenceConstants.PROPERTIES_FILE_WHEN_PASTING_ESCAPE_BACKSLASH_IF_REQUIRED, fCheckboxEscapeBackslash.getSelection());
645
			}
646
		});
647
	}
648
649
	private void resetTypingPreferences() {
650
		fCheckboxEscapeBackslash.setSelection(fOverlayStore.getBoolean(PreferenceConstants.PROPERTIES_FILE_WHEN_PASTING_ESCAPE_BACKSLASH_IF_REQUIRED));
651
	}
652
625
	private void initialize() {
653
	private void initialize() {
626
654
627
		initializeFields();
655
		initializeFields();
656
		resetTypingPreferences();
628
657
629
		for (int i= 0, n= fSyntaxColorListModel.length; i < n; i++)
658
		for (int i= 0, n= fSyntaxColorListModel.length; i < n; i++)
630
			fHighlightingColorList.add(new HighlightingColorListItem (fSyntaxColorListModel[i][0], fSyntaxColorListModel[i][1], fSyntaxColorListModel[i][1] + BOLD, fSyntaxColorListModel[i][1] + ITALIC, fSyntaxColorListModel[i][1] + STRIKETHROUGH, fSyntaxColorListModel[i][1] + UNDERLINE, null));
659
			fHighlightingColorList.add(new HighlightingColorListItem (fSyntaxColorListModel[i][0], fSyntaxColorListModel[i][1], fSyntaxColorListModel[i][1] + BOLD, fSyntaxColorListModel[i][1] + ITALIC, fSyntaxColorListModel[i][1] + STRIKETHROUGH, fSyntaxColorListModel[i][1] + UNDERLINE, null));
Lines 665-670 Link Here
665
694
666
		handleSyntaxColorListSelection();
695
		handleSyntaxColorListSelection();
667
696
697
		resetTypingPreferences();
698
668
		super.performDefaults();
699
		super.performDefaults();
669
700
670
		fPreviewViewer.invalidateTextPresentation();
701
		fPreviewViewer.invalidateTextPresentation();
(-)ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileAutoEditStrategy.java (-9 / +64 lines)
Lines 17-39 Link Here
17
17
18
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
19
19
20
import org.eclipse.jface.preference.IPreferenceStore;
21
20
import org.eclipse.jface.text.DocumentCommand;
22
import org.eclipse.jface.text.DocumentCommand;
21
import org.eclipse.jface.text.IAutoEditStrategy;
23
import org.eclipse.jface.text.IAutoEditStrategy;
22
import org.eclipse.jface.text.IDocument;
24
import org.eclipse.jface.text.IDocument;
23
25
26
import org.eclipse.jdt.ui.PreferenceConstants;
27
24
/**
28
/**
25
 * Auto edit strategy that escapes a character if it cannot be encoded in the .properties file's
29
 * Auto edit strategy that escapes a character if it cannot be encoded in the .properties file's
26
 * encoding.
30
 * encoding.
27
 * 
31
 * 
32
 * <p>
33
 * Backslashes are escaped only when the pasted text is not perfectly correct for the .properties
34
 * file, i.e. if the text contains
35
 * <ul>
36
 * <li>a single backslash that is not followed by <code>t,n,f,r,u,\</code></li>
37
 * <li>a character which requires Unicode escapes</li>
38
 * </ul>
39
 * Escaping of backslash is controlled by the preference
40
 * {@link PreferenceConstants#PROPERTIES_FILE_WHEN_PASTING_ESCAPE_BACKSLASH_IF_REQUIRED}
41
 * </p>
42
 * 
28
 * @since 3.7
43
 * @since 3.7
29
 */
44
 */
30
public class PropertiesFileAutoEditStrategy implements IAutoEditStrategy {
45
public class PropertiesFileAutoEditStrategy implements IAutoEditStrategy {
31
46
47
	private final IPreferenceStore fPreferenceStore;
32
	private final IFile fFile;
48
	private final IFile fFile;
33
	private String fCharsetName;
49
	private String fCharsetName;
34
	private CharsetEncoder fCharsetEncoder;
50
	private CharsetEncoder fCharsetEncoder;
35
51
36
	public PropertiesFileAutoEditStrategy(IFile file) {
52
	public PropertiesFileAutoEditStrategy(IPreferenceStore preferenceStore, IFile file) {
53
		fPreferenceStore= preferenceStore;
37
		fFile= file;
54
		fFile= file;
38
	}
55
	}
39
56
Lines 52-74 Link Here
52
			return;
69
			return;
53
		}
70
		}
54
71
55
		if (fCharsetEncoder.canEncode(command.text))
72
		String text= command.text;
73
		boolean escapeUnicodeChars= !fCharsetEncoder.canEncode(text);
74
		boolean escapeSlash= (text.length() > 1)
75
				&& fPreferenceStore.getBoolean(PreferenceConstants.PROPERTIES_FILE_WHEN_PASTING_ESCAPE_BACKSLASH_IF_REQUIRED) && (escapeUnicodeChars || shouldEscapeSlashes(text));
76
77
		if (!escapeUnicodeChars && !escapeSlash)
56
			return;
78
			return;
57
79
58
		command.text= escape(command.text);
80
		command.text= escape(text, escapeUnicodeChars, escapeSlash);
59
	}
81
	}
60
82
61
	private static String escape(String s) {
83
	/**
84
	 * Tests if the backslashes should be escaped in the given text.
85
	 * 
86
	 * @param text the text
87
	 * @return <code>true</code> if backslashes need to be escaped, <code>false</code> otherwise
88
	 */
89
	private boolean shouldEscapeSlashes(String text) {
90
		int length= text.length();
91
		for (int i= 0; i < length; i++) {
92
			char c= text.charAt(i);
93
			if (c == '\\') {
94
				if (i < length - 1) {
95
					char nextC= text.charAt(i + 1);
96
					switch (nextC) {
97
						case 't':
98
						case 'n':
99
						case 'f':
100
						case 'r':
101
						case 'u':
102
							break;
103
						case '\\':
104
							i++;
105
							break;
106
						default:
107
							return true;
108
					}
109
				}else {
110
					return true;
111
				}
112
			}
113
		}
114
		return false;
115
	}
116
117
	private static String escape(String s, boolean escapeUnicodeChars, boolean escapeSlash) {
62
		StringBuffer sb= new StringBuffer(s.length());
118
		StringBuffer sb= new StringBuffer(s.length());
63
		int length= s.length();
119
		int length= s.length();
64
		for (int i= 0; i < length; i++) {
120
		for (int i= 0; i < length; i++) {
65
			char c= s.charAt(i);
121
			char c= s.charAt(i);
66
			sb.append(escape(c));
122
			sb.append(escape(c, escapeUnicodeChars, escapeSlash));
67
		}
123
		}
68
		return sb.toString();
124
		return sb.toString();
69
	}
125
	}
70
126
71
	private static String escape(char c) {
127
	private static String escape(char c, boolean escapeUnicodeChars, boolean escapeSlash) {
72
		switch (c) {
128
		switch (c) {
73
			case '\t':
129
			case '\t':
74
				return "\t";//$NON-NLS-1$
130
				return "\t";//$NON-NLS-1$
Lines 79-88 Link Here
79
			case '\r':
135
			case '\r':
80
				return "\r";//$NON-NLS-1$
136
				return "\r";//$NON-NLS-1$
81
			case '\\':
137
			case '\\':
82
				return "\\";//$NON-NLS-1$
138
				return escapeSlash ? "\\\\" : "\\"; //$NON-NLS-1$ //$NON-NLS-2$
83
84
			default:
139
			default:
85
				return PropertiesFileEscapes.escape(c);
140
				return escapeUnicodeChars ? PropertiesFileEscapes.escape(c) : String.valueOf(c);
86
		}
141
		}
87
	}
142
	}
88
}
143
}
(-)ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileSourceViewerConfiguration.java (-1 / +1 lines)
Lines 348-354 Link Here
348
			for (int i= 0; i < autoEditStrategies.length; i++) {
348
			for (int i= 0; i < autoEditStrategies.length; i++) {
349
				stratergies.add(autoEditStrategies[i]);
349
				stratergies.add(autoEditStrategies[i]);
350
			}
350
			}
351
			stratergies.add(new PropertiesFileAutoEditStrategy(((IFileEditorInput)fTextEditor.getEditorInput()).getFile()));
351
			stratergies.add(new PropertiesFileAutoEditStrategy(fPreferenceStore, ((IFileEditorInput)fTextEditor.getEditorInput()).getFile()));
352
			return (IAutoEditStrategy[])stratergies.toArray(new IAutoEditStrategy[stratergies.size()]);
352
			return (IAutoEditStrategy[])stratergies.toArray(new IAutoEditStrategy[stratergies.size()]);
353
		} catch (CoreException e) {
353
		} catch (CoreException e) {
354
			JavaPlugin.log(e);
354
			JavaPlugin.log(e);
(-)ui/org/eclipse/jdt/ui/PreferenceConstants.java (+13 lines)
Lines 3569-3574 Link Here
3569
	public static final String PROPERTIES_FILE_COLORING_ARGUMENT_UNDERLINE= PROPERTIES_FILE_COLORING_ARGUMENT + EDITOR_UNDERLINE_SUFFIX;
3569
	public static final String PROPERTIES_FILE_COLORING_ARGUMENT_UNDERLINE= PROPERTIES_FILE_COLORING_ARGUMENT + EDITOR_UNDERLINE_SUFFIX;
3570
3570
3571
	/**
3571
	/**
3572
	 * A named preference that controls whether backslashes are escaped if required, when pasting in
3573
	 * a properties file.
3574
	 * <p>
3575
	 * Value is of type <code>Boolean</code>.
3576
	 * </p>
3577
	 * 
3578
	 * @since 3.7
3579
	 */
3580
	public static final String PROPERTIES_FILE_WHEN_PASTING_ESCAPE_BACKSLASH_IF_REQUIRED= "pf_when_pasting_escape_backslash_if_required"; //$NON-NLS-1$
3581
3582
	/**
3572
	 * A named preference that stores the content assist LRU history
3583
	 * A named preference that stores the content assist LRU history
3573
	 * <p>
3584
	 * <p>
3574
	 * Value is an XML encoded version of the history.
3585
	 * Value is an XML encoded version of the history.
Lines 3890-3895 Link Here
3890
		store.setDefault(PreferenceConstants.PROPERTIES_FILE_COLORING_COMMENT_BOLD, false);
3901
		store.setDefault(PreferenceConstants.PROPERTIES_FILE_COLORING_COMMENT_BOLD, false);
3891
		store.setDefault(PreferenceConstants.PROPERTIES_FILE_COLORING_COMMENT_ITALIC, false);
3902
		store.setDefault(PreferenceConstants.PROPERTIES_FILE_COLORING_COMMENT_ITALIC, false);
3892
3903
3904
		store.setDefault(PreferenceConstants.PROPERTIES_FILE_WHEN_PASTING_ESCAPE_BACKSLASH_IF_REQUIRED, true);
3905
3893
		// semantic highlighting
3906
		// semantic highlighting
3894
		SemanticHighlightings.initDefaults(store);
3907
		SemanticHighlightings.initDefaults(store);
3895
3908
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 33-38 Link Here
33
 org.eclipse.jdt.ui.tests.performance;x-internal:=true,
33
 org.eclipse.jdt.ui.tests.performance;x-internal:=true,
34
 org.eclipse.jdt.ui.tests.performance.views;x-internal:=true,
34
 org.eclipse.jdt.ui.tests.performance.views;x-internal:=true,
35
 org.eclipse.jdt.ui.tests.preferences;x-internal:=true,
35
 org.eclipse.jdt.ui.tests.preferences;x-internal:=true,
36
 org.eclipse.jdt.ui.tests.propertiesfileeditor;x-internal:=true,
36
 org.eclipse.jdt.ui.tests.quickfix;x-internal:=true,
37
 org.eclipse.jdt.ui.tests.quickfix;x-internal:=true,
37
 org.eclipse.jdt.ui.tests.search;x-internal:=true,
38
 org.eclipse.jdt.ui.tests.search;x-internal:=true,
38
 org.eclipse.jdt.ui.tests.ui.internal.compatibility;x-internal:=true,
39
 org.eclipse.jdt.ui.tests.ui.internal.compatibility;x-internal:=true,
(-)ui/org/eclipse/jdt/ui/tests/AutomatedSuite.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 26-31 Link Here
26
import org.eclipse.jdt.ui.tests.jarexport.JarExportTests;
26
import org.eclipse.jdt.ui.tests.jarexport.JarExportTests;
27
import org.eclipse.jdt.ui.tests.model.ContentProviderTests;
27
import org.eclipse.jdt.ui.tests.model.ContentProviderTests;
28
import org.eclipse.jdt.ui.tests.packageview.PackageExplorerTests;
28
import org.eclipse.jdt.ui.tests.packageview.PackageExplorerTests;
29
import org.eclipse.jdt.ui.tests.propertiesfileeditor.PropertiesFileEditorTests;
29
import org.eclipse.jdt.ui.tests.quickfix.QuickFixTest;
30
import org.eclipse.jdt.ui.tests.quickfix.QuickFixTest;
30
import org.eclipse.jdt.ui.tests.search.SearchTest;
31
import org.eclipse.jdt.ui.tests.search.SearchTest;
31
import org.eclipse.jdt.ui.tests.wizardapi.NewJavaProjectWizardTest;
32
import org.eclipse.jdt.ui.tests.wizardapi.NewJavaProjectWizardTest;
Lines 73-78 Link Here
73
		addTest(BuildpathModifierActionTest.suite());
74
		addTest(BuildpathModifierActionTest.suite());
74
75
75
		addTest(JarExportTests.suite());
76
		addTest(JarExportTests.suite());
77
		addTest(PropertiesFileEditorTests.suite());
76
	}
78
	}
77
}
79
}
78
80
(-)ui/org/eclipse/jdt/ui/tests/propertiesfileeditor/PropertiesFileAutoEditStrategyTest.java (+334 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.ui.tests.propertiesfileeditor;
12
13
import java.io.IOException;
14
import java.io.InputStream;
15
import java.io.Reader;
16
import java.io.StringReader;
17
18
import junit.framework.Test;
19
import junit.framework.TestCase;
20
import junit.framework.TestSuite;
21
22
import org.eclipse.jdt.testplugin.JavaProjectHelper;
23
24
import org.eclipse.core.runtime.CoreException;
25
26
import org.eclipse.core.resources.IFile;
27
import org.eclipse.core.resources.IFolder;
28
29
import org.eclipse.jface.preference.IPreferenceStore;
30
31
import org.eclipse.jface.text.DocumentCommand;
32
33
import org.eclipse.jdt.core.IJavaProject;
34
import org.eclipse.jdt.core.IPackageFragment;
35
import org.eclipse.jdt.core.IPackageFragmentRoot;
36
37
import org.eclipse.jdt.ui.PreferenceConstants;
38
import org.eclipse.jdt.ui.tests.core.ProjectTestSetup;
39
40
import org.eclipse.jdt.internal.ui.JavaPlugin;
41
import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileAutoEditStrategy;
42
43
/**
44
 * PropertiesFileAutoEditStratergyTest
45
 * 
46
 * @since 3.7
47
 */
48
public class PropertiesFileAutoEditStrategyTest extends TestCase {
49
50
	private static final String UTF_8= "UTF-8";
51
	private static final String ISO_8859_1= "ISO-8859-1";
52
53
	private DocumentCommand fDocumentCommand;
54
55
	private IPreferenceStore fPreferenceStore;
56
57
	private PropertiesFileAutoEditStrategy fPropertiesFileAutoEditStrategyISO_8859_1;
58
	private PropertiesFileAutoEditStrategy fPropertiesFileAutoEditStrategyUTF8;
59
60
	private IJavaProject fJProject1;
61
	private IPackageFragmentRoot fSourceFolder;
62
	private IFile fPropertiesFileISO_8859_1;
63
	private IFile fPropertiesFileUTF8;
64
65
	public PropertiesFileAutoEditStrategyTest(String name) {
66
		super(name);
67
		fPreferenceStore= JavaPlugin.getDefault().getPreferenceStore();
68
		fDocumentCommand= new DocumentCommand() {
69
		};
70
	}
71
72
	public static Test suite() {
73
		return new ProjectTestSetup(new TestSuite(PropertiesFileAutoEditStrategyTest.class));
74
	}
75
76
	protected void setUp() throws Exception {
77
		super.setUp();
78
		setEscapeBackslashIfRequired(true); // make sure that the preference is set to true
79
		try {
80
			fJProject1= ProjectTestSetup.getProject();
81
			fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
82
			IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
83
			fPropertiesFileISO_8859_1= write((IFolder)pack.getCorrespondingResource(), "", "Messages_ISO_8859_1.properties");
84
			fPropertiesFileISO_8859_1.setCharset(ISO_8859_1, null);
85
			fPropertiesFileUTF8= write((IFolder)pack.getCorrespondingResource(), "", "Messages_UTF8.properties");
86
			fPropertiesFileUTF8.setCharset(UTF_8, null);
87
			fPropertiesFileAutoEditStrategyISO_8859_1= new PropertiesFileAutoEditStrategy(fPreferenceStore, fPropertiesFileISO_8859_1);
88
			fPropertiesFileAutoEditStrategyUTF8= new PropertiesFileAutoEditStrategy(fPreferenceStore, fPropertiesFileUTF8);
89
		} catch (CoreException e) {
90
			e.printStackTrace();
91
		}
92
	}
93
94
	protected void tearDown() throws Exception {
95
		JavaProjectHelper.clear(fJProject1, ProjectTestSetup.getDefaultClasspath());
96
		super.tearDown();
97
	}
98
99
	//utility methods
100
	private void performTestISO_8859_1() {
101
		fPropertiesFileAutoEditStrategyISO_8859_1.customizeDocumentCommand(null, fDocumentCommand);
102
	}
103
104
	private void performTestAutoEscapeSlashDisabledISO_8859_1() {
105
		setEscapeBackslashIfRequired(false);
106
		fPropertiesFileAutoEditStrategyISO_8859_1.customizeDocumentCommand(null, fDocumentCommand);
107
		setEscapeBackslashIfRequired(true);
108
	}
109
110
	private void performTestUTF8() {
111
		fPropertiesFileAutoEditStrategyUTF8.customizeDocumentCommand(null, fDocumentCommand);
112
	}
113
114
	private void performTestAutoEscapeSlashDisabledUTF8() {
115
		setEscapeBackslashIfRequired(false);
116
		fPropertiesFileAutoEditStrategyUTF8.customizeDocumentCommand(null, fDocumentCommand);
117
		setEscapeBackslashIfRequired(true);
118
	}
119
120
	private void setEscapeBackslashIfRequired(boolean value) {
121
		fPreferenceStore.setValue(PreferenceConstants.PROPERTIES_FILE_WHEN_PASTING_ESCAPE_BACKSLASH_IF_REQUIRED, value);
122
	}
123
124
	private IFile write(IFolder folder, final String content, final String fileName) throws CoreException {
125
		InputStream stream= new InputStream() {
126
			private final Reader fReader= new StringReader(content);
127
128
			public int read() throws IOException {
129
				return fReader.read();
130
			}
131
		};
132
		IFile file= fJProject1.getProject().getFile(folder.getProjectRelativePath().append(fileName));
133
		file.create(stream, true, null);
134
		return file;
135
	}
136
137
	//typing ISO-8859-1
138
	public void testTypeISO_8859_1_01() throws Exception {
139
		fDocumentCommand.text= "\\";
140
		performTestISO_8859_1();
141
		assertEquals("\\", fDocumentCommand.text);
142
	}
143
144
	public void testTypeISO_8859_1_02() throws Exception {
145
		fDocumentCommand.text= "\t";
146
		performTestISO_8859_1();
147
		assertEquals("\t", fDocumentCommand.text);
148
	}
149
150
	public void testTypeISO_8859_1_03() throws Exception {
151
		fDocumentCommand.text= "\f";
152
		performTestISO_8859_1();
153
		assertEquals("\f", fDocumentCommand.text);
154
	}
155
156
	public void testTypeISO_8859_1_04() throws Exception {
157
		fDocumentCommand.text= "\r";
158
		performTestISO_8859_1();
159
		assertEquals("\r", fDocumentCommand.text);
160
	}
161
162
	public void testTypeISO_8859_1_05() throws Exception {
163
		fDocumentCommand.text= "\n";
164
		performTestISO_8859_1();
165
		assertEquals("\n", fDocumentCommand.text);
166
	}
167
168
	public void testTypeISO_8859_1_06() throws Exception {
169
		fDocumentCommand.text= "\u2603";
170
		performTestISO_8859_1();
171
		assertEquals("\\u2603", fDocumentCommand.text);
172
	}
173
174
	//typing UTF-8
175
	public void testTypeUTF8_01() throws Exception {
176
		fDocumentCommand.text= "\u2603";
177
		performTestUTF8();
178
		assertEquals("\u2603", fDocumentCommand.text);
179
	}
180
181
	//paste ISO-8859-1
182
	public void testPasteISO_8859_1_01() throws Exception {
183
		fDocumentCommand.text= "C:\\Program Files\\Java";
184
		performTestISO_8859_1();
185
		assertEquals("C:\\\\Program Files\\\\Java", fDocumentCommand.text);
186
	}
187
188
	public void testPasteISO_8859_1_02() throws Exception {
189
		fDocumentCommand.text= "C:\\new folder\\A.java";
190
		performTestISO_8859_1();
191
		assertEquals("C:\\\\new folder\\\\A.java", fDocumentCommand.text);
192
	}
193
194
	public void testPasteISO_8859_1_03() throws Exception {
195
		fDocumentCommand.text= "\u0926 \u0905";
196
		performTestISO_8859_1();
197
		assertEquals("\\u0926 \\u0905", fDocumentCommand.text);
198
	}
199
200
	public void testPasteISO_8859_1_04() throws Exception {
201
		fDocumentCommand.text= "\u0926 \\u0905";
202
		performTestISO_8859_1();
203
		assertEquals("\\u0926 \\\\u0905", fDocumentCommand.text);
204
	}
205
206
	public void testPasteISO_8859_1_05() throws Exception {
207
		fDocumentCommand.text= "ä \u0926";
208
		performTestISO_8859_1();
209
		assertEquals("ä \\u0926", fDocumentCommand.text);
210
	}
211
212
	public void testPasteISO_8859_1_06() throws Exception {
213
		fDocumentCommand.text= "some text\\";
214
		performTestISO_8859_1();
215
		assertEquals("some text\\\\", fDocumentCommand.text);
216
	}
217
218
	//paste UTF-8
219
	public void testPasteUTF8_01() throws Exception {
220
		fDocumentCommand.text= "C:\\Program Files\\Java";
221
		performTestUTF8();
222
		assertEquals("C:\\\\Program Files\\\\Java", fDocumentCommand.text);
223
	}
224
225
	public void testPasteUTF8_02() throws Exception {
226
		fDocumentCommand.text= "C:\\new folder\\A.java";
227
		performTestUTF8();
228
		assertEquals("C:\\\\new folder\\\\A.java", fDocumentCommand.text);
229
	}
230
231
	public void testPasteUTF8_03() throws Exception {
232
		fDocumentCommand.text= "\u0926 \u0905";
233
		performTestUTF8();
234
		assertEquals("\u0926 \u0905", fDocumentCommand.text);
235
	}
236
237
	public void testPasteUTF8_04() throws Exception {
238
		fDocumentCommand.text= "\u0926 \\u0905";
239
		performTestUTF8();
240
		assertEquals("\u0926 \\u0905", fDocumentCommand.text);
241
	}
242
243
	public void testPasteUTF8_05() throws Exception {
244
		fDocumentCommand.text= "\u0926 \\some text";
245
		performTestUTF8();
246
		assertEquals("\u0926 \\\\some text", fDocumentCommand.text);
247
	}
248
249
	//paste from properties file ISO-8859-1
250
	public void testPasteFromPropertiesFileISO_8859_1_01() throws Exception {
251
		fDocumentCommand.text= "\t \n \f \r";
252
		performTestISO_8859_1();
253
		assertEquals("\t \n \f \r", fDocumentCommand.text);
254
	}
255
256
	public void testPasteFromPropertiesFileISO_8859_1_02() throws Exception {
257
		fDocumentCommand.text= "\\u00e4 \\t \\u0926 \\n";
258
		performTestISO_8859_1();
259
		assertEquals("\\u00e4 \\t \\u0926 \\n", fDocumentCommand.text);
260
	}
261
262
	public void testPasteFromPropertiesFileISO_8859_1_03() throws Exception {
263
		fDocumentCommand.text= "C:\\\\Program Files\\\\Java";
264
		performTestISO_8859_1();
265
		assertEquals("C:\\\\Program Files\\\\Java", fDocumentCommand.text);
266
	}
267
268
	public void testPasteFromPropertiesFileISO_8859_1_04() throws Exception {
269
		fDocumentCommand.text= "C:\\\\new folder\\\\A.java";
270
		performTestISO_8859_1();
271
		assertEquals("C:\\\\new folder\\\\A.java", fDocumentCommand.text);
272
	}
273
274
	public void testPasteFromPropertiesFileISO_8859_1_05() throws Exception {
275
		fDocumentCommand.text= "\\u2603 \\\\u2603";
276
		performTestISO_8859_1();
277
		assertEquals("\\u2603 \\\\u2603", fDocumentCommand.text);
278
	}
279
280
	// paste ISO-8859-1 and PreferenceConstants.PROPERTIES_FILE_ESCAPE_BACKSLASH_ON_PASTE_IF_REQUIRED disabled
281
	public void testAutoEscapeSlashDisabledISO_8859_1_01() throws Exception {
282
		fDocumentCommand.text= "C:\\Program Files\\Java";
283
		performTestAutoEscapeSlashDisabledISO_8859_1();
284
		assertEquals("C:\\Program Files\\Java", fDocumentCommand.text);
285
	}
286
287
	public void testAutoEscapeSlashDisabledISO_8859_1_02() throws Exception {
288
		fDocumentCommand.text= "C:\\new folder\\A.java";
289
		performTestAutoEscapeSlashDisabledISO_8859_1();
290
		assertEquals("C:\\new folder\\A.java", fDocumentCommand.text);
291
	}
292
293
	public void testAutoEscapeSlashDisabledISO_8859_1_03() throws Exception {
294
		fDocumentCommand.text= "\u0926 \\u0905";
295
		performTestAutoEscapeSlashDisabledISO_8859_1();
296
		assertEquals("\\u0926 \\u0905", fDocumentCommand.text);
297
	}
298
299
	//paste UTF-8 and PreferenceConstants.PROPERTIES_FILE_ESCAPE_BACKSLASH_ON_PASTE_IF_REQUIRED disabled
300
	public void testAutoEscapeSlashDisabledUTF8_01() throws Exception {
301
		fDocumentCommand.text= "\u0926 \\some text";
302
		performTestAutoEscapeSlashDisabledUTF8();
303
		assertEquals("\u0926 \\some text", fDocumentCommand.text);
304
	}
305
	
306
	//change encoding of file
307
	public void testChangeEncodingOfFile_01() throws Exception {
308
		fDocumentCommand.text= "\u2603";
309
		performTestUTF8();
310
		assertEquals("\u2603", fDocumentCommand.text);
311
		
312
		fPropertiesFileUTF8.setCharset(ISO_8859_1, null);
313
314
		fDocumentCommand.text= "\u2603";
315
		performTestUTF8();
316
		assertEquals("\\u2603", fDocumentCommand.text);
317
318
		fPropertiesFileUTF8.setCharset(UTF_8, null);
319
	}
320
321
	public void testChangeEncodingOfFile_02() throws Exception {
322
		fDocumentCommand.text= "\u2603";
323
		performTestISO_8859_1();
324
		assertEquals("\\u2603", fDocumentCommand.text);
325
		
326
		fPropertiesFileISO_8859_1.setCharset(UTF_8, null);
327
		
328
		fDocumentCommand.text= "\u2603";
329
		performTestISO_8859_1();
330
		assertEquals("\u2603", fDocumentCommand.text);
331
332
		fPropertiesFileISO_8859_1.setCharset(ISO_8859_1, null);
333
	}
334
}
(-)ui/org/eclipse/jdt/ui/tests/propertiesfileeditor/PropertiesFileEditorTests.java (+25 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.ui.tests.propertiesfileeditor;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
16
public class PropertiesFileEditorTests {
17
18
	public static Test suite() {
19
		TestSuite suite= new TestSuite("Test for org.eclipse.jdt.ui.tests.propertiesfileeditor");
20
		//$JUnit-BEGIN$
21
		suite.addTest(PropertiesFileAutoEditStrategyTest.suite());
22
		//$JUnit-END$
23
		return suite;
24
	}
25
}

Return to bug 328524