Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 184025 Details for
Bug 328524
[nls tooling] Properties File editor could escape \ on paste
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
fix + tests v0.9
autoescapequickassist13.txt (text/plain), 48.45 KB, created by
Deepak Azad
on 2010-11-29 06:24:50 EST
(
hide
)
Description:
fix + tests v0.9
Filename:
MIME Type:
Creator:
Deepak Azad
Created:
2010-11-29 06:24:50 EST
Size:
48.45 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/EscapeBackslashCompletionProposal.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/EscapeBackslashCompletionProposal.java >diff -N ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/EscapeBackslashCompletionProposal.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/EscapeBackslashCompletionProposal.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,69 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.propertiesfileeditor; >+ >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; >+ >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.contentassist.ICompletionProposal; >+import org.eclipse.jface.text.contentassist.IContextInformation; >+ >+import org.eclipse.jdt.internal.ui.JavaPluginImages; >+ >+/** >+ * Proposal to escape backslashes. >+ * >+ * @since 3.7 >+ */ >+public class EscapeBackslashCompletionProposal implements ICompletionProposal { >+ >+ private final String fProposalText; >+ >+ private final int fOffset; >+ >+ private final int fLength; >+ >+ public EscapeBackslashCompletionProposal(String proposalText, int offset, int length) { >+ fProposalText= proposalText; >+ fOffset= offset; >+ fLength= length; >+ } >+ >+ public void apply(IDocument document) { >+ try { >+ document.replace(fOffset, fLength, fProposalText); >+ } catch (BadLocationException e) { >+ //do nothing >+ } >+ } >+ >+ public Point getSelection(IDocument document) { >+ return null; >+ } >+ >+ public String getAdditionalProposalInfo() { >+ return fProposalText; >+ } >+ >+ public String getDisplayString() { >+ return PropertiesFileEditorMessages.EscapeBackslashCompletionProposal_escapeBackslashes; >+ } >+ >+ public Image getImage() { >+ return JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); >+ } >+ >+ public IContextInformation getContextInformation() { >+ return null; >+ } >+} >\ No newline at end of file >Index: ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesCorrectionAssistant.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesCorrectionAssistant.java >diff -N ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesCorrectionAssistant.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesCorrectionAssistant.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,48 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.propertiesfileeditor; >+ >+import org.eclipse.swt.widgets.Shell; >+ >+import org.eclipse.jface.text.DefaultInformationControl; >+import org.eclipse.jface.text.IInformationControl; >+import org.eclipse.jface.text.IInformationControlCreator; >+import org.eclipse.jface.text.quickassist.QuickAssistAssistant; >+ >+import org.eclipse.ui.IWorkbenchPreferenceConstants; >+import org.eclipse.ui.PlatformUI; >+ >+import org.eclipse.jdt.internal.ui.JavaPlugin; >+ >+/** >+ * The properties file correction assistant. >+ * >+ * @since 3.7 >+ */ >+public class PropertiesCorrectionAssistant extends QuickAssistAssistant { >+ >+ public PropertiesCorrectionAssistant() { >+ super(); >+ >+ setQuickAssistProcessor(new PropertiesCorrectionProcessor(this)); >+ enableColoredLabels(PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS)); >+ >+ setInformationControlCreator(getInformationControlCreator()); >+ } >+ >+ private IInformationControlCreator getInformationControlCreator() { >+ return new IInformationControlCreator() { >+ public IInformationControl createInformationControl(Shell parent) { >+ return new DefaultInformationControl(parent, JavaPlugin.getAdditionalInfoAffordanceString()); >+ } >+ }; >+ } >+} >Index: ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesCorrectionProcessor.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesCorrectionProcessor.java >diff -N ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesCorrectionProcessor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesCorrectionProcessor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,215 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.jdt.internal.ui.propertiesfileeditor; >+ >+import java.util.Arrays; >+ >+import org.eclipse.swt.graphics.Point; >+ >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.BadPartitioningException; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.IDocumentExtension3; >+import org.eclipse.jface.text.ITypedRegion; >+import org.eclipse.jface.text.contentassist.ContentAssistEvent; >+import org.eclipse.jface.text.contentassist.ICompletionListener; >+import org.eclipse.jface.text.contentassist.ICompletionProposal; >+import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext; >+import org.eclipse.jface.text.source.Annotation; >+import org.eclipse.jface.text.source.ISourceViewer; >+import org.eclipse.jface.text.source.TextInvocationContext; >+ >+import org.eclipse.ui.texteditor.spelling.SpellingCorrectionProcessor; >+ >+import org.eclipse.ltk.core.refactoring.NullChange; >+ >+import org.eclipse.jdt.ui.text.java.CompletionProposalComparator; >+ >+import org.eclipse.jdt.internal.ui.JavaPlugin; >+import org.eclipse.jdt.internal.ui.text.correction.CorrectionMessages; >+import org.eclipse.jdt.internal.ui.text.correction.IStatusLineProposal; >+import org.eclipse.jdt.internal.ui.text.correction.proposals.ChangeCorrectionProposal; >+ >+/** >+ * The properties file correction processor. Clients can set pre-computed proposals, and if set the >+ * processor returns only these pre-computed proposals. >+ * >+ * @since 3.7 >+ */ >+public class PropertiesCorrectionProcessor implements org.eclipse.jface.text.quickassist.IQuickAssistProcessor { >+ >+ private PropertiesCorrectionAssistant fAssistant; >+ >+ private String fErrorMessage; >+ >+ private SpellingCorrectionProcessor fSpellingCorrectionProcessor; >+ >+ private ICompletionProposal[] fPreComputedProposals; >+ >+ public PropertiesCorrectionProcessor(PropertiesCorrectionAssistant assistant) { >+ fAssistant= assistant; >+ fSpellingCorrectionProcessor= new SpellingCorrectionProcessor(); >+ fAssistant.addCompletionListener(new ICompletionListener() { >+ >+ public void assistSessionEnded(ContentAssistEvent event) { >+ fAssistant.setStatusLineVisible(false); >+ } >+ >+ public void assistSessionStarted(ContentAssistEvent event) { >+ fAssistant.setStatusLineVisible(true); >+ fAssistant.setStatusMessage(getJumpHintStatusLineMessage()); >+ } >+ >+ public void selectionChanged(ICompletionProposal proposal, boolean smartToggle) { >+ if (proposal instanceof IStatusLineProposal) { >+ IStatusLineProposal statusLineProposal= (IStatusLineProposal)proposal; >+ String message= statusLineProposal.getStatusMessage(); >+ if (message != null) { >+ fAssistant.setStatusMessage(message); >+ return; >+ } >+ } >+ fAssistant.setStatusMessage(getJumpHintStatusLineMessage()); >+ } >+ >+ private String getJumpHintStatusLineMessage() { >+ return ""; //$NON-NLS-1$ >+ } >+ }); >+ } >+ >+ /* >+ * @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int) >+ */ >+ public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext quickAssistContext) { >+ ICompletionProposal[] spellingProposals= fSpellingCorrectionProcessor.computeQuickAssistProposals(quickAssistContext); >+ if (spellingProposals.length > 1) { >+ return spellingProposals; >+ } >+ >+ ISourceViewer viewer= quickAssistContext.getSourceViewer(); >+ int length= viewer != null ? viewer.getSelectedRange().y : 0; >+ TextInvocationContext context= new TextInvocationContext(viewer, quickAssistContext.getOffset(), length); >+ >+ fErrorMessage= null; >+ ICompletionProposal[] res= null; >+ if (fPreComputedProposals != null) { >+ res= fPreComputedProposals; >+ } else { >+ try { >+ res= collectAssists(context); >+ } catch (BadLocationException e) { >+ fErrorMessage= CorrectionMessages.JavaCorrectionProcessor_error_quickassist_message; >+ JavaPlugin.log(e); >+ } catch (BadPartitioningException e) { >+ fErrorMessage= CorrectionMessages.JavaCorrectionProcessor_error_quickassist_message; >+ JavaPlugin.log(e); >+ } >+ } >+ >+ if (res == null || res.length == 0) { >+ return new ICompletionProposal[] { new ChangeCorrectionProposal(CorrectionMessages.NoCorrectionProposal_description, new NullChange(""), 0, null) }; //$NON-NLS-1$ >+ } >+ if (res.length > 1) { >+ Arrays.sort(res, new CompletionProposalComparator()); >+ } >+ fPreComputedProposals= null; >+ return res; >+ } >+ >+ private static ICompletionProposal[] collectAssists(IQuickAssistInvocationContext invocationContext) throws BadLocationException, BadPartitioningException { >+ ISourceViewer sourceViewer= invocationContext.getSourceViewer(); >+ IDocument document= sourceViewer.getDocument(); >+ Point selectedRange= sourceViewer.getSelectedRange(); >+ int selectionOffset= selectedRange.x; >+ int selectionLength= selectedRange.y; >+ int proposalOffset; >+ int proposalLength; >+ String text; >+ if (selectionLength == 0) { >+ // FIXME: separators should not be part of the value partition >+ if (selectionOffset != document.getLength()) { >+ String s= document.get(selectionOffset, 1); >+ if (s.charAt(0) == '=' || s.charAt(0) == ':') { >+ return null; >+ } >+ } >+ >+ ITypedRegion partition= null; >+ if (document instanceof IDocumentExtension3) >+ partition= ((IDocumentExtension3)document).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, invocationContext.getOffset(), false); >+ if (partition == null) >+ return null; >+ >+ String type= partition.getType(); >+ if (!(type.equals(IPropertiesFilePartitions.PROPERTY_VALUE) || type.equals(IDocument.DEFAULT_CONTENT_TYPE))) { >+ return null; >+ } >+ proposalOffset= partition.getOffset(); >+ proposalLength= partition.getLength(); >+ text= document.get(proposalOffset, proposalLength); >+ >+ if (type.equals(IPropertiesFilePartitions.PROPERTY_VALUE)) { >+ text= text.substring(1); //see PropertiesFilePartitionScanner() >+ proposalOffset++; >+ proposalLength--; >+ } >+ } else { >+ proposalOffset= selectionOffset; >+ proposalLength= selectionLength; >+ text= document.get(proposalOffset, proposalLength); >+ } >+ >+ if (PropertiesFileEscapes.containsUnescapedBackslash(text)) >+ return new ICompletionProposal[] { new EscapeBackslashCompletionProposal(PropertiesFileEscapes.escape(text, false, true, false), proposalOffset, proposalLength) }; >+ if (PropertiesFileEscapes.containsEscapedBackslashes(text)) >+ return new ICompletionProposal[] { new UnescapeBackslashCompletionProposal(PropertiesFileEscapes.unescapeBackslashes(text), proposalOffset, proposalLength) }; >+ return null; >+ } >+ >+ /* >+ * @see IContentAssistProcessor#getErrorMessage() >+ */ >+ public String getErrorMessage() { >+ return fErrorMessage; >+ } >+ >+ /* >+ * @see org.eclipse.jface.text.quickassist.IQuickAssistProcessor#canFix(org.eclipse.jface.text.source.Annotation) >+ */ >+ public boolean canFix(Annotation annotation) { >+ return fSpellingCorrectionProcessor.canFix(annotation); >+ } >+ >+ /* >+ * @see org.eclipse.jface.text.quickassist.IQuickAssistProcessor#canAssist(org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext) >+ */ >+ public boolean canAssist(IQuickAssistInvocationContext invocationContext) { >+ try { >+ return collectAssists(invocationContext) != null; >+ } catch (BadLocationException e) { >+ JavaPlugin.log(e); >+ } catch (BadPartitioningException e) { >+ JavaPlugin.log(e); >+ } >+ return false; >+ } >+ >+ /** >+ * Sets the pre-computed proposals. >+ * >+ * @param preComputedProposals the pre-computed proposals >+ */ >+ public void setProposals(ICompletionProposal[] preComputedProposals) { >+ fPreComputedProposals= preComputedProposals; >+ } >+} >Index: ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileAutoEditStrategy.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileAutoEditStrategy.java,v >retrieving revision 1.3 >diff -u -r1.3 PropertiesFileAutoEditStrategy.java >--- ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileAutoEditStrategy.java 5 Nov 2010 05:49:58 -0000 1.3 >+++ ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileAutoEditStrategy.java 29 Nov 2010 11:19:43 -0000 >@@ -14,27 +14,52 @@ > import java.nio.charset.CharsetEncoder; > > import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; > > import org.eclipse.core.resources.IFile; > > import org.eclipse.jface.text.DocumentCommand; > import org.eclipse.jface.text.IAutoEditStrategy; > import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.contentassist.ICompletionProposal; >+import org.eclipse.jface.text.quickassist.IQuickAssistAssistant; >+import org.eclipse.jface.text.quickassist.IQuickAssistProcessor; >+import org.eclipse.jface.text.source.ISourceViewer; >+import org.eclipse.jface.text.source.ISourceViewerExtension3; >+ >+import org.eclipse.ui.progress.WorkbenchJob; > > /** > * Auto edit strategy that escapes a character if it cannot be encoded in the .properties file's > * encoding. > * >+ * <p> >+ * A quick assist to escape backslashes is offered iff the pasted text is not perfectly correct for >+ * the .properties file, i.e. if the text contains >+ * <ul> >+ * <li>an invalid escape sequence as defined by >+ * {@link PropertiesFileEscapes#containsInvalidEscapeSequence(String)}</li> >+ * <li>a character which requires Unicode escapes</li> >+ * </ul> >+ * </p> >+ * > * @since 3.7 > */ > public class PropertiesFileAutoEditStrategy implements IAutoEditStrategy { > > private final IFile fFile; >+ > private String fCharsetName; >+ > private CharsetEncoder fCharsetEncoder; > >- public PropertiesFileAutoEditStrategy(IFile file) { >+ private final ISourceViewer fSourceViewer; >+ >+ public PropertiesFileAutoEditStrategy(IFile file, ISourceViewer sourceViewer) { > fFile= file; >+ fSourceViewer= sourceViewer; > } > > /* >@@ -42,6 +67,10 @@ > * @see org.eclipse.jface.text.IAutoEditStrategy#customizeDocumentCommand(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.DocumentCommand) > */ > public void customizeDocumentCommand(IDocument document, DocumentCommand command) { >+ showProposal(escape(command)); >+ } >+ >+ private ICompletionProposal escape(DocumentCommand command) { > try { > String charsetName= fFile.getCharset(); > if (!charsetName.equals(fCharsetName)) { >@@ -49,40 +78,39 @@ > fCharsetEncoder= Charset.forName(fCharsetName).newEncoder(); > } > } catch (CoreException e) { >- return; >+ return null; > } > >- if (fCharsetEncoder.canEncode(command.text)) >- return; >- >- command.text= escape(command.text); >- } >- >- private static String escape(String s) { >- StringBuffer sb= new StringBuffer(s.length()); >- int length= s.length(); >- for (int i= 0; i < length; i++) { >- char c= s.charAt(i); >- sb.append(escape(c)); >+ String text= command.text; >+ boolean escapeUnicodeChars= !fCharsetEncoder.canEncode(text); >+ boolean escapeBackslash= (text.length() > 1) && ((escapeUnicodeChars && PropertiesFileEscapes.containsUnescapedBackslash(text)) || PropertiesFileEscapes.containsInvalidEscapeSequence(text)); >+ >+ if (!escapeUnicodeChars && !escapeBackslash) >+ return null; >+ >+ command.text= PropertiesFileEscapes.escape(text, false, false, escapeUnicodeChars); >+ if (escapeBackslash) { >+ String proposalText= PropertiesFileEscapes.escape(text, false, true, escapeUnicodeChars); >+ return new EscapeBackslashCompletionProposal(proposalText, command.offset, command.text.length()); > } >- return sb.toString(); >+ return null; > } > >- private static String escape(char c) { >- switch (c) { >- case '\t': >- return "\t";//$NON-NLS-1$ >- case '\n': >- return "\n";//$NON-NLS-1$ >- case '\f': >- return "\f";//$NON-NLS-1$ >- case '\r': >- return "\r";//$NON-NLS-1$ >- case '\\': >- return "\\";//$NON-NLS-1$ >- >- default: >- return PropertiesFileEscapes.escape(c); >+ private void showProposal(final ICompletionProposal proposal) { >+ if (proposal != null && fSourceViewer instanceof ISourceViewerExtension3) { >+ WorkbenchJob job= new WorkbenchJob(PropertiesFileEditorMessages.PropertiesFileAutoEditStrategy_showQuickAssist) { >+ public IStatus runInUIThread(IProgressMonitor monitor) { >+ IQuickAssistAssistant assistant= ((ISourceViewerExtension3)fSourceViewer).getQuickAssistAssistant(); >+ IQuickAssistProcessor processor= assistant.getQuickAssistProcessor(); >+ if (processor instanceof PropertiesCorrectionProcessor) { >+ ((PropertiesCorrectionProcessor)processor).setProposals(new ICompletionProposal[] { proposal }); >+ assistant.showPossibleQuickAssists(); >+ } >+ return Status.OK_STATUS; >+ } >+ }; >+ job.setSystem(true); >+ job.schedule(200); > } > } > } >Index: ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileEditorMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileEditorMessages.java,v >retrieving revision 1.11 >diff -u -r1.11 PropertiesFileEditorMessages.java >--- ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileEditorMessages.java 19 Oct 2010 14:22:01 -0000 1.11 >+++ ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileEditorMessages.java 29 Nov 2010 11:19:43 -0000 >@@ -41,6 +41,7 @@ > // Do not instantiate > } > >+ public static String EscapeBackslashCompletionProposal_escapeBackslashes; > public static String OpenAction_label; > public static String OpenAction_tooltip; > public static String OpenAction_error_title; >@@ -56,7 +57,9 @@ > public static String OpenAction_SelectionDialog_elementLabel; > public static String OpenAction_SelectionDialog_elementLabelWithMatchCount; > >+ public static String PropertiesFileAutoEditStrategy_showQuickAssist; > public static String PropertiesFileHover_MalformedEncoding; >+ public static String UnescapeBackslashCompletionProposal_unescapeBackslashes; > > static { > NLS.initializeMessages(BUNDLE_NAME, PropertiesFileEditorMessages.class); >Index: ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileEditorMessages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileEditorMessages.properties,v >retrieving revision 1.12 >diff -u -r1.12 PropertiesFileEditorMessages.properties >--- ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileEditorMessages.properties 19 Oct 2010 14:22:01 -0000 1.12 >+++ ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileEditorMessages.properties 29 Nov 2010 11:19:43 -0000 >@@ -9,6 +9,7 @@ > # IBM Corporation - initial API and implementation > ############################################################################### > >+EscapeBackslashCompletionProposal_escapeBackslashes=Escape backslashes > OpenAction_label= &Open > OpenAction_tooltip= Open an Editor on the Selected Properties Key > >@@ -30,4 +31,6 @@ > # The first argument is the file name and the second is number of matches in that file > OpenAction_SelectionDialog_elementLabelWithMatchCount= {0} ({1} matches) > >+PropertiesFileAutoEditStrategy_showQuickAssist=Show Quick Assist > PropertiesFileHover_MalformedEncoding=Malformed \\uxxxx encoding: {0} >+UnescapeBackslashCompletionProposal_unescapeBackslashes=Unescape backslashes >Index: ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileEscapes.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileEscapes.java,v >retrieving revision 1.2 >diff -u -r1.2 PropertiesFileEscapes.java >--- ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileEscapes.java 22 Oct 2010 11:26:49 -0000 1.2 >+++ ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileEscapes.java 29 Nov 2010 11:19:43 -0000 >@@ -76,20 +76,52 @@ > * @return escaped string > */ > public static String escape(char c) { >+ return escape(c, true, true, true); >+ } >+ >+ /** >+ * Convert characters in a Java string to the escaped form that must be used in .properties >+ * files. >+ * >+ * @param s the Java string >+ * @param escapeWhitespaceChars if <code>true</code>, escape whitespace characters >+ * @param escapeBackslash if <code>true</code>, escape backslash characters >+ * @param escapeUnicodeChars if <code>true</code>, escape unicode characters >+ * @return escaped string >+ */ >+ public static String escape(String s, boolean escapeWhitespaceChars, boolean escapeBackslash, boolean escapeUnicodeChars) { >+ StringBuffer sb= new StringBuffer(s.length()); >+ int length= s.length(); >+ for (int i= 0; i < length; i++) { >+ char c= s.charAt(i); >+ sb.append(escape(c, escapeWhitespaceChars, escapeBackslash, escapeUnicodeChars)); >+ } >+ return sb.toString(); >+ } >+ >+ /** >+ * Convert a Java char to the escaped form that must be used in .properties files. >+ * >+ * @param c the Java char >+ * @param escapeWhitespaceChars if <code>true</code>, escape whitespace characters >+ * @param escapeBackslash if <code>true</code>, escape backslash characters >+ * @param escapeUnicodeChars if <code>true</code>, escape unicode characters >+ * @return escaped string >+ */ >+ public static String escape(char c, boolean escapeWhitespaceChars, boolean escapeBackslash, boolean escapeUnicodeChars) { > switch (c) { > case '\t': >- return "\\t";//$NON-NLS-1$ >+ return escapeWhitespaceChars ? "\\t" : "\t"; //$NON-NLS-1$//$NON-NLS-2$ > case '\n': >- return "\\n";//$NON-NLS-1$ >+ return escapeWhitespaceChars ? "\\n" : "\n"; //$NON-NLS-1$//$NON-NLS-2$ > case '\f': >- return "\\f";//$NON-NLS-1$ >+ return escapeWhitespaceChars ? "\\f" : "\r"; //$NON-NLS-1$//$NON-NLS-2$ > case '\r': >- return "\\r";//$NON-NLS-1$ >+ return escapeWhitespaceChars ? "\\r" : "\r"; //$NON-NLS-1$//$NON-NLS-2$ > case '\\': >- return "\\\\";//$NON-NLS-1$ >- >+ return escapeBackslash ? "\\\\" : "\\"; //$NON-NLS-1$ //$NON-NLS-2$ > default: >- if (((c < 0x0020) || (c > 0x007e && c <= 0x00a0) || (c > 0x00ff))) { >+ if (escapeUnicodeChars && ((c < 0x0020) || (c > 0x007e && c <= 0x00a0) || (c > 0x00ff))) { > //NBSP (0x00a0) is escaped to differentiate from normal space character > return new StringBuffer() > .append('\\') >@@ -164,10 +196,137 @@ > } > if (isValidEscapedString) { > return outBuffer.toString(); >- } >- else { >+ } else { > String exceptionMessage= Messages.format(PropertiesFileEditorMessages.PropertiesFileHover_MalformedEncoding, outBuffer.toString()); > throw new CoreException(new StatusInfo(IStatus.WARNING, exceptionMessage)); > } > } >+ >+ /** >+ * Unescape backslash characters in a string. >+ * >+ * @param s the escaped string >+ * @return string with backslash characters unescaped >+ */ >+ public static String unescapeBackslashes(String s) { >+ if (s == null) >+ return null; >+ >+ char c; >+ int length= s.length(); >+ StringBuffer outBuffer= new StringBuffer(length); >+ >+ for (int i= 0; i < length;) { >+ c= s.charAt(i++); >+ if (c == '\\') { >+ c= s.charAt(i++); >+ } >+ outBuffer.append(c); >+ } >+ >+ return outBuffer.toString(); >+ } >+ >+ /** >+ * Tests if the given text contains any invalid escape sequence. >+ * >+ * @param text the text >+ * @return <code>true</code> if text contains an invalid escape sequence, <code>false</code> >+ * otherwise >+ */ >+ public static boolean containsInvalidEscapeSequence(String text) { >+ try { >+ //check for invalid unicode escapes >+ unescape(text); >+ } catch (CoreException e) { >+ return true; >+ } >+ >+ int length= text.length(); >+ for (int i= 0; i < length; i++) { >+ char c= text.charAt(i); >+ if (c == '\\') { >+ if (i < length - 1) { >+ char nextC= text.charAt(i + 1); >+ switch (nextC) { >+ case 't': >+ case 'n': >+ case 'f': >+ case 'r': >+ case 'u': >+ break; >+ case '\\': >+ i++; >+ break; >+ default: >+ return true; >+ } >+ } else { >+ return true; >+ } >+ } >+ } >+ return false; >+ } >+ >+ /** >+ * Tests if the given text contains an unescaped backslash character. >+ * >+ * @param text the text >+ * @return <code>true</code> if text contains an unescaped backslash character, >+ * <code>false</code> otherwise >+ */ >+ public static boolean containsUnescapedBackslash(String text) { >+ int length= text.length(); >+ for (int i= 0; i < length; i++) { >+ char c= text.charAt(i); >+ if (c == '\\') { >+ if (i < length - 1) { >+ char nextC= text.charAt(i + 1); >+ switch (nextC) { >+ case '\\': >+ i++; >+ break; >+ default: >+ return true; >+ } >+ } else { >+ return true; >+ } >+ } >+ } >+ return false; >+ } >+ >+ /** >+ * Tests if the given text contains only escaped backslash characters and no unescaped backslash >+ * character. >+ * >+ * @param text the text >+ * @return <code>true</code> if text contains only escaped backslash characters, >+ * <code>false</code> otherwise >+ */ >+ public static boolean containsEscapedBackslashes(String text) { >+ boolean result= false; >+ int length= text.length(); >+ for (int i= 0; i < length; i++) { >+ char c= text.charAt(i); >+ if (c == '\\') { >+ if (i < length - 1) { >+ char nextC= text.charAt(i + 1); >+ switch (nextC) { >+ case '\\': >+ i++; >+ result= true; >+ break; >+ default: >+ return false; >+ } >+ } else { >+ return false; >+ } >+ } >+ } >+ return result; >+ } > } >Index: ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileSourceViewerConfiguration.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileSourceViewerConfiguration.java,v >retrieving revision 1.39 >diff -u -r1.39 PropertiesFileSourceViewerConfiguration.java >--- ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileSourceViewerConfiguration.java 5 Nov 2010 05:49:58 -0000 1.39 >+++ ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileSourceViewerConfiguration.java 29 Nov 2010 11:19:43 -0000 >@@ -33,6 +33,7 @@ > import org.eclipse.jface.text.ITextHover; > import org.eclipse.jface.text.presentation.IPresentationReconciler; > import org.eclipse.jface.text.presentation.PresentationReconciler; >+import org.eclipse.jface.text.quickassist.IQuickAssistAssistant; > import org.eclipse.jface.text.reconciler.IReconciler; > import org.eclipse.jface.text.reconciler.IReconcilingStrategy; > import org.eclipse.jface.text.reconciler.MonoReconciler; >@@ -348,7 +349,7 @@ > for (int i= 0; i < autoEditStrategies.length; i++) { > stratergies.add(autoEditStrategies[i]); > } >- stratergies.add(new PropertiesFileAutoEditStrategy(((IFileEditorInput)fTextEditor.getEditorInput()).getFile())); >+ stratergies.add(new PropertiesFileAutoEditStrategy(((IFileEditorInput)fTextEditor.getEditorInput()).getFile(), sourceViewer)); > return (IAutoEditStrategy[])stratergies.toArray(new IAutoEditStrategy[stratergies.size()]); > } catch (CoreException e) { > JavaPlugin.log(e); >@@ -364,4 +365,18 @@ > public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) { > return new PropertiesFileHover(super.getTextHover(sourceViewer, contentType)); > } >+ >+ /* >+ * (non-Javadoc) >+ * @see org.eclipse.ui.editors.text.TextSourceViewerConfiguration#getQuickAssistAssistant(org.eclipse.jface.text.source.ISourceViewer) >+ * @since 3.7 >+ */ >+ public IQuickAssistAssistant getQuickAssistAssistant(ISourceViewer sourceViewer) { >+ if (getEditor() != null) { >+ return new PropertiesCorrectionAssistant(); >+ } >+ return null; >+ } >+ >+ > } >Index: ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/UnescapeBackslashCompletionProposal.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/UnescapeBackslashCompletionProposal.java >diff -N ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/UnescapeBackslashCompletionProposal.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/UnescapeBackslashCompletionProposal.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,69 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.propertiesfileeditor; >+ >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; >+ >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.contentassist.ICompletionProposal; >+import org.eclipse.jface.text.contentassist.IContextInformation; >+ >+import org.eclipse.jdt.internal.ui.JavaPluginImages; >+ >+/** >+ * Proposal to unescape backslashes. >+ * >+ * @since 3.7 >+ */ >+public class UnescapeBackslashCompletionProposal implements ICompletionProposal { >+ >+ private final String fProposalText; >+ >+ private final int fOffset; >+ >+ private final int fLength; >+ >+ public UnescapeBackslashCompletionProposal(String proposalText, int offset, int length) { >+ fProposalText= proposalText; >+ fOffset= offset; >+ fLength= length; >+ } >+ >+ public void apply(IDocument document) { >+ try { >+ document.replace(fOffset, fLength, fProposalText); >+ } catch (BadLocationException e) { >+ //do nothing >+ } >+ } >+ >+ public Point getSelection(IDocument document) { >+ return null; >+ } >+ >+ public String getAdditionalProposalInfo() { >+ return fProposalText; >+ } >+ >+ public String getDisplayString() { >+ return PropertiesFileEditorMessages.UnescapeBackslashCompletionProposal_unescapeBackslashes; >+ } >+ >+ public Image getImage() { >+ return JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); >+ } >+ >+ public IContextInformation getContextInformation() { >+ return null; >+ } >+} >\ No newline at end of file >#P org.eclipse.jdt.ui.tests >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests/META-INF/MANIFEST.MF,v >retrieving revision 1.17 >diff -u -r1.17 MANIFEST.MF >--- META-INF/MANIFEST.MF 5 Nov 2010 05:34:10 -0000 1.17 >+++ META-INF/MANIFEST.MF 29 Nov 2010 11:19:46 -0000 >@@ -33,6 +33,7 @@ > org.eclipse.jdt.ui.tests.performance;x-internal:=true, > org.eclipse.jdt.ui.tests.performance.views;x-internal:=true, > org.eclipse.jdt.ui.tests.preferences;x-internal:=true, >+ org.eclipse.jdt.ui.tests.propertiesfileeditor;x-internal:=true, > org.eclipse.jdt.ui.tests.quickfix;x-internal:=true, > org.eclipse.jdt.ui.tests.search;x-internal:=true, > org.eclipse.jdt.ui.tests.ui.internal.compatibility;x-internal:=true, >Index: ui/org/eclipse/jdt/ui/tests/AutomatedSuite.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/AutomatedSuite.java,v >retrieving revision 1.55 >diff -u -r1.55 AutomatedSuite.java >--- ui/org/eclipse/jdt/ui/tests/AutomatedSuite.java 25 Nov 2008 11:01:46 -0000 1.55 >+++ ui/org/eclipse/jdt/ui/tests/AutomatedSuite.java 29 Nov 2010 11:19:46 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2010 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -26,6 +26,7 @@ > import org.eclipse.jdt.ui.tests.jarexport.JarExportTests; > import org.eclipse.jdt.ui.tests.model.ContentProviderTests; > import org.eclipse.jdt.ui.tests.packageview.PackageExplorerTests; >+import org.eclipse.jdt.ui.tests.propertiesfileeditor.PropertiesFileEditorTests; > import org.eclipse.jdt.ui.tests.quickfix.QuickFixTest; > import org.eclipse.jdt.ui.tests.search.SearchTest; > import org.eclipse.jdt.ui.tests.wizardapi.NewJavaProjectWizardTest; >@@ -73,6 +74,7 @@ > addTest(BuildpathModifierActionTest.suite()); > > addTest(JarExportTests.suite()); >+ addTest(PropertiesFileEditorTests.suite()); > } > } > >Index: ui/org/eclipse/jdt/ui/tests/propertiesfileeditor/PropertiesFileAutoEditStrategyTest.java >=================================================================== >RCS file: ui/org/eclipse/jdt/ui/tests/propertiesfileeditor/PropertiesFileAutoEditStrategyTest.java >diff -N ui/org/eclipse/jdt/ui/tests/propertiesfileeditor/PropertiesFileAutoEditStrategyTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/ui/tests/propertiesfileeditor/PropertiesFileAutoEditStrategyTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,315 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.ui.tests.propertiesfileeditor; >+ >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.Reader; >+import java.io.StringReader; >+ >+import junit.framework.Test; >+import junit.framework.TestCase; >+import junit.framework.TestSuite; >+ >+import org.eclipse.jdt.testplugin.JavaProjectHelper; >+ >+import org.eclipse.core.runtime.CoreException; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IFolder; >+ >+import org.eclipse.text.tests.Accessor; >+ >+import org.eclipse.jface.text.DocumentCommand; >+import org.eclipse.jface.text.contentassist.ICompletionProposal; >+import org.eclipse.jface.text.source.ISourceViewer; >+ >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IPackageFragment; >+import org.eclipse.jdt.core.IPackageFragmentRoot; >+ >+import org.eclipse.jdt.ui.tests.core.ProjectTestSetup; >+ >+/** >+ * PropertiesFileAutoEditStratergyTest >+ * >+ * @since 3.7 >+ */ >+public class PropertiesFileAutoEditStrategyTest extends TestCase { >+ >+ private static final String UTF_8= "UTF-8"; >+ private static final String ISO_8859_1= "ISO-8859-1"; >+ >+ private DocumentCommand fDocumentCommand; >+ >+ private IJavaProject fJProject1; >+ private IPackageFragmentRoot fSourceFolder; >+ private IFile fPropertiesFileISO_8859_1; >+ private IFile fPropertiesFileUTF8; >+ >+ private Accessor fAccessorPropertiesFileAutoEditStrategyISO_8859_1; >+ >+ private Accessor fAccessorPropertiesFileUTF8; >+ >+ public PropertiesFileAutoEditStrategyTest(String name) { >+ super(name); >+ fDocumentCommand= new DocumentCommand() { >+ }; >+ } >+ >+ public static Test suite() { >+ return new ProjectTestSetup(new TestSuite(PropertiesFileAutoEditStrategyTest.class)); >+ } >+ >+ protected void setUp() throws Exception { >+ super.setUp(); >+ try { >+ fJProject1= ProjectTestSetup.getProject(); >+ fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); >+ IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null); >+ fPropertiesFileISO_8859_1= write((IFolder)pack.getCorrespondingResource(), "", "Messages_ISO_8859_1.properties"); >+ fPropertiesFileISO_8859_1.setCharset(ISO_8859_1, null); >+ fPropertiesFileUTF8= write((IFolder)pack.getCorrespondingResource(), "", "Messages_UTF8.properties"); >+ fPropertiesFileUTF8.setCharset(UTF_8, null); >+ >+ fAccessorPropertiesFileAutoEditStrategyISO_8859_1= new Accessor("org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileAutoEditStrategy", getClass().getClassLoader(), >+ new Class[] { IFile.class, ISourceViewer.class }, new Object[] { fPropertiesFileISO_8859_1, null }); >+ >+ fAccessorPropertiesFileUTF8= new Accessor("org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileAutoEditStrategy", getClass().getClassLoader(), new Class[] { IFile.class, >+ ISourceViewer.class }, new Object[] { fPropertiesFileUTF8, null }); >+ >+ } catch (CoreException e) { >+ e.printStackTrace(); >+ } >+ } >+ >+ protected void tearDown() throws Exception { >+ JavaProjectHelper.clear(fJProject1, ProjectTestSetup.getDefaultClasspath()); >+ super.tearDown(); >+ } >+ >+ //utility methods >+ private Object performTestISO_8859_1() { >+ return fAccessorPropertiesFileAutoEditStrategyISO_8859_1.invoke("escape", new Class[] { DocumentCommand.class }, new Object[] { fDocumentCommand }); >+ } >+ >+ private Object performTestUTF8() { >+ return fAccessorPropertiesFileUTF8.invoke("escape", new Class[] { DocumentCommand.class }, new Object[] { fDocumentCommand }); >+ } >+ >+ private IFile write(IFolder folder, final String content, final String fileName) throws CoreException { >+ InputStream stream= new InputStream() { >+ private final Reader fReader= new StringReader(content); >+ >+ public int read() throws IOException { >+ return fReader.read(); >+ } >+ }; >+ IFile file= fJProject1.getProject().getFile(folder.getProjectRelativePath().append(fileName)); >+ file.create(stream, true, null); >+ return file; >+ } >+ >+ //typing ISO-8859-1 >+ public void testTypeISO_8859_1_01() throws Exception { >+ fDocumentCommand.text= "\\"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("\\", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ public void testTypeISO_8859_1_02() throws Exception { >+ fDocumentCommand.text= "\t"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("\t", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ public void testTypeISO_8859_1_03() throws Exception { >+ fDocumentCommand.text= "\f"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("\f", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ public void testTypeISO_8859_1_04() throws Exception { >+ fDocumentCommand.text= "\r"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("\r", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ public void testTypeISO_8859_1_05() throws Exception { >+ fDocumentCommand.text= "\n"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("\n", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ public void testTypeISO_8859_1_06() throws Exception { >+ fDocumentCommand.text= "\u2603"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("\\u2603", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ //typing UTF-8 >+ public void testTypeUTF8_01() throws Exception { >+ fDocumentCommand.text= "\u2603"; >+ Object proposal= performTestUTF8(); >+ assertEquals("\u2603", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ //paste ISO-8859-1 >+ public void testPasteISO_8859_1_01() throws Exception { >+ fDocumentCommand.text= "C:\\Program Files\\Java"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("C:\\Program Files\\Java", fDocumentCommand.text); >+ assertEquals("C:\\\\Program Files\\\\Java", ((ICompletionProposal)proposal).getAdditionalProposalInfo()); >+ } >+ >+ public void testPasteISO_8859_1_02() throws Exception { >+ fDocumentCommand.text= "C:\\new folder\\A.java"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("C:\\new folder\\A.java", fDocumentCommand.text); >+ assertEquals("C:\\\\new folder\\\\A.java", ((ICompletionProposal)proposal).getAdditionalProposalInfo()); >+ } >+ >+ public void testPasteISO_8859_1_03() throws Exception { >+ fDocumentCommand.text= "\u0926 \u0905"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("\\u0926 \\u0905", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ public void testPasteISO_8859_1_04() throws Exception { >+ fDocumentCommand.text= "\u0926 \\u0905"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("\\u0926 \\u0905", fDocumentCommand.text); >+ assertEquals("\\u0926 \\\\u0905", ((ICompletionProposal)proposal).getAdditionalProposalInfo()); >+ } >+ >+ public void testPasteISO_8859_1_05() throws Exception { >+ fDocumentCommand.text= "ä \u0926"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("ä \\u0926", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ public void testPasteISO_8859_1_06() throws Exception { >+ fDocumentCommand.text= "some text\\"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("some text\\", fDocumentCommand.text); >+ assertEquals("some text\\\\", ((ICompletionProposal)proposal).getAdditionalProposalInfo()); >+ } >+ >+ //paste UTF-8 >+ public void testPasteUTF8_01() throws Exception { >+ fDocumentCommand.text= "C:\\Program Files\\Java"; >+ Object proposal= performTestUTF8(); >+ assertEquals("C:\\Program Files\\Java", fDocumentCommand.text); >+ assertEquals("C:\\\\Program Files\\\\Java", ((ICompletionProposal)proposal).getAdditionalProposalInfo()); >+ } >+ >+ public void testPasteUTF8_02() throws Exception { >+ fDocumentCommand.text= "C:\\new folder\\A.java"; >+ Object proposal= performTestUTF8(); >+ assertEquals("C:\\new folder\\A.java", fDocumentCommand.text); >+ assertEquals("C:\\\\new folder\\\\A.java", ((ICompletionProposal)proposal).getAdditionalProposalInfo()); >+ } >+ >+ public void testPasteUTF8_03() throws Exception { >+ fDocumentCommand.text= "\u0926 \u0905"; >+ Object proposal= performTestUTF8(); >+ assertEquals("\u0926 \u0905", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ public void testPasteUTF8_04() throws Exception { >+ fDocumentCommand.text= "\u0926 \\u0905"; >+ Object proposal= performTestUTF8(); >+ assertEquals("\u0926 \\u0905", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ public void testPasteUTF8_05() throws Exception { >+ fDocumentCommand.text= "\u0926 \\some text"; >+ Object proposal= performTestUTF8(); >+ assertEquals("\u0926 \\some text", fDocumentCommand.text); >+ assertEquals("\u0926 \\\\some text", ((ICompletionProposal)proposal).getAdditionalProposalInfo()); >+ } >+ >+ //paste from properties file ISO-8859-1 >+ public void testPasteFromPropertiesFileISO_8859_1_01() throws Exception { >+ fDocumentCommand.text= "\t \n \f \r"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("\t \n \f \r", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ public void testPasteFromPropertiesFileISO_8859_1_02() throws Exception { >+ fDocumentCommand.text= "\\u00e4 \\t \\u0926 \\n"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("\\u00e4 \\t \\u0926 \\n", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ public void testPasteFromPropertiesFileISO_8859_1_03() throws Exception { >+ fDocumentCommand.text= "C:\\\\Program Files\\\\Java"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("C:\\\\Program Files\\\\Java", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ public void testPasteFromPropertiesFileISO_8859_1_04() throws Exception { >+ fDocumentCommand.text= "C:\\\\new folder\\\\A.java"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("C:\\\\new folder\\\\A.java", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ public void testPasteFromPropertiesFileISO_8859_1_05() throws Exception { >+ fDocumentCommand.text= "\\u2603 \\\\u2603"; >+ Object proposal= performTestISO_8859_1(); >+ assertEquals("\\u2603 \\\\u2603", fDocumentCommand.text); >+ assertNull(proposal); >+ } >+ >+ //change encoding of file >+ public void testChangeEncodingOfFile_01() throws Exception { >+ fDocumentCommand.text= "\u2603"; >+ performTestUTF8(); >+ assertEquals("\u2603", fDocumentCommand.text); >+ >+ fPropertiesFileUTF8.setCharset(ISO_8859_1, null); >+ >+ fDocumentCommand.text= "\u2603"; >+ performTestUTF8(); >+ assertEquals("\\u2603", fDocumentCommand.text); >+ >+ fPropertiesFileUTF8.setCharset(UTF_8, null); >+ } >+ >+ public void testChangeEncodingOfFile_02() throws Exception { >+ fDocumentCommand.text= "\u2603"; >+ performTestISO_8859_1(); >+ assertEquals("\\u2603", fDocumentCommand.text); >+ >+ fPropertiesFileISO_8859_1.setCharset(UTF_8, null); >+ >+ fDocumentCommand.text= "\u2603"; >+ performTestISO_8859_1(); >+ assertEquals("\u2603", fDocumentCommand.text); >+ >+ fPropertiesFileISO_8859_1.setCharset(ISO_8859_1, null); >+ } >+} >Index: ui/org/eclipse/jdt/ui/tests/propertiesfileeditor/PropertiesFileEditorTests.java >=================================================================== >RCS file: ui/org/eclipse/jdt/ui/tests/propertiesfileeditor/PropertiesFileEditorTests.java >diff -N ui/org/eclipse/jdt/ui/tests/propertiesfileeditor/PropertiesFileEditorTests.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/ui/tests/propertiesfileeditor/PropertiesFileEditorTests.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,25 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.ui.tests.propertiesfileeditor; >+ >+import junit.framework.Test; >+import junit.framework.TestSuite; >+ >+public class PropertiesFileEditorTests { >+ >+ public static Test suite() { >+ TestSuite suite= new TestSuite("Test for org.eclipse.jdt.ui.tests.propertiesfileeditor"); >+ //$JUnit-BEGIN$ >+ suite.addTest(PropertiesFileAutoEditStrategyTest.suite()); >+ //$JUnit-END$ >+ return suite; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 328524
:
181574
|
181613
|
182449
|
182556
|
183841
|
184015
|
184025
|
184574
|
184585
|
184598
|
184619