Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 52038 Details for
Bug 161028
[search] NPE on organize imports in TypeNameMatch.equals
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
v00.txt (text/plain), 26.97 KB, created by
Frederic Fusier
on 2006-10-16 12:02:29 EDT
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2006-10-16 12:02:29 EDT
Size:
26.97 KB
patch
obsolete
>### 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.9 >diff -u -r1.9 MultiTypeDeclarationPattern.java >--- search/org/eclipse/jdt/internal/core/search/matching/MultiTypeDeclarationPattern.java 11 Oct 2006 16:58:19 -0000 1.9 >+++ search/org/eclipse/jdt/internal/core/search/matching/MultiTypeDeclarationPattern.java 16 Oct 2006 13:13:50 -0000 >@@ -46,15 +46,16 @@ > for (int i = 0; i < length; i++) > this.qualifications[i] = CharOperation.toLowerCase(qualifications[i]); > } >- if (simpleNames == null) { >- this.simpleNames = CharOperation.NO_CHAR_CHAR; >- } else if ((isCaseSensitive() || isCamelCase()) ) { >- this.simpleNames = simpleNames; >- } else { >- int length = simpleNames.length; >- this.simpleNames = new char[length][]; >- for (int i = 0; i < length; i++) >- this.simpleNames[i] = CharOperation.toLowerCase(simpleNames[i]); >+ // null simple names are allowed (should return all names) >+ if (simpleNames != null) { >+ if ((isCaseSensitive() || isCamelCase()) ) { >+ this.simpleNames = simpleNames; >+ } else { >+ int length = simpleNames.length; >+ this.simpleNames = new char[length][]; >+ for (int i = 0; i < length; i++) >+ this.simpleNames[i] = CharOperation.toLowerCase(simpleNames[i]); >+ } > } > this.typeSuffix = typeSuffix; > >@@ -94,7 +95,8 @@ > } > } > >- // chekc simple name >+ // check simple name (null are allowed) >+ if (this.simpleNames == null) return true; > int count = 0; > int max = this.simpleNames.length; > for (; count < max; count++) >@@ -103,6 +105,11 @@ > return count < max; > } > EntryResult[] queryIn(Index index) throws IOException { >+ if (this.simpleNames == null) { >+ // if no simple names then return all possible ones from index >+ return index.query(getIndexCategories(), null, -1); // match rule is irrelevant when the key is null >+ } >+ > int count = -1; > int numOfNames = this.simpleNames.length; > EntryResult[][] allResults = numOfNames > 1 ? new EntryResult[numOfNames][] : null; >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.5 >diff -u -r1.5 TypeNameMatch.java >--- search/org/eclipse/jdt/core/search/TypeNameMatch.java 15 Oct 2006 08:42:07 -0000 1.5 >+++ search/org/eclipse/jdt/core/search/TypeNameMatch.java 16 Oct 2006 13:13:48 -0000 >@@ -13,49 +13,30 @@ > import org.eclipse.jdt.core.*; > > /** >- * A match collected while searching for all type names using >- * {@link SearchEngine#searchAllTypeNames( char[] packageName, int >- * packageMatchRule, char[] typeName, int typeMatchRule, int searchFor, >- * IJavaSearchScope scope, TypeNameMatchRequestor nameMatchRequestor, int >- * waitingPolicy, org.eclipse.core.runtime.IProgressMonitor monitor)} method >+ * A match collected while searching for {@link SearchEngine} >+ * all type names methods using a {@link TypeNameRequestor requestor}. > * <p> > * User can get type from this match using {@link #getType()} method. > * </p> > * <p> >- * This class may be overridden by clients. >+ * This class is intented to be overridden by clients. > * </p> > * > * @see TypeNameMatchRequestor >- * >+ * @see SearchEngine#searchAllTypeNames(char[], int, char[], int, int, IJavaSearchScope, TypeNameMatchRequestor, int, org.eclipse.core.runtime.IProgressMonitor) >+ * @see SearchEngine#searchAllTypeNames(char[][], char[][], IJavaSearchScope, TypeNameMatchRequestor, int, org.eclipse.core.runtime.IProgressMonitor) > * @since 3.3 > */ >-public class TypeNameMatch { >- >-private IType type; >-private int modifiers = -1; // store modifiers to avoid java model population >- >-/** >- * Creates a new type name match. >- */ >-public TypeNameMatch(IType type, int modifiers) { >- this.type = type; >- this.modifiers = modifiers; >-} >- >-/** >- * Returns whether the stored type is equals to given object or not. >- */ >-public boolean equals(Object obj) { >- if (obj == null) return false; >- return getType().equals(obj); >-} >+public abstract class TypeNameMatch { > > /** >- * Returns the fully qualified name of stored type >- * (e.g. package name + '.' enclosing type names + '.' simple name) >+ * Returns the matched type fully qualified name using '.' character >+ * as separator (e.g. package name + '.' enclosing type names + '.' simple name). > * > * @see #getType() > * @see IType#getFullyQualifiedName(char) >+ * >+ * @throws NullPointerException if matched type is <code> null</code> > * @return Fully qualified type name of the type > */ > public String getFullyQualifiedName() { >@@ -70,9 +51,7 @@ > * > * @return the type modifiers > */ >-public int getModifiers() { >- return this.modifiers; >-} >+public abstract int getModifiers(); > > /** > * Returns the package fragment root of the stored type. >@@ -80,6 +59,8 @@ > * > * @see #getType() > * @see IJavaElement#getAncestor(int) >+ * >+ * @throws NullPointerException if matched type is <code> null</code> > * @return the existing java model package fragment root (ie. cannot be <code>null</code> > * and will return <code>true</code> to <code>exists()</code> message). > */ >@@ -92,6 +73,8 @@ > * > * @see #getType() > * @see IType#getPackageFragment() >+ * >+ * @throws NullPointerException if matched type is <code> null</code> > * @return the package name > */ > public String getPackageName() { >@@ -103,6 +86,8 @@ > * > * @see #getType() > * @see IJavaElement#getElementName() >+ * >+ * @throws NullPointerException if matched type is <code> null</code> > * @return the type name > */ > public String getSimpleTypeName() { >@@ -110,8 +95,8 @@ > } > > /** >- * Returns an non-null java model type handle. This handle may >- * exist or not. >+ * Returns a java model type handle. >+ * This handle may exist or not, but is not supposed to be <code>null</code>. > * <p> > * This is a handle-only method as neither Java Model nor classpath > * initializations are done while calling this method. >@@ -119,15 +104,16 @@ > * @see IType > * @return the non-null handle on matched java model type. > */ >-public IType getType() { >- return this.type; >-} >+public abstract IType getType(); > > /** >- * Name of the type container (e.g. enclosing type names + '.' + simple name). >+ * Name of the type container using '.' character >+ * as separator (e.g. enclosing type names + '.' + simple name). > * > * @see #getType() > * @see IMember#getDeclaringType() >+ * >+ * @throws NullPointerException if matched type is <code> null</code> > * @return Name of the type container > */ > public String getTypeContainerName() { >@@ -140,49 +126,16 @@ > } > > /** >- * Returns the qualified name of type >- * (e.g. enclosing type names + '.' simple name). >+ * Returns the matched type qualified name using '.' character >+ * as separator (e.g. enclosing type names + '.' simple name). > * > * @see #getType() > * @see IType#getTypeQualifiedName(char) >+ * >+ * @throws NullPointerException if matched type is <code> null</code> > * @return Fully qualified type name of the type > */ > public String getTypeQualifiedName() { > return getType().getTypeQualifiedName('.'); > } >- >-/* (non-Javadoc) >- * Returns the hash code of the matched type. >- * @see java.lang.Object#hashCode() >- */ >-public int hashCode() { >- return getType().hashCode(); >-} >- >-/** >- * Set modifiers which corresponds to the matched type. >- * >- * @param modifiers the modifiers of the matched type. >- */ >-public void setModifiers(int modifiers) { >- this.modifiers = modifiers; >-} >- >-/** >- * Set matched type. >- * >- * @param type the matched type. >- */ >-public void setType(IType type) { >- this.type = type; >-} >- >- >-/* (non-Javadoc) >- * Returns the string of the matched type. >- * @see java.lang.Object#toString() >- */ >-public String toString() { >- return getType().toString(); >-} > } >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.135 >diff -u -r1.135 SearchEngine.java >--- search/org/eclipse/jdt/core/search/SearchEngine.java 13 Oct 2006 13:27:57 -0000 1.135 >+++ search/org/eclipse/jdt/core/search/SearchEngine.java 16 Oct 2006 13:13:48 -0000 >@@ -157,6 +157,17 @@ > } > > /** >+ * Create a type name match on a given type with specific modifiers. >+ * >+ * @param type The java model handle of the type >+ * @param modifiers Modifiers of the type >+ * @return A non-null match on the given type. >+ */ >+ public static TypeNameMatch createDefaultTypeNameMatch(IType type, int modifiers) { >+ return BasicSearchEngine.createDefaultTypeNameMatch(type, modifiers); >+ } >+ >+ /** > * Returns a Java search scope limited to the hierarchy of the given type. > * The Java elements resulting from a search with this scope will > * be types in this hierarchy, or members of the types in this hierarchy. >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.41 >diff -u -r1.41 BasicSearchEngine.java >--- search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 11 Oct 2006 16:58:02 -0000 1.41 >+++ search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 16 Oct 2006 13:13:49 -0000 >@@ -94,6 +94,13 @@ > } > > /** >+ * @see SearchEngine#createDefaultTypeNameMatch(IType, int) for detailed comment. >+ */ >+ public static TypeNameMatch createDefaultTypeNameMatch(IType type, int modifiers) { >+ return new JavaSearchTypeNameMatch(type, modifiers); >+ } >+ >+ /** > * @see SearchEngine#createHierarchyScope(IType) for detailed comment. > */ > public static IJavaSearchScope createHierarchyScope(IType type) throws JavaModelException { >@@ -809,7 +816,7 @@ > } > if (match(typeSuffix, packageName, typeName, typeMatchRule, kind, packageDeclaration, simpleName)) { > if (nameRequestor instanceof TypeNameMatchRequestorWrapper) { >- ((TypeNameMatchRequestorWrapper)nameRequestor).requestor.acceptTypeNameMatch(new TypeNameMatch(type, type.getFlags())); >+ ((TypeNameMatchRequestorWrapper)nameRequestor).requestor.acceptTypeNameMatch(new JavaSearchTypeNameMatch(type, type.getFlags())); > } else { > nameRequestor.acceptType(type.getFlags(), packageDeclaration, simpleName, enclosingTypeNames, path, null); > } >@@ -830,7 +837,7 @@ > if (match(typeSuffix, packageName, typeName, typeMatchRule, TypeDeclaration.kind(typeDeclaration.modifiers), packageDeclaration, typeDeclaration.name)) { > if (nameRequestor instanceof TypeNameMatchRequestorWrapper) { > IType type = workingCopy.getType(new String(typeName)); >- ((TypeNameMatchRequestorWrapper)nameRequestor).requestor.acceptTypeNameMatch(new TypeNameMatch(type, typeDeclaration.modifiers)); >+ ((TypeNameMatchRequestorWrapper)nameRequestor).requestor.acceptTypeNameMatch(new JavaSearchTypeNameMatch(type, typeDeclaration.modifiers)); > } else { > nameRequestor.acceptType(typeDeclaration.modifiers, packageDeclaration, typeDeclaration.name, CharOperation.NO_CHAR_CHAR, path, null); > } >@@ -856,7 +863,7 @@ > for (int j=1, l=enclosingTypeNames.length; j<l; j++) { > type = type.getType(new String(enclosingTypeNames[j])); > } >- ((TypeNameMatchRequestorWrapper)nameRequestor).requestor.acceptTypeNameMatch(new TypeNameMatch(type, 0)); >+ ((TypeNameMatchRequestorWrapper)nameRequestor).requestor.acceptTypeNameMatch(new JavaSearchTypeNameMatch(type, 0)); > } else { > nameRequestor.acceptType(memberTypeDeclaration.modifiers, packageDeclaration, memberTypeDeclaration.name, enclosingTypeNames, path, null); > } >@@ -953,6 +960,10 @@ > IndexQueryRequestor searchRequestor = new IndexQueryRequestor(){ > public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant, AccessRuleSet access) { > // Filter unexpected types >+ QualifiedTypeDeclarationPattern record = (QualifiedTypeDeclarationPattern) indexRecord; >+ if (record.enclosingTypeNames == IIndexConstants.ONE_ZERO_CHAR) { >+ return true; // filter out local and anonymous classes >+ } > switch (copiesLength) { > case 0: > break; >@@ -969,7 +980,6 @@ > } > > // Accept document path >- QualifiedTypeDeclarationPattern record = (QualifiedTypeDeclarationPattern) indexRecord; > AccessRestriction accessRestriction = null; > if (access != null) { > // Compute document relative path >Index: search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java,v >retrieving revision 1.2 >diff -u -r1.2 TypeNameMatchRequestorWrapper.java >--- search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java 6 Oct 2006 17:43:34 -0000 1.2 >+++ search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java 16 Oct 2006 13:13:49 -0000 >@@ -19,7 +19,6 @@ > import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.compiler.CharOperation; > import org.eclipse.jdt.core.search.IJavaSearchScope; >-import org.eclipse.jdt.core.search.TypeNameMatch; > import org.eclipse.jdt.core.search.TypeNameMatchRequestor; > import org.eclipse.jdt.core.search.TypeNameRequestor; > import org.eclipse.jdt.internal.compiler.env.AccessRestriction; >@@ -75,44 +74,13 @@ > */ > public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) { > if (access == null) { // accept only if there's no access violation >-// if (this.handleFactory == null) { >-// this.handleFactory = new HandleFactory(); >-// } >-// Openable openable = this.handleFactory.createOpenable(path, this.scope); >-// if (openable != null) { >-// try { >-// IType type = null; >-// switch (openable.getElementType()) { >-// case IJavaElement.CLASS_FILE: >-// type = ((IClassFile)openable).getType(); >-// break; >-// case IJavaElement.COMPILATION_UNIT: >-// int length = enclosingTypeNames == null ? 0 : enclosingTypeNames.length; >-// if (length == 0) { >-// type = ((ICompilationUnit)openable).getType(new String(simpleTypeName)); >-// } else { >-// type = ((ICompilationUnit)openable).getType(new String(enclosingTypeNames[0])); >-// for (int i=1; i<length; i++) { >-// type = type.getType(new String(enclosingTypeNames[i])); >-// } >-// type = type.getType(new String(simpleTypeName)); >-// } >-// break; >-// } >-// if (type != null) { >-// this.requestor.acceptTypeNameMatch(new TypeNameMatch(type, modifiers)); >-// } >-// } catch (JavaModelException e) { >-// // skip >-// } >-// } > try { > int separatorIndex= path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR); > IType type = separatorIndex == -1 > ? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames) > : createTypeFromJar(path, separatorIndex); > if (type != null) { >- this.requestor.acceptTypeNameMatch(new TypeNameMatch(type, modifiers)); >+ this.requestor.acceptTypeNameMatch(new JavaSearchTypeNameMatch(type, modifiers)); > } > } catch (JavaModelException e) { > // skip >Index: search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java,v >retrieving revision 1.40 >diff -u -r1.40 SourceIndexerRequestor.java >--- search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java 14 Jun 2006 16:44:26 -0000 1.40 >+++ search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java 16 Oct 2006 13:13:49 -0000 >@@ -155,6 +155,7 @@ > } > char[][] typeNames; > if (this.methodDepth > 0) { >+ // set specific ['0'] value for local and anonymous to be able to filter them > typeNames = ONE_ZERO_CHAR; > } else { > typeNames = this.enclosingTypeNames(); >Index: search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java,v >retrieving revision 1.57 >diff -u -r1.57 BinaryIndexer.java >--- search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java 4 Aug 2006 15:11:23 -0000 1.57 >+++ search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java 16 Oct 2006 13:13:49 -0000 >@@ -642,6 +642,7 @@ > name = reader.getInnerSourceName(); > } > if (reader.isLocal() || reader.isAnonymous()) { >+ // set specific ['0'] value for local and anonymous to be able to filter them > enclosingTypeName = ONE_ZERO; > } else { > char[] fullEnclosingName = reader.getEnclosingTypeName(); >Index: search/org/eclipse/jdt/internal/core/search/JavaSearchTypeNameMatch.java >=================================================================== >RCS file: search/org/eclipse/jdt/internal/core/search/JavaSearchTypeNameMatch.java >diff -N search/org/eclipse/jdt/internal/core/search/JavaSearchTypeNameMatch.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ search/org/eclipse/jdt/internal/core/search/JavaSearchTypeNameMatch.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,101 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2006 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 >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.core.search; >+ >+import org.eclipse.jdt.core.*; >+import org.eclipse.jdt.core.search.*; >+ >+/** >+ * Java Search concrete class for a type name match. >+ * >+ * @since 3.3 >+ */ >+public class JavaSearchTypeNameMatch extends TypeNameMatch { >+ >+private IType type; >+private int modifiers = -1; // store modifiers to avoid java model population >+ >+/** >+ * Creates a new Java Search type name match. >+ */ >+public JavaSearchTypeNameMatch(IType type, int modifiers) { >+ this.type = type; >+ this.modifiers = modifiers; >+} >+ >+/* (non-Javadoc) >+ * Returns whether the matched type is equals to the given object or not. >+ * @see java.lang.Object#equals(java.lang.Object) >+ */ >+public boolean equals(Object obj) { >+ if (obj == this) return true; // avoid unnecessary calls for identical objects >+ if (obj instanceof TypeNameMatch) { >+ TypeNameMatch match = (TypeNameMatch) obj; >+ if (this.type == null) { >+ return match.getType() == null && match.getModifiers() == this.modifiers; >+ } >+ return this.type.equals(match.getType()) && match.getModifiers() == this.modifiers; >+ } >+ return false; >+} >+ >+/* (non-Javadoc) >+ * @see org.eclipse.jdt.core.search.TypeNameMatch#getModifiers() >+ */ >+public int getModifiers() { >+ return this.modifiers; >+} >+ >+/* (non-Javadoc) >+ * Note that returned handle exists as it matches a type accepted >+ * from up-to-date index file. >+ * @see org.eclipse.jdt.core.search.TypeNameMatch#getType() >+ */ >+public IType getType() { >+ return this.type; >+} >+ >+/* (non-Javadoc) >+ * Returns the hash code of the matched type. >+ * @see java.lang.Object#hashCode() >+ */ >+public int hashCode() { >+ if (this.type == null) return this.modifiers; >+ return this.type.hashCode(); >+} >+ >+/** >+ * Set modifiers of the matched type. >+ * >+ * @param modifiers the modifiers of the matched type. >+ */ >+public void setModifiers(int modifiers) { >+ this.modifiers = modifiers; >+} >+ >+/** >+ * Set matched type. >+ * >+ * @param type the matched type. >+ */ >+public void setType(IType type) { >+ this.type = type; >+} >+ >+/* (non-Javadoc) >+ * Returns the string of the matched type. >+ * @see java.lang.Object#toString() >+ */ >+public String toString() { >+ if (this.type == null) return super.toString(); >+ return this.type.toString(); >+} >+} >#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.90 >diff -u -r1.90 JavaSearchBugsTests.java >--- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 11 Oct 2006 16:58:38 -0000 1.90 >+++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 16 Oct 2006 13:14:15 -0000 >@@ -7164,11 +7164,6 @@ > 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(); > } >@@ -7199,6 +7194,7 @@ > 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} >@@ -7206,13 +7202,9 @@ > * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=160324" > */ > public void testBug160324a() throws CoreException { >+ boolean debug = false; > // 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(); > } >@@ -7224,7 +7216,6 @@ > 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( >@@ -7234,7 +7225,10 @@ > requestor, > IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, > null); >- assertEquals("We should not find any type", "", requestor.toString()); >+ if (debug) System.out.println("TypeNameRequestor results: \n"+requestor); >+ // 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()); > } > public void testBug160324b() throws CoreException { > // Search all type names with new API >@@ -7312,4 +7306,74 @@ > assertEquals("Wrong number of found types!", packagesList.length, collector.size()); > assertEquals("Found types sounds not to be correct", requestor.toString(), collector.toString()); > } >+ >+/** >+ * @bug 160854: [search] No type is found using seachAllTypeNames(char[][],char[][],...) methods when no type names is specified >+ * @test Ensure that types are found when typeNames parameter is null... >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=160854" >+ */ >+public void testBug160854() throws CoreException { >+ char[][] packagesList = new char[][] { >+ "java.lang".toCharArray() >+ }; >+ // Search all type names with new API >+ TypeNameMatchCollector collector = new TypeNameMatchCollector() { >+ public String toString(){ >+ return toFullyQualifiedNamesString(); >+ } >+ }; >+ new SearchEngine().searchAllTypeNames( >+ packagesList, >+ null, >+ getJavaSearchScopeBugs(), >+ collector, >+ IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, >+ null); >+ // Search all type names with old API >+ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); >+ new SearchEngine().searchAllTypeNames( >+ packagesList, >+ null, >+ getJavaSearchScopeBugs(), >+ requestor, >+ IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, >+ null); >+ // Should have same types with these 2 searches >+ assertSearchResults("Wrong types found!", >+ "java.lang.CharSequence\n" + >+ "java.lang.Class\n" + >+ "java.lang.CloneNotSupportedException\n" + >+ "java.lang.Comparable\n" + >+ "java.lang.Enum\n" + >+ "java.lang.Error\n" + >+ "java.lang.Exception\n" + >+ "java.lang.IllegalMonitorStateException\n" + >+ "java.lang.InterruptedException\n" + >+ "java.lang.Object\n" + >+ "java.lang.RuntimeException\n" + >+ "java.lang.String\n" + >+ "java.lang.Throwable", >+ requestor >+ ); >+ assertEquals("Found types sounds not to be correct", requestor.toString(), collector.toString()); >+} >+ >+ >+/** >+ * @bug 161028: [search] NPE on organize imports in TypeNameMatch.equals >+ * @test Ensure that no NPE may happen calling <code>equals(Object)</code>, >+ * <code>hashCode()</code> or <code>toString()</code> methods. >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=161028" >+ */ >+public void testBug161028() throws CoreException { >+ TypeNameMatch match1 = SearchEngine.createDefaultTypeNameMatch(null, 0); >+ assertEquals("Should be equals!", match1, match1); >+ assertEquals("Wrong toString value!", "org.eclipse.jdt.internal.core.search.JavaSearchTypeNameMatch@0", match1.toString()); >+ TypeNameMatch match2 = SearchEngine.createDefaultTypeNameMatch(null, 0); >+ assertFalse("Should NOT be identical!", match1 == match2); >+ assertTrue("Should be equals!", match1.equals(match2)); >+ assertTrue("Should be equals!", match2.equals(match1)); >+ assertEquals("Wrong toString value!", match1, match2); >+ assertEquals("Should have same hashCode!", match1.hashCode(), match2.hashCode()); >+} > } >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 161028
:
52022
| 52038