Bug 97120

Summary: [search] SearchEngine.createHierarchyScope() proposes an empty list in a TypeDialog
Product: [Eclipse Project] JDT Reporter: julien <yang_ying_min>
Component: CoreAssignee: Frederic Fusier <frederic_fusier>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: dirk_baeumer
Version: 3.1   
Target Milestone: 3.1 RC3   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Patch against open type action
none
Showing the parameters for the all type names search call
none
Open Type Dialog with correct "Matched Types" list none

Description julien CLA 2005-05-28 14:58:19 EDT
SelectionDialog dialog = JavaUI.createTypeDialog(
	xx.getShell(),
	null,								
	SearchEngine.createHierarchyScope(throwable), // scope		
	IJavaElementSearchConstants.CONSIDER_ALL_TYPES, // style
	true); // multiple selection

When you type the pattern "E", there is nothing in the "Matching types" list. 

I'm using 31RC1
Comment 1 Dirk Baeumer CLA 2005-05-30 13:26:51 EDT
JDT/UI passes the hierarchy scope 1:1 to the all type name search. 

Moving to JDT/Core.
Comment 2 Frederic Fusier CLA 2005-06-13 04:46:43 EDT
I'm not sure to understand your sample. What is throwable?
What matches do you expect with pattern "E"?
Can you provide more details on your test case?
TIA
Comment 3 Dirk Baeumer CLA 2005-06-13 06:42:25 EDT
The hierarchy scope is created on class Throwable. Since Exception is a subclass
of Throwable typing in E and a pattern should list Exception
Comment 4 Frederic Fusier CLA 2005-06-15 08:34:17 EDT
Dirk,
Can you give exact values for argument that UI gives to searchAllTypeNames method
(same way you did in bug 99915 comment 2)?
Thx
Comment 5 Dirk Baeumer CLA 2005-06-15 08:43:48 EDT
packagePattern:= null
pattern:= E*
flags:= 2 (== SearchPattern.R_PATTERN_MATCH)
elementKind:= 0 // meaning types
scope:= SearchEngine.createHierarchyScope(Throwable)
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH
Comment 6 Frederic Fusier CLA 2005-06-15 09:18:56 EDT
I'm not able to reproduce this problem using N20050615-0010.
I've added following test case to JavaSearchBugsTests and it pass:


/**
 * Bug 97120: [search] SearchEngine.createHierarchyScope() ...
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=97120"
 */
public void testBug97120() throws CoreException {
  IType type = getClassFile("JavaSearchBugs",
    getExternalJCLPathString("1.5"),
    "java.lang",
    "Throwable.class").getType();
  IJavaSearchScope scope = SearchEngine.createHierarchyScope(type);
  TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
  new SearchEngine().searchAllTypeNames(
	null,
	"E*".toCharArray(),
	SearchPattern.R_PATTERN_MATCH,
	TYPE,
	scope,
	requestor,
	IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
	null
  );
  assertSearchResults(
	"Unexpected all type names",
	"java.lang.Error\n" + 
	"java.lang.Exception",
	requestor
  );
}
Comment 7 Frederic Fusier CLA 2005-06-15 09:20:20 EDT
To be perfectly exact I've done test with N20050615-0010 + JDT/Core HEAD.
Comment 8 Dirk Baeumer CLA 2005-06-15 09:48:06 EDT
Frederic, I can still reproduce this. I will attach a patch to the
OpenTypeDialog that opens the dialog in this mode. All you have to have is a
project XX in your workspace to access the throwable class.
Comment 9 Dirk Baeumer CLA 2005-06-15 09:52:50 EDT
Created attachment 23187 [details]
Patch against open type action
Comment 10 Dirk Baeumer CLA 2005-06-15 09:54:11 EDT
Created attachment 23189 [details]
Showing the parameters for the all type names search call
Comment 11 Frederic Fusier CLA 2005-06-16 07:08:54 EDT
Dirk,
I'm still not able to reproduce even with your patch.
I've also made tests with yesterday's nightly build and RC2. I always get
correct "Matching Types" list!

For all builds, here are arguments send to searchAllTypeNames method (I've
changed 'XX' project to 'b97120'):
BasicSearchEngine.searchAllTypeNames(char[], char[], int, int, IJavaSearchScope,
IRestrictedAccessTypeRequestor, int, IProgressMonitor)
	- package name: null
	- type name: E*
	- match rule: 2
	- search for: 0
	- scope: HierarchyScope on Throwable [in Throwable.class [in java.lang [in
D:\a\JDKs\sun\1.4.2\jre\lib\rt.jar [in b97120]]]]

I'll attach snapshot of resulting dialog which shows "Matching Types" list with
expected "E*" types...
Comment 12 Frederic Fusier CLA 2005-06-16 07:09:55 EDT
Created attachment 23298 [details]
Open Type Dialog with correct "Matched Types" list
Comment 13 Frederic Fusier CLA 2005-06-16 09:48:08 EDT
Still cannot reproduce using a plugin with following action:
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.tests.utils.actions.AbstractAction;
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.ui.dialogs.SelectionDialog;

public class TestBug97120 extends AbstractAction {

  protected void run(Object obj) throws Exception {
    if (obj instanceof ICompilationUnit) {
	this.type = ((ICompilationUnit) obj).findPrimaryType();
    } else if (obj instanceof IClassFile) {
	this.type = ((IClassFile) obj).getType();
    } else if (obj instanceof IType) {
	this.type = (IType) obj;
    } else {
	System.err.println(obj.getClass().getName()+" is not a valid class for this
action!!!");
	return;
    }
    System.out.println("Open Type Dialog with using Hierarchy Scope on
"+this.type.getPath());
    IJavaSearchScope scope = SearchEngine.createHierarchyScope(this.type);
    SelectionDialog dialog = JavaUI.createTypeDialog(null, null,
	scope, // scope
	IJavaElementSearchConstants.CONSIDER_ALL_TYPES, // style
	true); // multiple selection
    dialog.open();
  }
}

In the opened dialog, I type 'E' and get all sub-types of Throwable starting
with E...
Comment 14 Dirk Baeumer CLA 2005-06-16 13:30:52 EDT
Retested it on the latest and it works now for me as well.
Comment 15 Frederic Fusier CLA 2005-06-17 03:26:18 EDT
Thanks Dirk for the feedback => close as WORKSFORME