Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 97228 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/jdt/internal/ui/javaeditor/NLSKeyHyperlink.java (-52 / +51 lines)
Lines 10-21 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.javaeditor;
11
package org.eclipse.jdt.internal.ui.javaeditor;
12
12
13
import org.eclipse.swt.widgets.Display;
14
15
import org.eclipse.core.runtime.Assert;
13
import org.eclipse.core.runtime.Assert;
14
import org.eclipse.core.runtime.IPath;
15
16
import org.eclipse.core.filebuffers.FileBuffers;
17
import org.eclipse.core.filebuffers.ITextFileBuffer;
18
import org.eclipse.core.filebuffers.LocationKind;
16
19
17
import org.eclipse.core.resources.IStorage;
20
import org.eclipse.core.resources.IStorage;
18
21
22
import org.eclipse.swt.widgets.Display;
23
19
import org.eclipse.jface.text.BadLocationException;
24
import org.eclipse.jface.text.BadLocationException;
20
import org.eclipse.jface.text.BadPartitioningException;
25
import org.eclipse.jface.text.BadPartitioningException;
21
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
26
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
Lines 27-36 Link Here
27
32
28
import org.eclipse.ui.IEditorInput;
33
import org.eclipse.ui.IEditorInput;
29
import org.eclipse.ui.IEditorPart;
34
import org.eclipse.ui.IEditorPart;
35
import org.eclipse.ui.IFileEditorInput;
30
import org.eclipse.ui.PartInitException;
36
import org.eclipse.ui.PartInitException;
31
32
import org.eclipse.ui.texteditor.IEditorStatusLine;
37
import org.eclipse.ui.texteditor.IEditorStatusLine;
33
import org.eclipse.ui.texteditor.ITextEditor;
34
38
35
import org.eclipse.jdt.core.JavaModelException;
39
import org.eclipse.jdt.core.JavaModelException;
36
import org.eclipse.jdt.core.dom.ITypeBinding;
40
import org.eclipse.jdt.core.dom.ITypeBinding;
Lines 42-48 Link Here
42
import org.eclipse.jdt.internal.corext.util.Messages;
46
import org.eclipse.jdt.internal.corext.util.Messages;
43
47
44
import org.eclipse.jdt.internal.ui.propertiesfileeditor.IPropertiesFilePartitions;
48
import org.eclipse.jdt.internal.ui.propertiesfileeditor.IPropertiesFilePartitions;
45
import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertyKeyHyperlinkDetector;
46
import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
49
import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
47
50
48
51
Lines 121-178 Link Here
121
			return;
124
			return;
122
		}
125
		}
123
126
124
		// Reveal the key in the properties file
127
		// Reveal the key in the editor
125
		if (editor instanceof ITextEditor) {
128
		IEditorInput input = editor.getEditorInput();
126
			IRegion region= null;
129
		if (input instanceof IFileEditorInput) {
127
			boolean found= false;
130
			IPath path= ((IFileEditorInput)input).getFile().getFullPath();
128
131
			ITextFileBuffer buffer= FileBuffers.getTextFileBufferManager().getTextFileBuffer(
129
			// Find key in document
132
					path, LocationKind.IFILE);
130
			IEditorInput editorInput= editor.getEditorInput();
133
			if (buffer != null) {
131
			IDocument document= ((ITextEditor)editor).getDocumentProvider().getDocument(editorInput);
134
				// Find key in document
132
			if (document != null) {
135
				IDocument document= buffer.getDocument();
133
				FindReplaceDocumentAdapter finder= new FindReplaceDocumentAdapter(document);
136
				boolean found= false;
134
				PropertyKeyHyperlinkDetector detector= new PropertyKeyHyperlinkDetector();
137
				IRegion region= null;
135
				detector.setContext(editor);
138
				if (document != null) {
136
				String key= PropertyFileDocumentModel.unwindEscapeChars(keyName);
139
					FindReplaceDocumentAdapter finder= new FindReplaceDocumentAdapter(document);
137
				int offset= document.getLength() - 1;
140
					String key= PropertyFileDocumentModel.unwindEscapeChars(keyName);
138
				try {
141
					int offset= document.getLength() - 1;
139
					while (!found && offset >= 0) {
142
					try {
140
						region= finder.find(offset, key, false, true, false, false);
143
						while (!found && offset >= 0) {
141
						if (region == null)
144
							region= finder.find(offset, key, false, true, false, false);
142
							offset= -1;
145
							if (region == null)
143
						else {
146
								offset= -1;
144
							// test whether it's the key
147
							else {
145
							IHyperlink[] hyperlinks= detector.detectHyperlinks(null, region, false);
148
								// test whether it's the key
146
							if (hyperlinks != null) {
149
								if (document instanceof IDocumentExtension3) {
147
								for (int i= 0; i < hyperlinks.length; i++) {
150
									// test using properties file partitioning
148
									IRegion hyperlinkRegion= hyperlinks[i].getHyperlinkRegion();
151
									ITypedRegion partition= null;
149
									found= key.equals(document.get(hyperlinkRegion.getOffset(), hyperlinkRegion.getLength()));
152
									partition= ((IDocumentExtension3)document).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, region.getOffset(), false);
153
									found= IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
154
											&& key.equals(document.get(partition.getOffset(), partition.getLength()).trim());
150
								}
155
								}
151
							} else if (document instanceof IDocumentExtension3) {
156
								// Prevent endless loop (panic code, shouldn't be needed)
152
								// Fall back: test using properties file partitioning
157
								if (offset == region.getOffset())
153
								ITypedRegion partition= null;
158
									offset= -1;
154
								partition= ((IDocumentExtension3)document).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, region.getOffset(), false);
159
								else
155
								found= IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
160
									offset= region.getOffset();
156
										&& key.equals(document.get(partition.getOffset(), partition.getLength()).trim());
157
							}
161
							}
158
							// Prevent endless loop (panic code, shouldn't be needed)
159
							if (offset == region.getOffset())
160
								offset= -1;
161
							else
162
								offset= region.getOffset();
163
						}
162
						}
163
					} catch (BadLocationException ex) {
164
						found= false;
165
					} catch (BadPartitioningException e1) {
166
						found= false;
164
					}
167
					}
165
				} catch (BadLocationException ex) {
166
					found= false;
167
				} catch (BadPartitioningException e1) {
168
					found= false;
169
				}
168
				}
170
			}
169
				if (found)
171
			if (found)
170
					EditorUtility.revealInEditor(editor, region);
172
				EditorUtility.revealInEditor(editor, region);
171
				else {
173
			else {
172
					EditorUtility.revealInEditor(editor, 0, 0);
174
				EditorUtility.revealInEditor(editor, 0, 0);
173
					showErrorInStatusLine(editor, Messages.format(JavaEditorMessages.Editor_OpenPropertiesFile_error_keyNotFound, keyName));
175
				showErrorInStatusLine(editor, Messages.format(JavaEditorMessages.Editor_OpenPropertiesFile_error_keyNotFound, keyName));
174
				}
176
			}
175
			}
177
		}
176
		}
178
	}
177
	}

Return to bug 97228