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 380520 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaSourceHover.java (-17 / +27 lines)
Lines 13-18 Link Here
13
import java.io.IOException;
13
import java.io.IOException;
14
14
15
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.SWTException;
16
import org.eclipse.swt.custom.StyledText;
17
import org.eclipse.swt.custom.StyledText;
17
import org.eclipse.swt.graphics.Point;
18
import org.eclipse.swt.graphics.Point;
18
import org.eclipse.swt.graphics.Rectangle;
19
import org.eclipse.swt.graphics.Rectangle;
Lines 26-32 Link Here
26
import org.eclipse.jface.text.IInformationControlCreator;
27
import org.eclipse.jface.text.IInformationControlCreator;
27
import org.eclipse.jface.text.IRegion;
28
import org.eclipse.jface.text.IRegion;
28
import org.eclipse.jface.text.ITextViewer;
29
import org.eclipse.jface.text.ITextViewer;
29
import org.eclipse.jface.text.source.ISourceViewer;
30
30
31
import org.eclipse.ui.IEditorPart;
31
import org.eclipse.ui.IEditorPart;
32
import org.eclipse.ui.part.IWorkbenchPartOrientation;
32
import org.eclipse.ui.part.IWorkbenchPartOrientation;
Lines 118-141 Link Here
118
		return null;
118
		return null;
119
	}
119
	}
120
120
121
	private String getBracketHoverInfo(ITextViewer textViewer, IRegion region, ITypeRoot editorInput) {
121
	private String getBracketHoverInfo(final ITextViewer textViewer, IRegion region, ITypeRoot editorInput) {
122
		IEditorPart editor= getEditor();
122
		IEditorPart editor= getEditor();
123
		if (!(editor instanceof JavaEditor))
123
		if (!(editor instanceof JavaEditor))
124
			return null;
124
			return null;
125
125
126
		int offset= region.getOffset();
126
		int offset= region.getOffset();
127
		IDocument document= textViewer.getDocument();
127
		IDocument document= textViewer.getDocument();
128
		if (document == null)
129
			return null;
128
		try {
130
		try {
129
			char c= document.getChar(offset);
131
			char c= document.getChar(offset);
130
			if (c != '}')
132
			if (c != '}')
131
				return null;
133
				return null;
132
			JavaPairMatcher matcher= ((JavaEditor) editor).getBracketMatcher();
134
			JavaPairMatcher matcher= ((JavaEditor) editor).getBracketMatcher();
135
			if (matcher == null)
136
				return null;
133
			IRegion match= matcher.match(document, offset);
137
			IRegion match= matcher.match(document, offset);
134
			if (match == null)
138
			if (match == null)
135
				return null;
139
				return null;
136
140
137
			int sourceOffset;
138
			int sourceLength;
139
			String delim= StubUtility.getLineDelimiterUsed(editorInput);
141
			String delim= StubUtility.getLineDelimiterUsed(editorInput);
140
142
141
			CompilationUnit ast= SharedASTProvider.getAST(editorInput, SharedASTProvider.WAIT_NO, null);
143
			CompilationUnit ast= SharedASTProvider.getAST(editorInput, SharedASTProvider.WAIT_NO, null);
Lines 167-192 Link Here
167
			}
169
			}
168
170
169
			int line1= document.getLineOfOffset(nodeStart);
171
			int line1= document.getLineOfOffset(nodeStart);
170
			sourceOffset= document.getLineOffset(line1);
172
			int sourceOffset= document.getLineOffset(line1);
171
			int line2= document.getLineOfOffset(nodeStart + nodeLength);
173
			int line2= document.getLineOfOffset(nodeStart + nodeLength);
172
			int hoveredLine= document.getLineOfOffset(offset);
174
			int hoveredLine= document.getLineOfOffset(offset);
173
			if (line2 > hoveredLine)
175
			if (line2 > hoveredLine)
174
				line2= hoveredLine;
176
				line2= hoveredLine;
175
177
176
			//check if line1 is visible
178
			//check if line1 is visible
177
			JavaEditor javaEditor= (JavaEditor) editor;
178
			final ISourceViewer viewer= javaEditor.getViewer();
179
			final int[] topIndex= new int[1];
179
			final int[] topIndex= new int[1];
180
			StyledText textWidget= viewer.getTextWidget();
180
			StyledText textWidget= textViewer.getTextWidget();
181
			if (textWidget != null) {
181
			if (textWidget == null)
182
				Display display= textWidget.getDisplay();
182
				return null;
183
				display.syncExec(new Runnable() {
183
184
					public void run() {
184
			Display display;
185
						topIndex[0]= viewer.getTopIndex();
185
			try {
186
					}
186
				display= textWidget.getDisplay();
187
				});
187
			} catch (SWTException ex) {
188
				if (ex.code == SWT.ERROR_WIDGET_DISPOSED)
189
					return null;
190
				else
191
					throw ex;
188
			}
192
			}
189
			
193
194
			display.syncExec(new Runnable() {
195
				public void run() {
196
					topIndex[0]= textViewer.getTopIndex();
197
				}
198
			});
199
190
			int topLine= topIndex[0];
200
			int topLine= topIndex[0];
191
			int noOfSourceLines;
201
			int noOfSourceLines;
192
			IRegion endLine;
202
			IRegion endLine;
Lines 208-217 Link Here
208
				endLine= document.getLineInformation(line2);
218
				endLine= document.getLineInformation(line2);
209
				fUpwardShiftInLines= line2 - line1;
219
				fUpwardShiftInLines= line2 - line1;
210
			}
220
			}
211
			sourceLength= (endLine.getOffset() + endLine.getLength()) - sourceOffset;
212
			if (fUpwardShiftInLines == 0)
221
			if (fUpwardShiftInLines == 0)
213
				return null;
222
				return null;
214
223
224
			int sourceLength= (endLine.getOffset() + endLine.getLength()) - sourceOffset;
215
			String source= document.get(sourceOffset, sourceLength);
225
			String source= document.get(sourceOffset, sourceLength);
216
			String[] sourceLines= getTrimmedSource(source, editorInput);
226
			String[] sourceLines= getTrimmedSource(source, editorInput);
217
			if (sourceLines == null)
227
			if (sourceLines == null)

Return to bug 380520