### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.debug.ui
Index: ui/org/eclipse/jdt/internal/debug/ui/actions/OpenTypeAction.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenTypeAction.java,v
retrieving revision 1.27
diff -u -r1.27 OpenTypeAction.java
--- ui/org/eclipse/jdt/internal/debug/ui/actions/OpenTypeAction.java 30 Nov 2009 16:38:02 -0000 1.27
+++ ui/org/eclipse/jdt/internal/debug/ui/actions/OpenTypeAction.java 3 May 2011 18:33:59 -0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 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
@@ -16,8 +16,10 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
-
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
@@ -25,23 +27,15 @@
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.search.TypeNameMatch;
import org.eclipse.jdt.core.search.TypeNameMatchRequestor;
-
import org.eclipse.jdt.debug.core.IJavaArrayType;
import org.eclipse.jdt.debug.core.IJavaType;
import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants;
-
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.IStructuredSelection;
-
-import org.eclipse.debug.core.DebugException;
-import org.eclipse.debug.core.model.IDebugElement;
-
import org.eclipse.jdt.internal.debug.core.JavaDebugUtils;
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
-
import org.eclipse.jdt.internal.ui.util.OpenTypeHierarchyUtil;
-
import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.IStructuredSelection;
public abstract class OpenTypeAction extends ObjectActionDelegate {
@@ -102,7 +96,7 @@
if (source == null) {
//resort to looking through the workspace projects for the
//type as the source locators failed.
- source = findTypeInWorkspace(type.getName());
+ source = findTypeInWorkspace(type.getName(), false);
}
}
}
@@ -140,10 +134,15 @@
* or null
if none.
*
* @param typeName fully qualified type name
+ * @param findOnlyUniqueMatch
+ * if true
, this method only returns a type iff
+ * there's only a single match in the workspace, and
+ * null
otherwise. If false
, it returns
+ * the first match.
* @return type or null
- * @throws JavaModelException
+ * @throws CoreException if search failed
*/
- public static IType findTypeInWorkspace(String typeName) throws CoreException {
+ public static IType findTypeInWorkspace(String typeName, boolean findOnlyUniqueMatch) throws CoreException {
int dot= typeName.lastIndexOf('.');
char[][] qualifications;
String simpleName;
@@ -156,6 +155,14 @@
}
char[][] typeNames= new char[][] { simpleName.toCharArray() };
+ if (findOnlyUniqueMatch)
+ return findUniqueTypeInWorkspace(qualifications, typeNames);
+ else
+ return findAnyTypeInWorkspace(qualifications, typeNames);
+ }
+
+ private static IType findAnyTypeInWorkspace(char[][] qualifications,
+ char[][] typeNames) throws JavaModelException {
class ResultException extends RuntimeException {
private static final long serialVersionUID= 1L;
private final IType fType;
@@ -176,6 +183,26 @@
return null;
}
+ private static IType findUniqueTypeInWorkspace(char[][] qualifications,
+ char[][] typeNames) throws JavaModelException {
+ final IType[] result = { null };
+ TypeNameMatchRequestor requestor= new TypeNameMatchRequestor() {
+ public void acceptTypeNameMatch(TypeNameMatch match) {
+ if (result[0] == null) {
+ result[0]= match.getType();
+ } else {
+ throw new OperationCanceledException();
+ }
+ }
+ };
+ try {
+ new SearchEngine().searchAllTypeNames(qualifications, typeNames, SearchEngine.createWorkspaceScope(), requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
+ } catch (OperationCanceledException e) {
+ return null;
+ }
+ return result[0];
+ }
+
protected void typeHierarchyError() {
showErrorMessage(ActionMessages.ObjectActionDelegate_Unable_to_display_type_hierarchy__The_selected_source_element_is_not_contained_in_the_workspace__1);