### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: search/org/eclipse/jdt/internal/core/search/matching/MultiTypeDeclarationPattern.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MultiTypeDeclarationPattern.java,v retrieving revision 1.8 diff -u -r1.8 MultiTypeDeclarationPattern.java --- search/org/eclipse/jdt/internal/core/search/matching/MultiTypeDeclarationPattern.java 7 Sep 2006 12:59:26 -0000 1.8 +++ search/org/eclipse/jdt/internal/core/search/matching/MultiTypeDeclarationPattern.java 11 Oct 2006 15:44:15 -0000 @@ -83,10 +83,15 @@ if (this.qualifications != null) { int count = 0; int max = this.qualifications.length; - for (; count < max; count++) - if (matchesName(this.qualifications[count], pattern.qualification)) - break; - if (count == max) return false; + if (max == 0 && pattern.qualification.length > 0) { + return false; + } + if (max > 0) { + for (; count < max; count++) + if (matchesName(this.qualifications[count], pattern.qualification)) + break; + if (count == max) return false; + } } // chekc simple name Index: search/org/eclipse/jdt/core/search/SearchEngine.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/SearchEngine.java,v retrieving revision 1.133 diff -u -r1.133 SearchEngine.java --- search/org/eclipse/jdt/core/search/SearchEngine.java 6 Oct 2006 17:43:34 -0000 1.133 +++ search/org/eclipse/jdt/core/search/SearchEngine.java 11 Oct 2006 15:44:14 -0000 @@ -774,9 +774,9 @@ * and type names in a case sensitive way. * * @param qualifications the qualified name of the package/enclosing type of the searched types. - * May be null, then any package name is accepted. + * If this parameter is null, then no type will be found. * @param typeNames the simple names of the searched types. - * May be null, then any type name is accepted. + * If this parameter is null, then no type will be found. * @param scope the scope to search in * @param nameRequestor the requestor that collects the results of the search * @param waitingPolicy one of @@ -816,6 +816,57 @@ } /** + * Searches for all top-level types and member types in the given scope matching any of the given qualifications + * and type names in a case sensitive way. + *

+ * Provided {@link TypeNameMatchRequestor} requestor will collect {@link TypeNameMatch} + * matches found during the search. + *

+ * + * @param qualifications the qualified name of the package/enclosing type of the searched types. + * If this parameter is null, then no type will be found. + * @param typeNames the simple names of the searched types. + * If this parameter is null, then no type will be found. + * @param scope the scope to search in + * @param nameMatchRequestor the {@link TypeNameMatchRequestor requestor} that collects + * {@link TypeNameMatch matches} of the search. + * @param waitingPolicy one of + * + * @param progressMonitor the progress monitor to report progress to, or null if no progress + * monitor is provided + * @exception JavaModelException if the search failed. Reasons include: + * + * @since 3.3 + */ + public void searchAllTypeNames( + final char[][] qualifications, + final char[][] typeNames, + IJavaSearchScope scope, + final TypeNameMatchRequestor nameMatchRequestor, + int waitingPolicy, + IProgressMonitor progressMonitor) throws JavaModelException { + + TypeNameMatchRequestorWrapper requestorWrapper = new TypeNameMatchRequestorWrapper(nameMatchRequestor, scope); + this.basicEngine.searchAllTypeNames( + qualifications, + typeNames, + SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, + IJavaSearchConstants.TYPE, + scope, + requestorWrapper, + waitingPolicy, + progressMonitor); + } + + /** * Searches for all top-level types and member types in the given scope. * The search can be selecting specific types (given a package or a type name * prefix and match modes). Index: search/org/eclipse/jdt/core/search/TypeNameMatch.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/TypeNameMatch.java,v retrieving revision 1.2 diff -u -r1.2 TypeNameMatch.java --- search/org/eclipse/jdt/core/search/TypeNameMatch.java 6 Oct 2006 17:43:34 -0000 1.2 +++ search/org/eclipse/jdt/core/search/TypeNameMatch.java 11 Oct 2006 15:44:14 -0000 @@ -10,10 +10,8 @@ *******************************************************************************/ package org.eclipse.jdt.core.search; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.core.runtime.Assert; +import org.eclipse.jdt.core.*; /** * A match collected while searching for all type names using @@ -41,44 +39,26 @@ /** * Creates a new type name match. */ -public TypeNameMatch(IType type) { - this.type = type; -} - public TypeNameMatch(IType type, int modifiers) { - this(type); + Assert.isNotNull(type, "Type cannot be null for a name match!"); //$NON-NLS-1$ + this.type = type; this.modifiers = modifiers; } /** - * Returns the java model type corresponding to fully qualified type name (based - * on package, enclosing types and simple name). - * - * @return the java model type - * @throws JavaModelException - * happens when type stored information are not valid + * Returns whether the stored type is equals to given object or not. */ -public IType getType() throws JavaModelException { - return this.type; -} - -/* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ -public String toString() { - return this.type.toString(); -} - -public IPackageFragmentRoot getPackageFragmentRoot() { - return (IPackageFragmentRoot) this.type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); +public boolean equals(Object obj) { + if (obj == null) return false; + return this.type.equals(obj); } /** - * Fully qualified name of type (e.g. package name + '.' enclosing type names + - * '.' simple name) + * Returns the fully qualified name of stored type + * (e.g. package name + '.' enclosing type names + '.' simple name) * + * @see #getType() + * @see IType#getFullyQualifiedName(char) * @return Fully qualified type name of the type */ public String getFullyQualifiedName() { @@ -86,27 +66,33 @@ } /** - * Fully qualified name of type (e.g. package name + '.' enclosing type names + - * '.' simple name) + * Returns the stored modifiers of the type. + * This is a handle-only method. * - * @return Fully qualified type name of the type + * @return the type modifiers */ -public String getTypeQualifiedName() { - return this.type.getTypeQualifiedName('.'); +public int getModifiers() { + return this.modifiers; } /** - * Returns the modifiers of the type. + * Returns the package fragment root of the stored type. + * Package fragment root cannot be null and does exist. * - * @return the type modifiers + * @see #getType() + * @see IJavaElement#getAncestor(int) + * @return the existing java model package fragment root (ie. cannot be null + * and will return true to exists() message). */ -public int getModifiers() { - return this.modifiers; +public IPackageFragmentRoot getPackageFragmentRoot() { + return (IPackageFragmentRoot) this.type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); } /** - * Returns the package name of the type. + * Returns the package name of the stored type. * + * @see #getType() + * @see IType#getPackageFragment() * @return the package name */ public String getPackageName() { @@ -114,8 +100,10 @@ } /** - * Returns the name of the type. + * Returns the name of the stored type. * + * @see #getType() + * @see IJavaElement#getElementName() * @return the type name */ public String getSimpleTypeName() { @@ -123,8 +111,23 @@ } /** - * Name of the type container (e.g. enclosing type names + '.' + simple name) + * Returns the stored java model type. As this match was built while searching + * for all types in index files, the stored type cannot be null and does exist. + * This is a handle-only method. + * + * @see IType + * @return the existing java model type (ie. cannot be null + * and will return true to exists() message). + */ +public IType getType() { + return this.type; +} + +/** + * Name of the type container (e.g. enclosing type names + '.' + simple name). * + * @see #getType() + * @see IMember#getDeclaringType() * @return Name of the type container */ public String getTypeContainerName() { @@ -135,4 +138,30 @@ return this.type.getPackageFragment().getElementName(); } } + +/** + * Returns the qualified name of type + * (e.g. enclosing type names + '.' simple name). + * + * @see #getType() + * @see IType#getTypeQualifiedName(char) + * @return Fully qualified type name of the type + */ +public String getTypeQualifiedName() { + return this.type.getTypeQualifiedName('.'); +} + +/** + * Returns stored type hashCode. + */ +public int hashCode() { + return this.type.hashCode(); +} + +/** + * Returns stored type string. + */ +public String toString() { + return this.type.toString(); +} } Index: search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java,v retrieving revision 1.40 diff -u -r1.40 BasicSearchEngine.java --- search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 6 Oct 2006 17:43:34 -0000 1.40 +++ search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 11 Oct 2006 15:44:15 -0000 @@ -809,7 +809,7 @@ } if (match(typeSuffix, packageName, typeName, typeMatchRule, kind, packageDeclaration, simpleName)) { if (nameRequestor instanceof TypeNameMatchRequestorWrapper) { - ((TypeNameMatchRequestorWrapper)nameRequestor).requestor.acceptTypeNameMatch(new TypeNameMatch(type)); + ((TypeNameMatchRequestorWrapper)nameRequestor).requestor.acceptTypeNameMatch(new TypeNameMatch(type, type.getFlags())); } else { nameRequestor.acceptType(type.getFlags(), packageDeclaration, simpleName, enclosingTypeNames, path, null); } Index: buildnotes_jdt-core.html =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/buildnotes_jdt-core.html,v retrieving revision 1.5458 diff -u -r1.5458 buildnotes_jdt-core.html --- buildnotes_jdt-core.html 11 Oct 2006 15:11:50 -0000 1.5458 +++ buildnotes_jdt-core.html 11 Oct 2006 15:44:13 -0000 @@ -51,8 +51,48 @@
Project org.eclipse.jdt.core v_717 (cvs).

What's new in this drop

+

Problem Reports Fixed

+160494 +[search] searchAllTypeNames(char[][], char[][],...) fails to find types in default package +
160328 +[search] Remove constructor TypeNameMatch(IType) +
160327 +[search] Add specification for TypeNameMatch.getType +
160324 +[search] SearchEngine.searchAllTypeNames(char[][], char[][], TypeNameMatchRequestor +
160323 +[search] TypeNameMatch: support hashCode/equals +
160352 90600 [model] CreateElementInCUOperation.apply: should use project options for rewriter
160352 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java,v retrieving revision 1.89 diff -u -r1.89 JavaSearchBugsTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 10 Oct 2006 10:33:02 -0000 1.89 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 11 Oct 2006 15:44:19 -0000 @@ -85,34 +85,45 @@ } class TypeNameMatchCollector extends TypeNameMatchRequestor { - private int index = -1; - public String[] results = new String[10]; + List matches = new ArrayList(); public void acceptTypeNameMatch(TypeNameMatch match) { - int length = results.length; - if (++index > length) { - System.arraycopy(results, 0, results = new String[length+10], 0, length); + IType type = match.getType(); + if (type != null) { + this.matches.add(type); } - try { - IType type = match.getType(); - if (type != null) { - results[index] = type.toString(); + } + public int size() { + return this.matches.size(); + } + private String toString(int kind) { + int size = size(); + if (size == 0) return ""; + String[] strings = new String[size]; + for (int i=0; i0) buffer.append('\n'); buffer.append(strings[i]); } return buffer.toString(); } + public String toString() { + return toString(0); + } + public String toFullyQualifiedNamesString() { + return toString(1); + } } IJavaSearchScope getJavaSearchScopeBugs() { return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearchBugs")}); @@ -7145,4 +7156,160 @@ ); } +/** + * @bug 160323: [search] TypeNameMatch: support hashCode/equals + * @test Ensure that match equals and hashCode methods return same values than those of stored {@link IType}. + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=160323" + */ +public void testBug160323() throws CoreException { + // Search all type names with TypeNameMatchRequestor + TypeNameMatchCollector collector = new TypeNameMatchCollector() { + public void acceptTypeNameMatch(TypeNameMatch match) { + assertTrue("Problem with equals method for match "+match, match.equals(match.getType())); + assertEquals("Problem with hashCode method for match "+match, match.getType().hashCode(), match.hashCode()); + super.acceptTypeNameMatch(match); + } + public String toString(){ + return toFullyQualifiedNamesString(); + } + }; + new SearchEngine().searchAllTypeNames( + null, + SearchPattern.R_EXACT_MATCH, + null, + SearchPattern.R_PREFIX_MATCH, + IJavaSearchConstants.TYPE, + getJavaSearchScopeBugs(), + collector, + IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + null); + // Search all type names with TypeNameRequestor + TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); + new SearchEngine().searchAllTypeNames( + null, + SearchPattern.R_EXACT_MATCH, + null, + SearchPattern.R_PREFIX_MATCH, + IJavaSearchConstants.TYPE, + getJavaSearchScopeBugs(), + requestor, + IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + null); + // Should have same types with these 2 searches + assertTrue("We should get some types!", collector.size() > 0); + assertEquals("Found types sounds not to be correct", requestor.toString(), collector.toString()); +} +/** + * @bug 160324: [search] SearchEngine.searchAllTypeNames(char[][], char[][], TypeNameMatchRequestor + * @test Ensure that types found using {@link SearchEngine#searchAllTypeNames(char[][], char[][], IJavaSearchScope, TypeNameMatchRequestor, int, org.eclipse.core.runtime.IProgressMonitor) new API method} + * are the same than with already existing API method using {@link TypeNameRequestor}... + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=160324" + */ +public void testBug160324a() throws CoreException { + // Search all type names with new API + TypeNameMatchCollector collector = new TypeNameMatchCollector() { + public void acceptTypeNameMatch(TypeNameMatch match) { + assertTrue("Problem with equals method for match "+match, match.equals(match.getType())); + assertEquals("Problem with hashCode method for match "+match, match.getType().hashCode(), match.hashCode()); + super.acceptTypeNameMatch(match); + } + public String toString(){ + return toFullyQualifiedNamesString(); + } + }; + new SearchEngine().searchAllTypeNames( + null, + null, + getJavaSearchScopeBugs(), + collector, + IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + null); + assertEquals("We should not find any type", "", collector.toString()); + // Search all type names with old API + TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); + new SearchEngine().searchAllTypeNames( + null, + null, + getJavaSearchScopeBugs(), + requestor, + IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + null); + assertEquals("We should not find any type", "", requestor.toString()); +} +public void testBug160324b() throws CoreException { + // Search all type names with new API + TypeNameMatchCollector collector = new TypeNameMatchCollector() { + public String toString(){ + return toFullyQualifiedNamesString(); + } + }; + new SearchEngine().searchAllTypeNames( + null, + new char[][] { "Test".toCharArray() }, + getJavaSearchScopeBugs(), + collector, + IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + null); + // Search all type names with old API + TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); + new SearchEngine().searchAllTypeNames( + null, + new char[][] { "Test".toCharArray() }, + getJavaSearchScopeBugs(), + requestor, + IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + null); + // Should have same types with these 2 searches + assertTrue("We should get some types!", collector.size() > 0); + assertEquals("Found types sounds not to be correct", requestor.toString(), collector.toString()); +} + +/** + * @bug 160494: [search] searchAllTypeNames(char[][], char[][],...) fails to find types in default package + * @test Ensure that types of default packge are found when empty package is specified in package lists + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=160494" + */ +public void testBug160324c() throws CoreException { + boolean debug = false; + char[][] packagesList = new char[][] { + CharOperation.NO_CHAR, + "b110422".toCharArray(), + "b123679.test".toCharArray(), + "b89848".toCharArray(), + "b95794".toCharArray(), + "pack".toCharArray(), + "pack.age".toCharArray() + }; + char[][] typesList = new char[][] { + "Test".toCharArray(), + "TestPrefix".toCharArray() + }; + // Search all type names with new API + TypeNameMatchCollector collector = new TypeNameMatchCollector() { + public String toString(){ + return toFullyQualifiedNamesString(); + } + }; + new SearchEngine().searchAllTypeNames( + packagesList, + typesList, + getJavaSearchScopeBugs(), + collector, + IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + null); + if (debug) System.out.println("TypeNameMatchRequestor results: \n"+collector); + // Search all type names with old API + TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); + new SearchEngine().searchAllTypeNames( + packagesList, + typesList, + getJavaSearchScopeBugs(), + requestor, + IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + null); + if (debug) System.out.println("TypeNameRequestor results: \n"+requestor); + // Should have same types with these 2 searches + assertEquals("Wrong number of found types!", packagesList.length, collector.size()); + assertEquals("Found types sounds not to be correct", requestor.toString(), collector.toString()); +} } \ No newline at end of file Index: workspace/JavaSearchBugs/lib/b110422.jar =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/workspace/JavaSearchBugs/lib/b110422.jar,v retrieving revision 1.1 diff -u -r1.1 b110422.jar Binary files /tmp/cvs.mIH2MY and b110422.jar differ