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 (-48 / +54 lines)
Lines 12-17 Link Here
12
12
13
import org.eclipse.core.runtime.Assert;
13
import org.eclipse.core.runtime.Assert;
14
14
15
import org.eclipse.core.filebuffers.FileBuffers;
16
import org.eclipse.core.filebuffers.ITextFileBuffer;
17
import org.eclipse.core.filebuffers.LocationKind;
18
15
import org.eclipse.core.resources.IStorage;
19
import org.eclipse.core.resources.IStorage;
16
20
17
import org.eclipse.swt.widgets.Display;
21
import org.eclipse.swt.widgets.Display;
Lines 27-35 Link Here
27
31
28
import org.eclipse.ui.IEditorInput;
32
import org.eclipse.ui.IEditorInput;
29
import org.eclipse.ui.IEditorPart;
33
import org.eclipse.ui.IEditorPart;
34
import org.eclipse.ui.IFileEditorInput;
30
import org.eclipse.ui.PartInitException;
35
import org.eclipse.ui.PartInitException;
31
import org.eclipse.ui.texteditor.IEditorStatusLine;
36
import org.eclipse.ui.texteditor.IEditorStatusLine;
32
import org.eclipse.ui.texteditor.ITextEditor;
33
37
34
import org.eclipse.jdt.core.JavaModelException;
38
import org.eclipse.jdt.core.JavaModelException;
35
import org.eclipse.jdt.core.dom.ITypeBinding;
39
import org.eclipse.jdt.core.dom.ITypeBinding;
Lines 109-166 Link Here
109
			return;
113
			return;
110
		}
114
		}
111
115
112
		// Reveal the key in the properties file
116
		IEditorInput input= editor.getEditorInput();
113
		if (editor instanceof ITextEditor) {
117
		  if (input instanceof IFileEditorInput) {
114
			IRegion region= null;
118
		   ITextFileBuffer buffer= FileBuffers.getTextFileBufferManager().getTextFileBuffer(
115
			boolean found= false;
119
				   ((IFileEditorInput)input).getFile().getFullPath(), LocationKind.IFILE);
116
120
			   if (buffer != null) {
117
			// Find key in document
121
			    // Find key in document
118
			IEditorInput editorInput= editor.getEditorInput();
122
			    IDocument document= buffer.getDocument();
119
			IDocument document= ((ITextEditor)editor).getDocumentProvider().getDocument(editorInput);
123
			    boolean found= false;
120
			if (document != null) {
124
			    IRegion region= null;
121
				FindReplaceDocumentAdapter finder= new FindReplaceDocumentAdapter(document);
125
				if (document != null) {
122
				PropertyKeyHyperlinkDetector detector= new PropertyKeyHyperlinkDetector();
126
					FindReplaceDocumentAdapter finder= new FindReplaceDocumentAdapter(document);
123
				detector.setContext(editor);
127
					PropertyKeyHyperlinkDetector detector= new PropertyKeyHyperlinkDetector();
124
				String key= PropertyFileDocumentModel.unwindEscapeChars(fKeyName);
128
					detector.setContext(editor);
125
				int offset= document.getLength() - 1;
129
					String key= PropertyFileDocumentModel.unwindEscapeChars(fKeyName);
126
				try {
130
					int offset= document.getLength() - 1;
127
					while (!found && offset >= 0) {
131
					try {
128
						region= finder.find(offset, key, false, true, false, false);
132
						while (!found && offset >= 0) {
129
						if (region == null)
133
							region= finder.find(offset, key, false, true, false, false);
130
							offset= -1;
134
							if (region == null)
131
						else {
135
								offset= -1;
132
							// test whether it's the key
136
							else {
133
							IHyperlink[] hyperlinks= detector.detectHyperlinks(null, region, false);
137
								// test whether it's the key
134
							if (hyperlinks != null) {
138
								IHyperlink[] hyperlinks= detector.detectHyperlinks(null, region, false);
135
								for (int i= 0; i < hyperlinks.length; i++) {
139
								if (hyperlinks != null) {
136
									IRegion hyperlinkRegion= hyperlinks[i].getHyperlinkRegion();
140
									for (int i= 0; i < hyperlinks.length; i++) {
137
									found= key.equals(document.get(hyperlinkRegion.getOffset(), hyperlinkRegion.getLength()));
141
										IRegion hyperlinkRegion= hyperlinks[i].getHyperlinkRegion();
142
										found= key.equals(document.get(hyperlinkRegion.getOffset(), hyperlinkRegion.getLength()));
143
									}
144
								} else if (document instanceof IDocumentExtension3) {
145
									// Fall back: test using properties file partitioning
146
									ITypedRegion partition= null;
147
									partition= ((IDocumentExtension3)document).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, region.getOffset(), false);
148
									found= IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
149
											&& key.equals(document.get(partition.getOffset(), partition.getLength()).trim());
138
								}
150
								}
139
							} else if (document instanceof IDocumentExtension3) {
151
								// Prevent endless loop (panic code, shouldn't be needed)
140
								// Fall back: test using properties file partitioning
152
								if (offset == region.getOffset())
141
								ITypedRegion partition= null;
153
									offset= -1;
142
								partition= ((IDocumentExtension3)document).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, region.getOffset(), false);
154
								else
143
								found= IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
155
									offset= region.getOffset();
144
										&& key.equals(document.get(partition.getOffset(), partition.getLength()).trim());
145
							}
156
							}
146
							// Prevent endless loop (panic code, shouldn't be needed)
147
							if (offset == region.getOffset())
148
								offset= -1;
149
							else
150
								offset= region.getOffset();
151
						}
157
						}
158
					} catch (BadLocationException ex) {
159
						found= false;
160
					} catch (BadPartitioningException e1) {
161
						found= false;
152
					}
162
					}
153
				} catch (BadLocationException ex) {
154
					found= false;
155
				} catch (BadPartitioningException e1) {
156
					found= false;
157
				}
163
				}
158
			}
164
				if (found)
159
			if (found)
165
					EditorUtility.revealInEditor(editor, region);
160
				EditorUtility.revealInEditor(editor, region);
166
				else {
161
			else {
167
					EditorUtility.revealInEditor(editor, 0, 0);
162
				EditorUtility.revealInEditor(editor, 0, 0);
168
					showErrorInStatusLine(editor, Messages.format(JavaEditorMessages.Editor_OpenPropertiesFile_error_keyNotFound, fKeyName));
163
				showErrorInStatusLine(editor, Messages.format(JavaEditorMessages.Editor_OpenPropertiesFile_error_keyNotFound, fKeyName));
169
				}
164
			}
170
			}
165
		}
171
		}
166
	}
172
	}

Return to bug 97228