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 175371 Details for
Bug 317264
[search] Refactoring is impossible with commons.lang added to project
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
patch.txt (text/plain), 14.62 KB, created by
Satyam Kandula
on 2010-07-28 03:14:36 EDT
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Satyam Kandula
Created:
2010-07-28 03:14:36 EDT
Size:
14.62 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >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.15 >diff -u -r1.15 TypeNameMatchRequestorWrapper.java >--- search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java 4 Dec 2009 09:12:10 -0000 1.15 >+++ search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java 28 Jul 2010 07:10:30 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2010 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,6 +16,7 @@ > import org.eclipse.jdt.core.IClassFile; > import org.eclipse.jdt.core.ICompilationUnit; > import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IJavaProject; > import org.eclipse.jdt.core.IPackageFragment; > import org.eclipse.jdt.core.IPackageFragmentRoot; > import org.eclipse.jdt.core.IType; >@@ -25,8 +26,11 @@ > import org.eclipse.jdt.core.search.IJavaSearchScope; > import org.eclipse.jdt.core.search.TypeNameMatchRequestor; > import org.eclipse.jdt.core.search.TypeNameRequestor; >+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; > import org.eclipse.jdt.internal.compiler.env.AccessRestriction; >+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; > import org.eclipse.jdt.internal.core.Openable; >+import org.eclipse.jdt.internal.core.PackageFragment; > import org.eclipse.jdt.internal.core.PackageFragmentRoot; > import org.eclipse.jdt.internal.core.util.HandleFactory; > import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject; >@@ -69,6 +73,8 @@ > * Cache package handles to optimize memory. > */ > private HashtableOfArrayToObject packageHandles; >+ private long complianceValue; >+ private IJavaProject lastProject; > > public TypeNameMatchRequestorWrapper(TypeNameMatchRequestor requestor, IJavaSearchScope scope) { > this.requestor = requestor; >@@ -116,7 +122,8 @@ > // Accept match if the type has been found > if (type != null) { > // hierarchy scopes require one more check: >- if (!(this.scope instanceof HierarchyScope) || ((HierarchyScope)this.scope).enclosesFineGrained(type)) { >+ if ((!(this.scope instanceof HierarchyScope) || ((HierarchyScope)this.scope).enclosesFineGrained(type)) >+ && (!filterMatch(type))) { > > // Create the match > final JavaSearchTypeNameMatch match = new JavaSearchTypeNameMatch(type, modifiers); >@@ -220,4 +227,57 @@ > } > return null; > } >+ >+private boolean filterMatch(IJavaElement type) { >+ >+ // filter enum and assert - these keywords have been added in >+ // latter versions of Java and hence should be filtered off >+ // for the versions they are introduced >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=313668 >+ while (type != null) { >+ if (type.getElementType() == IJavaElement.PACKAGE_FRAGMENT) { >+ String[] names = ((PackageFragment)type).names; >+ for (int i = 0, l = names.length; i < l; i++) { >+ if (isNameNewKeyword(type, names[i])) >+ return true; >+ } >+ return false; >+ } >+ if (isNameNewKeyword(type, type.getElementName())) { >+ return true; >+ } >+ type = type.getParent(); >+ } >+ return false; >+} >+ >+// this function is optimized to assume that there are lesser chances of enum or assert as the name >+private boolean isNameNewKeyword(IJavaElement type, String name) { >+ if (name == null) >+ return false; >+ switch(name.length()) { >+ case 4: // length of enum >+ if (name.equals("enum")) {//$NON-NLS-1$ >+ return (getProjectCompliance(type) >= ClassFileConstants.JDK1_5); >+ } >+ break; >+ case 6: // length of assert >+ if (name.equals("assert")) {//$NON-NLS-1$ >+ return (getProjectCompliance(type) >= ClassFileConstants.JDK1_4); >+ } >+ break; >+ } >+ return false; >+} >+ >+private long getProjectCompliance(IJavaElement type) { >+ IJavaProject proj = (IJavaProject)type.getAncestor(IJavaElement.JAVA_PROJECT); >+ if (proj != this.lastProject) { >+ String complianceStr = proj.getOption(CompilerOptions.OPTION_Source, true); >+ this.complianceValue = CompilerOptions.versionToJdkLevel(complianceStr); >+ this.lastProject = proj; >+ } >+ return this.complianceValue; >+} >+ > } >Index: search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java,v >retrieving revision 1.332 >diff -u -r1.332 MatchLocator.java >--- search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 20 May 2010 14:12:00 -0000 1.332 >+++ search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 28 Jul 2010 07:10:33 -0000 >@@ -257,6 +257,29 @@ > return null; > } > >+private boolean filterMatch(SearchMatch match) { >+ >+ // filter enum and assert - these keywords have been added in >+ // later versions of Java and hence should be filtered off >+ // for the versions they are introduced >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=313668 >+ IJavaElement element = (IJavaElement)match.getElement(); >+ if (this.options != null && this.options.sourceLevel < ClassFileConstants.JDK1_3) >+ return false; >+ while (element != null) { >+ if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT) { >+ String[] names = ((PackageFragment)element).names; >+ for (int i = 0, l = names.length; i < l; i++) { >+ if (isNameNewKeyword(element, names[i])) return true; >+ } >+ return false; >+ } >+ if (isNameNewKeyword(element, element.getElementName())) return true; >+ element = element.getParent(); >+ } >+ return false; >+} >+ > /** > * Query a given index for matching entries. Assumes the sender has opened the index and will close when finished. > */ >@@ -927,6 +950,14 @@ > this.bindings.put(methodPattern, new ProblemMethodBinding(methodPattern.selector, null, ProblemReasons.NotFound)); > return null; > } >+ >+private long getProjectCompliance(IJavaElement element) { >+ if (this.options != null) return this.options.sourceLevel; >+ IJavaProject proj = (IJavaProject)element.getAncestor(IJavaElement.JAVA_PROJECT); >+ String complianceStr = proj.getOption(CompilerOptions.OPTION_Source, true); >+ return CompilerOptions.versionToJdkLevel(complianceStr); >+} >+ > protected boolean hasAlreadyDefinedType(CompilationUnitDeclaration parsedUnit) { > CompilationResult result = parsedUnit.compilationResult; > if (result == null) return false; >@@ -935,6 +966,23 @@ > return true; > return false; > } >+ >+// this function is optimized to assume that there are lesser chances of enum or assert as the name >+private boolean isNameNewKeyword(IJavaElement element, String name) { >+ switch(name.length()) { >+ case 4: // length of enum >+ if (name.equals("enum")) {//$NON-NLS-1$ >+ return (getProjectCompliance(element) >= ClassFileConstants.JDK1_5); >+ } >+ return false; >+ case 6: // length of assert >+ if (name.equals("assert")) {//$NON-NLS-1$ >+ return (getProjectCompliance(element) >= ClassFileConstants.JDK1_4); >+ } >+ return false; >+ } >+ return false; >+} > /** > * Create a new parser for the given project, as well as a lookup environment. > */ >@@ -1702,6 +1750,9 @@ > } > return; > } >+ if (filterMatch(match)) { >+ return; >+ } > long start = -1; > if (BasicSearchEngine.VERBOSE) { > start = System.currentTimeMillis(); >#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.200 >diff -u -r1.200 JavaSearchBugsTests.java >--- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 28 Jun 2010 13:28:41 -0000 1.200 >+++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 28 Jul 2010 07:10:49 -0000 >@@ -61,7 +61,7 @@ > // Debug > static { > // org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true; >-// TESTS_NAMES = new String[] {"testBug306223"}; >+ //TESTS_NAMES = new String[] {"testBug317264f"}; > } > > public JavaSearchBugsTests(String name) { >@@ -11946,4 +11946,142 @@ > deleteProject(serverProject); > } > } >+ >+/** >+ * @bug 317264: Refactoring is impossible with commons.lang added to project >+ * @test 1.5 compliant project should not return any types having the name `enum` or `assert' >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=313668" >+ */ >+public void testBug317264a() throws CoreException { >+ IJavaProject project = null; >+ try >+ { >+ project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5"); >+ addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/b317264.jar"), null, null)); >+ int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS; >+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); >+ >+ waitUntilIndexesReady(); >+ TypeNameMatchCollector collector = new TypeNameMatchCollector(); >+ new SearchEngine().searchAllTypeNames( >+ "b317264".toCharArray(), >+ SearchPattern.R_PREFIX_MATCH, >+ "".toCharArray(), >+ SearchPattern.R_PREFIX_MATCH, >+ IJavaSearchConstants.TYPE, >+ scope, >+ collector, >+ IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, >+ null); >+ assertSearchResults("Unexpected search results!", "", collector); >+ } finally { >+ deleteProject(project); >+ } >+} >+ >+/** >+ * 1.4 compliant project should return types named enum >+ */ >+public void testBug317264b() throws CoreException { >+ IJavaProject project = null; >+ try >+ { >+ project = createJavaProject("P"); >+ project.setOption(CompilerOptions.OPTION_Source, "1.4"); >+ addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/b317264.jar"), null, null)); >+ int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS; >+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); >+ waitUntilIndexesReady(); >+ TypeNameMatchCollector collector = new TypeNameMatchCollector(); >+ new SearchEngine().searchAllTypeNames( >+ "b317264".toCharArray(), >+ SearchPattern.R_PREFIX_MATCH, >+ "".toCharArray(), >+ SearchPattern.R_PREFIX_MATCH, >+ IJavaSearchConstants.TYPE, >+ scope, >+ collector, >+ IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, >+ null); >+ assertSearchResults("Unexpected search results!", >+ "InEnum (not open) [in InEnum.class [in b317264.enum [in /JavaSearchBugs/lib/b317264.jar [in P]]]]", >+ collector); >+ } finally { >+ deleteProject(project); >+ } >+} >+ >+/** >+ * search of types in a 1.5 compliant project should not return any types having the name `enum` or `assert' >+ */ >+public void testBug317264c() throws CoreException { >+ try >+ { >+ IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5"); >+ addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/b317264.jar"), null, null)); >+ int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ; >+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); >+ search("b317264.*", IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, scope, this.resultCollector); >+ assertSearchResults("Unexpected search results!", "", this.resultCollector); >+ } finally { >+ deleteProject("P"); >+ } >+} >+ >+/** >+ * search of types in a 1.4 compliant project should return types having the name `enum` >+ */ >+public void testBug317264d() throws CoreException { >+ try >+ { >+ IJavaProject project = createJavaProject("P"); >+ project.setOption(CompilerOptions.OPTION_Source, "1.4"); >+ addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/b317264.jar"), null, null)); >+ int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ; >+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); >+ search("b317264.*", IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, scope, this.resultCollector); >+ assertSearchResults("Unexpected search results!", >+ "lib/b317264.jar b317264.enum.InEnum EXACT_MATCH", >+ this.resultCollector); >+ } finally { >+ deleteProject("P"); >+ } >+} >+ >+/** >+ * search of packages in a 1.5 compliant project should not return types having the name `enum` and `assert` >+ */ >+public void testBug317264e() throws CoreException { >+ try >+ { >+ IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5"); >+ addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/b317264.jar"), null, null)); >+ int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ; >+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); >+ search("b317264.*", IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, scope, this.resultCollector); >+ assertSearchResults("Unexpected search results!", "", this.resultCollector); >+ } finally { >+ deleteProject("P"); >+ } >+} >+ >+/** >+ * search of packages in a 1.4 compliant project should not return types having the name `assert` but should return 'enum' >+ */ >+public void testBug317264f() throws CoreException { >+ try >+ { >+ IJavaProject project = createJavaProject("P"); >+ project.setOption(CompilerOptions.OPTION_Source, "1.4"); >+ addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/b317264.jar"), null, null)); >+ int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ; >+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); >+ search("b317264.*", IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, scope, this.resultCollector); >+ assertSearchResults("Unexpected search results!", >+ "lib/b317264.jar b317264.enum [No source] EXACT_MATCH", >+ this.resultCollector); >+ } finally { >+ deleteProject("P"); >+ } >+} > } >\ 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 317264
:
172186
|
175371
|
175372
|
177329
|
177332
|
177381