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

Collapse All | Expand All

(-)ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementImplementationHyperlink.java (-2 / +44 lines)
Lines 12-17 Link Here
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.List;
15
16
16
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
Lines 39-45 Link Here
39
import org.eclipse.jdt.core.IJavaElement;
40
import org.eclipse.jdt.core.IJavaElement;
40
import org.eclipse.jdt.core.IMethod;
41
import org.eclipse.jdt.core.IMethod;
41
import org.eclipse.jdt.core.IType;
42
import org.eclipse.jdt.core.IType;
43
import org.eclipse.jdt.core.ITypeHierarchy;
42
import org.eclipse.jdt.core.ITypeRoot;
44
import org.eclipse.jdt.core.ITypeRoot;
45
import org.eclipse.jdt.core.JavaModelException;
43
import org.eclipse.jdt.core.dom.ASTNode;
46
import org.eclipse.jdt.core.dom.ASTNode;
44
import org.eclipse.jdt.core.dom.CompilationUnit;
47
import org.eclipse.jdt.core.dom.CompilationUnit;
45
import org.eclipse.jdt.core.dom.Expression;
48
import org.eclipse.jdt.core.dom.Expression;
Lines 59-64 Link Here
59
import org.eclipse.jdt.internal.corext.dom.Bindings;
62
import org.eclipse.jdt.internal.corext.dom.Bindings;
60
import org.eclipse.jdt.internal.corext.util.JdtFlags;
63
import org.eclipse.jdt.internal.corext.util.JdtFlags;
61
import org.eclipse.jdt.internal.corext.util.Messages;
64
import org.eclipse.jdt.internal.corext.util.Messages;
65
import org.eclipse.jdt.internal.corext.util.MethodOverrideTester;
62
66
63
import org.eclipse.jdt.ui.JavaElementLabels;
67
import org.eclipse.jdt.ui.JavaElementLabels;
64
import org.eclipse.jdt.ui.SharedASTProvider;
68
import org.eclipse.jdt.ui.SharedASTProvider;
Lines 200-206 Link Here
200
				}
204
				}
201
				try {
205
				try {
202
					String methodLabel= JavaElementLabels.getElementLabel(javaElement, JavaElementLabels.DEFAULT_QUALIFIED);
206
					String methodLabel= JavaElementLabels.getElementLabel(javaElement, JavaElementLabels.DEFAULT_QUALIFIED);
203
					monitor.beginTask(Messages.format(JavaEditorMessages.JavaElementImplementationHyperlink_search_method_implementors, methodLabel), 100);
207
					monitor.beginTask(Messages.format(JavaEditorMessages.JavaElementImplementationHyperlink_search_method_implementors, methodLabel), 10);
208
					ITypeHierarchy superTypeHierarchy= type.newSupertypeHierarchy(new SubProgressMonitor(monitor, 3));
209
					IType[] rootInterfaces= superTypeHierarchy.getRootInterfaces();
210
					IType superType;
211
					if (rootInterfaces.length == 0) {
212
						superType= type;
213
					} else {
214
						superType= getDeclaringType(superTypeHierarchy, rootInterfaces);
215
						if (superType == null)
216
							return;
217
					}
204
					SearchRequestor requestor= new SearchRequestor() {
218
					SearchRequestor requestor= new SearchRequestor() {
205
						public void acceptSearchMatch(SearchMatch match) throws CoreException {
219
						public void acceptSearchMatch(SearchMatch match) throws CoreException {
206
							if (match.getAccuracy() == SearchMatch.A_ACCURATE) {
220
							if (match.getAccuracy() == SearchMatch.A_ACCURATE) {
Lines 219-225 Link Here
219
					Assert.isNotNull(pattern);
233
					Assert.isNotNull(pattern);
220
					SearchParticipant[] participants= new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
234
					SearchParticipant[] participants= new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
221
					SearchEngine engine= new SearchEngine();
235
					SearchEngine engine= new SearchEngine();
222
					engine.search(pattern, participants, SearchEngine.createHierarchyScope(type), requestor, new SubProgressMonitor(monitor, 100));
236
					engine.search(pattern, participants, SearchEngine.createHierarchyScope(superType), requestor, new SubProgressMonitor(monitor, 7));
223
237
224
					if (monitor.isCanceled()) {
238
					if (monitor.isCanceled()) {
225
						throw new OperationCanceledException();
239
						throw new OperationCanceledException();
Lines 230-235 Link Here
230
					monitor.done();
244
					monitor.done();
231
				}
245
				}
232
			}
246
			}
247
248
			/**
249
			 * Get the declaring type for the given method.
250
			 * 
251
			 * @param superTypeHierarchy the super type hierarchy
252
			 * @param rootInterfaces the array of super interfaces
253
			 * @return the super interface if the method is declared only in one of the given super
254
			 *         interfaces, the declaring type itself if the method is not declared in any
255
			 *         super interface, null otherwise
256
			 * @throws JavaModelException if the java element does not exist or if an exception
257
			 *             occurs while accessing its corresponding resource
258
			 */
259
			public IType getDeclaringType(ITypeHierarchy superTypeHierarchy, IType[] rootInterfaces) throws JavaModelException {
260
				List typesContainingMethod= new ArrayList(rootInterfaces.length);
261
				MethodOverrideTester methodOverrideTester= new MethodOverrideTester(type, superTypeHierarchy);
262
				for (int i= 0; i < rootInterfaces.length; i++) {
263
					IMethod[] methods= rootInterfaces[i].getMethods();
264
					for (int j= 0; j < methods.length; j++) {
265
						if (methodOverrideTester.isSubsignature(methods[j], (IMethod)javaElement)) {
266
							typesContainingMethod.add(rootInterfaces[i]);
267
							break;
268
						}
269
					}
270
					if (typesContainingMethod.size() > 1)
271
						return null;
272
				}
273
				return (IType)(typesContainingMethod.size() == 1 ? typesContainingMethod.get(0) : type);
274
			}
233
		};
275
		};
234
276
235
		try {
277
		try {

Return to bug 288464