OpenType dialog: improve search by fully qualified names
diff --git a/core/plugins/org.eclipse.dltk.ui/core refactoring/org/eclipse/dltk/internal/corext/util/OpenTypeHistory.java b/core/plugins/org.eclipse.dltk.ui/core refactoring/org/eclipse/dltk/internal/corext/util/OpenTypeHistory.java
index 0a1565c..db50b89 100644
--- a/core/plugins/org.eclipse.dltk.ui/core refactoring/org/eclipse/dltk/internal/corext/util/OpenTypeHistory.java
+++ b/core/plugins/org.eclipse.dltk.ui/core refactoring/org/eclipse/dltk/internal/corext/util/OpenTypeHistory.java
@@ -286,9 +286,9 @@
 
 	public synchronized TypeNameMatch[] getFilteredTypeInfos(
 			TypeInfoFilter filter) {
-		Collection values = getValues();
-		List result = new ArrayList();
-		for (Iterator iter = values.iterator(); iter.hasNext();) {
+		Collection<?> values = getValues();
+		List<TypeNameMatch> result = new ArrayList<TypeNameMatch>();
+		for (Iterator<?> iter = values.iterator(); iter.hasNext();) {
 			TypeNameMatch type = (TypeNameMatch) iter.next();
 			if (type != null
 					&& (filter == null || filter.matchesHistoryElement(type))
@@ -296,9 +296,7 @@
 				result.add(type);
 		}
 		Collections.reverse(result);
-		return (TypeNameMatch[]) result
-				.toArray(new TypeNameMatch[result.size()]);
-
+		return result.toArray(new TypeNameMatch[result.size()]);
 	}
 
 	protected Object getKey(Object object) {
@@ -370,8 +368,8 @@
 			} else { // external JAR
 				IProjectFragment root = match.getProjectFragment();
 				if (root.exists()) {
-					IFileInfo info = EFS.getLocalFileSystem().getStore(
-							root.getPath()).fetchInfo();
+					IFileInfo info = EFS.getLocalFileSystem()
+							.getStore(root.getPath()).fetchInfo();
 					if (info.exists()) {
 						return info.getLastModified();
 					}
@@ -392,8 +390,8 @@
 		if (resource != null) {
 			ITextFileBufferManager manager = FileBuffers
 					.getTextFileBufferManager();
-			ITextFileBuffer textFileBuffer = manager.getTextFileBuffer(resource
-					.getFullPath(), LocationKind.NORMALIZE);
+			ITextFileBuffer textFileBuffer = manager.getTextFileBuffer(
+					resource.getFullPath(), LocationKind.NORMALIZE);
 			if (textFileBuffer != null) {
 				return textFileBuffer.isDirty();
 			}
@@ -442,12 +440,12 @@
 		TypeNameMatch type = (TypeNameMatch) object;
 		String handleId = type.getType().getHandleIdentifier();
 		typeElement.setAttribute(NODE_HANDLE, handleId);
-		typeElement.setAttribute(NODE_MODIFIERS, Integer.toString(type
-				.getModifiers()));
+		typeElement.setAttribute(NODE_MODIFIERS,
+				Integer.toString(type.getModifiers()));
 		Long timestamp = (Long) fTimestampMapping.get(type);
 		if (timestamp == null) {
-			typeElement.setAttribute(NODE_TIMESTAMP, Long
-					.toString(IResource.NULL_STAMP));
+			typeElement.setAttribute(NODE_TIMESTAMP,
+					Long.toString(IResource.NULL_STAMP));
 		} else {
 			typeElement.setAttribute(NODE_TIMESTAMP, timestamp.toString());
 		}
diff --git a/core/plugins/org.eclipse.dltk.ui/core refactoring/org/eclipse/dltk/internal/corext/util/TypeInfoFilter.java b/core/plugins/org.eclipse.dltk.ui/core refactoring/org/eclipse/dltk/internal/corext/util/TypeInfoFilter.java
index 1564c0e..7aedc95 100644
--- a/core/plugins/org.eclipse.dltk.ui/core refactoring/org/eclipse/dltk/internal/corext/util/TypeInfoFilter.java
+++ b/core/plugins/org.eclipse.dltk.ui/core refactoring/org/eclipse/dltk/internal/corext/util/TypeInfoFilter.java
@@ -9,7 +9,6 @@
  *******************************************************************************/
 package org.eclipse.dltk.internal.corext.util;
 
-import org.eclipse.dltk.core.DLTKLanguageManager;
 import org.eclipse.dltk.core.IDLTKLanguageToolkit;
 import org.eclipse.dltk.core.ISearchPatternProcessor;
 import org.eclipse.dltk.core.ISearchPatternProcessor.ITypePattern;
@@ -19,6 +18,7 @@
 import org.eclipse.dltk.core.search.SearchPattern;
 import org.eclipse.dltk.core.search.TypeNameMatch;
 import org.eclipse.dltk.internal.ui.util.StringMatcher;
+import org.eclipse.dltk.ui.IDLTKUILanguageToolkit;
 import org.eclipse.dltk.ui.dialogs.ITypeInfoFilterExtension;
 
 public class TypeInfoFilter {
@@ -125,7 +125,7 @@
 
 	private String fText;
 	private final IDLTKSearchScope fSearchScope;
-	private boolean fIsWorkspaceScope;
+	private final boolean fIsWorkspaceScope;
 	private int fElementKind;
 	private ITypeInfoFilterExtension fFilterExtension;
 	private TypeInfoRequestorAdapter fAdapter = new TypeInfoRequestorAdapter();
@@ -135,17 +135,16 @@
 
 	private static final int TYPE_MODIFIERS = 0;
 
-	public TypeInfoFilter(String text, IDLTKSearchScope scope, int elementKind,
-			ITypeInfoFilterExtension extension) {
+	public TypeInfoFilter(IDLTKUILanguageToolkit uiToolkit, String text,
+			IDLTKSearchScope scope, int elementKind,
+			ITypeInfoFilterExtension extension,
+			ISearchPatternProcessor processor) {
 		fText = text;
 		fSearchScope = scope;
-		IDLTKLanguageToolkit toolkit = scope.getLanguageToolkit();
 		fIsWorkspaceScope = fSearchScope.equals(SearchEngine
-				.createWorkspaceScope(toolkit));
+				.createWorkspaceScope(uiToolkit.getCoreToolkit()));
 		fElementKind = elementKind;
 		fFilterExtension = extension;
-		ISearchPatternProcessor processor = DLTKLanguageManager
-				.getSearchPatternProcessor(toolkit, true);
 		ITypePattern pattern = processor.parseType(text);
 		String simpleName = pattern.getSimpleName();
 		if (simpleName.length() == 0) {
@@ -194,7 +193,7 @@
 		if (!fText.startsWith(text))
 			return false;
 
-		return fText.indexOf('.', text.length()) == -1;
+		return fPackageMatcher == null;
 	}
 
 	public boolean isCamelCasePattern() {
diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/dialogs/TypeInfoViewer.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/dialogs/TypeInfoViewer.java
index 9480147..3e5eb6f 100644
--- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/dialogs/TypeInfoViewer.java
+++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/dialogs/TypeInfoViewer.java
@@ -29,13 +29,15 @@
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.dltk.ast.Modifiers;
+import org.eclipse.dltk.core.DLTKLanguageManager;
 import org.eclipse.dltk.core.IDLTKLanguageToolkit;
 import org.eclipse.dltk.core.IProjectFragment;
+import org.eclipse.dltk.core.ISearchPatternProcessor;
 import org.eclipse.dltk.core.IType;
 import org.eclipse.dltk.core.ModelException;
 import org.eclipse.dltk.core.WorkingCopyOwner;
-import org.eclipse.dltk.core.index2.search.ModelAccess;
 import org.eclipse.dltk.core.index2.search.ISearchEngine.MatchRule;
+import org.eclipse.dltk.core.index2.search.ModelAccess;
 import org.eclipse.dltk.core.search.IDLTKSearchConstants;
 import org.eclipse.dltk.core.search.IDLTKSearchScope;
 import org.eclipse.dltk.core.search.NopTypeNameRequestor;
@@ -161,8 +163,8 @@
 				return -1;
 			if (leftCategory > rightCategory)
 				return +1;
-			int result = compareName(leftInfo.getSimpleTypeName(), rightInfo
-					.getSimpleTypeName());
+			int result = compareName(leftInfo.getSimpleTypeName(),
+					rightInfo.getSimpleTypeName());
 			if (result != 0)
 				return result;
 			// TODO it should be generalized for scripting languages
@@ -294,9 +296,10 @@
 							// on MacOS X install locations end in an additional
 							// "/Home" segment; remove it
 							if (isMac && filePath.endsWith(HOME_SUFFIX))
-								filePath = filePath.substring(0, filePath
-										.length()
-										- (HOME_SUFFIX.length() - 1));
+								filePath = filePath.substring(
+										0,
+										filePath.length()
+												- (HOME_SUFFIX.length() - 1));
 							locations.add(filePath);
 							labels.add(label);
 						}
@@ -543,8 +546,7 @@
 				return fName;
 			} else {
 				return Messages
-						.format(
-								DLTKUIMessages.TypeInfoViewer_progress_label,
+						.format(DLTKUIMessages.TypeInfoViewer_progress_label,
 								new Object[] {
 										fName,
 										new Integer(
@@ -688,9 +690,9 @@
 				elements.clear();
 				imageDescriptors.clear();
 				labels.clear();
-				int delta = Math.min(nextIndex == 1 ? fViewer
-						.getNumberOfVisibleItems() : 10, result.length
-						- processed);
+				int delta = Math
+						.min(nextIndex == 1 ? fViewer.getNumberOfVisibleItems()
+								: 10, result.length - processed);
 				if (delta == 0)
 					break;
 				processed = processed + delta;
@@ -785,14 +787,13 @@
 			long start = System.currentTimeMillis();
 			fReqestor.setHistory(matchIdsInHistory);
 
-			monitor
-					.setTaskName(DLTKUIMessages.TypeInfoViewer_searchJob_taskName);
+			monitor.setTaskName(DLTKUIMessages.TypeInfoViewer_searchJob_taskName);
 
 			MatchRule searchRule = ModelAccess.convertSearchRule(fFilter
 					.getSearchFlags());
-			IType[] types = new ModelAccess().findTypes(fFilter
-					.getNamePattern(), searchRule, 0, Modifiers.AccNameSpace,
-					fScope, monitor);
+			IType[] types = new ModelAccess().findTypes(
+					fFilter.getNamePattern(), searchRule, 0,
+					Modifiers.AccNameSpace, fScope, monitor);
 			if (searchRule == MatchRule.CAMEL_CASE) {
 				LinkedList<IType> result = new LinkedList<IType>();
 				if (types != null) {
@@ -832,9 +833,7 @@
 				System.out
 						.println("Time needed until search has finished: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
 			TypeNameMatch[] result = fReqestor.getResult();
-			Arrays
-					.sort(result, new TypeInfoComparator(fLabelProvider,
-							fFilter));
+			Arrays.sort(result, new TypeInfoComparator(fLabelProvider, fFilter));
 			if (DEBUG)
 				System.out
 						.println("Time needed until sort has finished: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
@@ -891,8 +890,7 @@
 		@Override
 		protected IStatus doRun(ProgressMonitor monitor) {
 			try {
-				monitor
-						.setTaskName(DLTKUIMessages.TypeInfoViewer_syncJob_taskName);
+				monitor.setTaskName(DLTKUIMessages.TypeInfoViewer_syncJob_taskName);
 				new SearchEngine().searchAllTypeNames(
 						null,
 						0,
@@ -901,8 +899,8 @@
 						"_______________".toCharArray(), //$NON-NLS-1$
 						SearchPattern.R_EXACT_MATCH
 								| SearchPattern.R_CASE_SENSITIVE,
-						IDLTKSearchConstants.TYPE, SearchEngine
-								.createWorkspaceScope(fToolkit),
+						IDLTKSearchConstants.TYPE,
+						SearchEngine.createWorkspaceScope(fToolkit),
 						new NopTypeNameRequestor(),
 						IDLTKSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
 						monitor);
@@ -987,7 +985,8 @@
 	private SyncJob fSyncJob;
 
 	private TypeInfoFilter fTypeInfoFilter;
-	private ITypeInfoFilterExtension fFilterExtension;
+	private final ITypeInfoFilterExtension fFilterExtension;
+	private final ISearchPatternProcessor fSearchPatternProcessor;
 	private TypeNameMatch[] fLastCompletedResult;
 	private TypeInfoFilter fLastCompletedFilter;
 
@@ -1016,6 +1015,7 @@
 			IDLTKSearchScope scope, int elementKind, String initialFilter,
 			ITypeInfoFilterExtension filterExtension,
 			ITypeInfoImageProvider imageExtension,
+			ISearchPatternProcessor searchPatternProcessor,
 			IDLTKUILanguageToolkit toolkit) {
 		Assert.isNotNull(scope);
 
@@ -1025,6 +1025,9 @@
 		fSearchScope = scope;
 		fElementKind = elementKind;
 		fFilterExtension = filterExtension;
+		fSearchPatternProcessor = searchPatternProcessor != null ? searchPatternProcessor
+				: DLTKLanguageManager.getSearchPatternProcessor(
+						toolkit.getCoreToolkit(), true);
 		fFullyQualifySelection = (flags & SWT.MULTI) != 0;
 		fTable = new Table(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER
 				| SWT.FLAT | flags | (VIRTUAL ? SWT.VIRTUAL : SWT.NONE));
@@ -1252,7 +1255,8 @@
 		fDashLineIndex = -1;
 		TypeInfoFilter filter = (fTypeInfoFilter != null) ? fTypeInfoFilter
 				: new TypeInfoFilter(
-						"*", fSearchScope, fElementKind, fFilterExtension); //$NON-NLS-1$
+						fToolkit,
+						"*", fSearchScope, fElementKind, fFilterExtension, fSearchPatternProcessor); //$NON-NLS-1$
 		if (VIRTUAL) {
 			fHistoryMatches = fHistory.getFilteredTypeInfos(filter);
 			fExpectedItemCount = fHistoryMatches.length;
@@ -1289,8 +1293,8 @@
 	protected TypeInfoFilter createTypeInfoFilter(String text) {
 		if ("**".equals(text)) //$NON-NLS-1$
 			text = "*"; //$NON-NLS-1$
-		return new TypeInfoFilter(text, fSearchScope, fElementKind,
-				fFilterExtension);
+		return new TypeInfoFilter(fToolkit, text, fSearchScope, fElementKind,
+				fFilterExtension, fSearchPatternProcessor);
 	}
 
 	private void addPopupMenu() {
@@ -1710,10 +1714,8 @@
 		Rectangle bounds = item.getImageBounds(0);
 		Rectangle area = fTable.getBounds();
 		boolean willHaveScrollBar = fExpectedItemCount + 1 > fNumberOfVisibleItems;
-		item
-				.setText(fDashLine.getText(area.width - bounds.x - bounds.width
-						- fTableWidthDelta
-						- (willHaveScrollBar ? fScrollbarWidth : 0)));
+		item.setText(fDashLine.getText(area.width - bounds.x - bounds.width
+				- fTableWidthDelta - (willHaveScrollBar ? fScrollbarWidth : 0)));
 		item.setImage(fSeparatorIcon);
 		item.setForeground(fDashLineColor);
 		item.setData(fDashLine);
diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/dialogs/TypeSelectionComponent.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/dialogs/TypeSelectionComponent.java
index e6f26a1..c6df6ac 100644
--- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/dialogs/TypeSelectionComponent.java
+++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/dialogs/TypeSelectionComponent.java
@@ -219,10 +219,14 @@
 		label.setFont(font);
 		gd= new GridData(GridData.FILL_HORIZONTAL);
 		label.setLayoutData(gd);
-		fViewer= new TypeInfoViewer(this, fMultipleSelection ? SWT.MULTI : SWT.NONE, label, 
-			fScope, elementKind, fInitialFilterText, 
-			fTypeSelectionExtension != null ? fTypeSelectionExtension.getFilterExtension() : null,
-			fTypeSelectionExtension != null ? fTypeSelectionExtension.getImageProvider() : null, this.fToolkit);
+		fViewer = new TypeInfoViewer(this, fMultipleSelection ? SWT.MULTI
+				: SWT.NONE, label, fScope, elementKind, fInitialFilterText,
+				fTypeSelectionExtension != null ? fTypeSelectionExtension
+						.getFilterExtension() : null,
+				fTypeSelectionExtension != null ? fTypeSelectionExtension
+						.getImageProvider() : null,
+				fTypeSelectionExtension != null ? fTypeSelectionExtension
+						.getSearchPatternProcessor() : null, this.fToolkit);
 		gd= new GridData(GridData.FILL_BOTH);
 		final Table table= fViewer.getTable();
 		PixelConverter converter= new PixelConverter(table);
diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/dialogs/TypeSelectionExtension.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/dialogs/TypeSelectionExtension.java
index 377a48c..91f5984 100644
--- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/dialogs/TypeSelectionExtension.java
+++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/dialogs/TypeSelectionExtension.java
@@ -9,6 +9,7 @@
  *******************************************************************************/
 package org.eclipse.dltk.ui.dialogs;
 
+import org.eclipse.dltk.core.ISearchPatternProcessor;
 import org.eclipse.dltk.core.IType;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
@@ -89,4 +90,13 @@
 	public ITypeInfoImageProvider getImageProvider() {
 		return null;
 	}
+
+	/**
+	 * Returns search pattern processor to be used by the dialog or
+	 * <code>null</code> if default implementation contributed for the language
+	 * should be used.
+	 */
+	public ISearchPatternProcessor getSearchPatternProcessor() {
+		return null;
+	}
 }