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 51563 Details for
Bug 148380
[search] get IType from TypeNameRequestor result
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
New implementation for this functionality
v11.txt (text/plain), 52.16 KB, created by
Frederic Fusier
on 2006-10-06 13:40:08 EDT
(
hide
)
Description:
New implementation for this functionality
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2006-10-06 13:40:08 EDT
Size:
52.16 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#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.86 >diff -u -r1.86 JavaSearchBugsTests.java >--- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 3 Oct 2006 11:31:47 -0000 1.86 >+++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 6 Oct 2006 16:25:15 -0000 >@@ -11,6 +11,7 @@ > package org.eclipse.jdt.core.tests.model; > > import java.util.ArrayList; >+import java.util.Arrays; > import java.util.List; > > import junit.framework.Test; >@@ -82,6 +83,36 @@ > } > } > >+class TypeNameMatchCollector extends TypeNameMatchRequestor { >+ private int index = -1; >+ public String[] results = new String[10]; >+ public void acceptTypeNameMatch(TypeNameMatch match) { >+ int length = results.length; >+ if (++index > length) { >+ System.arraycopy(results, 0, results = new String[length+10], 0, length); >+ } >+ try { >+ IType type = match.getType(); >+ if (type != null) { >+ results[index] = type.toString(); >+ } >+ } >+ catch (JavaModelException jme) { >+ assertTrue("We should not have any JavaModel exception! Message:"+jme.getMessage(), false); >+ } >+ } >+ public String toString() { >+ String[] strings = new String[index+1]; >+ System.arraycopy(results, 0, strings, 0, index+1); >+ Arrays.sort(strings); >+ StringBuffer buffer = new StringBuffer(); >+ for (int i=0; i<=index; i++) { >+ if (i>0) buffer.append('\n'); >+ buffer.append(strings[i]); >+ } >+ return buffer.toString(); >+ } >+} > IJavaSearchScope getJavaSearchScopeBugs() { > return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearchBugs")}); > } >@@ -6879,7 +6910,7 @@ > "public class Y {}\n" > ); > IJavaSearchScope scope = getJavaSearchScopeBugs(); >- TestTypeNameMatchRequestor requestor1 = new TestTypeNameMatchRequestor(); >+ TypeNameMatchCollector requestor1 = new TypeNameMatchCollector(); > new SearchEngine(this.workingCopies).searchAllTypeNames( > "b148380".toCharArray(), > SearchPattern.R_EXACT_MATCH, >@@ -6890,15 +6921,13 @@ > requestor1, > IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, > null); >- assertSearchResults( >- "interface I [in [Working copy] I.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + >+ String expected = "class Sub [in [Working copy] Sub.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + > "class X [in [Working copy] X.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + >- "class Sub [in [Working copy] Sub.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + >- "class Y [in [Working copy] Y.java [in b148380 [in src [in JavaSearchBugs]]]]", >- requestor1); >- /* DISABLED as results order is not the same on different VM... >- * Expected same result with the wc owner >- TestTypeNameMatchRequestor requestor2 = new TestTypeNameMatchRequestor(); >+ "class Y [in [Working copy] Y.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + >+ "interface I [in [Working copy] I.java [in b148380 [in src [in JavaSearchBugs]]]]"; >+ assertSearchResults(expected, requestor1); >+ // Expected same result with the wc owner >+ TypeNameMatchCollector requestor2 = new TypeNameMatchCollector(); > new SearchEngine(this.wcOwner).searchAllTypeNames( > "b148380".toCharArray(), > SearchPattern.R_EXACT_MATCH, >@@ -6909,16 +6938,11 @@ > requestor2, > IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, > null); >- assertSearchResults("class Sub [in [Working copy] Sub.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + >- "class Y [in [Working copy] Y.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + >- "interface I [in [Working copy] I.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + >- "class X [in [Working copy] X.java [in b148380 [in src [in JavaSearchBugs]]]]", >- requestor2); >- */ >+ assertSearchResults(expected, requestor2); > } > public void testBug148380_SearchAllTypes_cu() throws CoreException, JavaModelException { > IJavaSearchScope scope = getJavaSearchScopeBugs(); >- TestTypeNameMatchRequestor requestor = new TestTypeNameMatchRequestor(); >+ TypeNameMatchCollector requestor = new TypeNameMatchCollector(); > new SearchEngine().searchAllTypeNames( > null, > SearchPattern.R_EXACT_MATCH, >@@ -6936,7 +6960,7 @@ > } > public void testBug148380_SearchAllTypes_cu_wksp() throws CoreException, JavaModelException { > IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); >- TestTypeNameMatchRequestor requestor = new TestTypeNameMatchRequestor(); >+ TypeNameMatchCollector requestor = new TypeNameMatchCollector(); > new SearchEngine().searchAllTypeNames( > null, > SearchPattern.R_EXACT_MATCH, >@@ -7083,26 +7107,4 @@ > ); > } > >-/** >- * Bug 156491: [1.5][search] interfaces and annotations could be found with only one requets of searchAllTypeName >- * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491" >- */ >-class TestTypeNameMatchRequestor extends TypeNameMatchRequestor { >- public StringBuffer results = new StringBuffer(); >- public void acceptTypeNameMatch(TypeNameMatch match) { >- if (results.length() > 0) results.append('\n'); >- try { >- IType type = match.resolvedType(); >- if (type != null) { >- results.append(type.toString()); >- } >- } >- catch (JavaModelException jme) { >- assertTrue("We should not have no JavaModel exception! Message:"+jme.getMessage(), false); >- } >- } >- public String toString() { >- return this.results.toString(); >- } >-} > } >\ No newline at end of file >#P org.eclipse.jdt.core >Index: search/org/eclipse/jdt/internal/core/search/WorkingCopiesTypeNameMatch.java >=================================================================== >RCS file: search/org/eclipse/jdt/internal/core/search/WorkingCopiesTypeNameMatch.java >diff -N search/org/eclipse/jdt/internal/core/search/WorkingCopiesTypeNameMatch.java >--- search/org/eclipse/jdt/internal/core/search/WorkingCopiesTypeNameMatch.java 3 Oct 2006 11:32:05 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,36 +0,0 @@ >-/******************************************************************************* >- * 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.ICompilationUnit; >-import org.eclipse.jdt.core.search.TypeNameMatch; >- >-/** >- * Specific match collected while searching for all type names >- * when type belongs to a working copy. >- * >- * @since 3.3 >- */ >-public class WorkingCopiesTypeNameMatch extends TypeNameMatch { >- private ICompilationUnit[] workingCopies; >- >-public WorkingCopiesTypeNameMatch(int modifiers, char[] packageName, char[] typeName, char[][] enclosingTypeNames, String path, ICompilationUnit[] workingCopies) { >- super(modifiers, packageName, typeName, enclosingTypeNames, path); >- this.workingCopies = workingCopies; >-} >- >-/* (non-Javadoc) >- * @see org.eclipse.jdt.core.search.TypeNameMatch#getWorkingCopies() >- */ >-protected ICompilationUnit[] getWorkingCopies() { >- return this.workingCopies; >-} >-} >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.39 >diff -u -r1.39 BasicSearchEngine.java >--- search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 3 Oct 2006 11:32:05 -0000 1.39 >+++ search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 6 Oct 2006 16:25:27 -0000 >@@ -326,7 +326,7 @@ > * Returns the list of working copies used by this search engine. > * Returns null if none. > */ >- public ICompilationUnit[] getWorkingCopies() { >+ private ICompilationUnit[] getWorkingCopies() { > ICompilationUnit[] copies; > if (this.workingCopies != null) { > if (this.workingCopyOwner == null) { >@@ -779,7 +779,7 @@ > // add type names from working copies > if (copies != null) { > for (int i = 0; i < copiesLength; i++) { >- ICompilationUnit workingCopy = copies[i]; >+ final ICompilationUnit workingCopy = copies[i]; > if (!scope.encloses(workingCopy)) continue; > final String path = workingCopy.getPath().toString(); > if (workingCopy.isConsistent()) { >@@ -808,7 +808,11 @@ > kind = TypeDeclaration.INTERFACE_DECL; > } > if (match(typeSuffix, packageName, typeName, typeMatchRule, kind, packageDeclaration, simpleName)) { >- nameRequestor.acceptType(type.getFlags(), packageDeclaration, simpleName, enclosingTypeNames, path, null); >+ if (nameRequestor instanceof TypeNameMatchRequestorWrapper) { >+ ((TypeNameMatchRequestorWrapper)nameRequestor).requestor.acceptTypeNameMatch(new TypeNameMatch(type)); >+ } else { >+ nameRequestor.acceptType(type.getFlags(), packageDeclaration, simpleName, enclosingTypeNames, path, null); >+ } > } > } > } else { >@@ -824,7 +828,12 @@ > } > public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope compilationUnitScope) { > if (match(typeSuffix, packageName, typeName, typeMatchRule, TypeDeclaration.kind(typeDeclaration.modifiers), packageDeclaration, typeDeclaration.name)) { >- nameRequestor.acceptType(typeDeclaration.modifiers, packageDeclaration, typeDeclaration.name, CharOperation.NO_CHAR_CHAR, path, null); >+ if (nameRequestor instanceof TypeNameMatchRequestorWrapper) { >+ IType type = workingCopy.getType(new String(typeName)); >+ ((TypeNameMatchRequestorWrapper)nameRequestor).requestor.acceptTypeNameMatch(new TypeNameMatch(type, typeDeclaration.modifiers)); >+ } else { >+ nameRequestor.acceptType(typeDeclaration.modifiers, packageDeclaration, typeDeclaration.name, CharOperation.NO_CHAR_CHAR, path, null); >+ } > } > return true; > } >@@ -842,7 +851,15 @@ > } > } > // report >- nameRequestor.acceptType(memberTypeDeclaration.modifiers, packageDeclaration, memberTypeDeclaration.name, enclosingTypeNames, path, null); >+ if (nameRequestor instanceof TypeNameMatchRequestorWrapper) { >+ IType type = workingCopy.getType(new String(enclosingTypeNames[0])); >+ 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)); >+ } else { >+ nameRequestor.acceptType(memberTypeDeclaration.modifiers, packageDeclaration, memberTypeDeclaration.name, enclosingTypeNames, path, null); >+ } > } > return true; > } >Index: search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java,v >retrieving revision 1.51 >diff -u -r1.51 JavaSearchScope.java >--- search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java 3 Oct 2006 11:32:05 -0000 1.51 >+++ search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java 6 Oct 2006 16:25:28 -0000 >@@ -16,11 +16,26 @@ > > import org.eclipse.core.resources.IProject; > import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.ResourcesPlugin; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.Path; >-import org.eclipse.jdt.core.*; >+import org.eclipse.jdt.core.IClasspathContainer; >+import org.eclipse.jdt.core.IClasspathEntry; >+import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IJavaElementDelta; >+import org.eclipse.jdt.core.IJavaModel; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IMember; >+import org.eclipse.jdt.core.IPackageFragmentRoot; >+import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; >-import org.eclipse.jdt.internal.core.*; >+import org.eclipse.jdt.internal.core.ClasspathEntry; >+import org.eclipse.jdt.internal.core.JavaElement; >+import org.eclipse.jdt.internal.core.JavaModel; >+import org.eclipse.jdt.internal.core.JavaModelManager; >+import org.eclipse.jdt.internal.core.JavaProject; >+import org.eclipse.jdt.internal.core.PackageFragment; > import org.eclipse.jdt.internal.core.util.Util; > > /** >@@ -44,7 +59,7 @@ > > private IPath[] enclosingProjectsAndJars; > public final static AccessRuleSet NOT_ENCLOSED = new AccessRuleSet(null, null); >- >+ > public JavaSearchScope() { > this(5); > } >@@ -158,7 +173,7 @@ > if ((includeMask & SOURCES) != 0) { > IPath path = entry.getPath(); > if (pathToAdd == null || pathToAdd.equals(path)) { >- add(null, Util.relativePath(path,1/*remove project segment*/), projectPathString, false/*not a package*/, access); >+ add(projectPath.toString(), Util.relativePath(path,1/*remove project segment*/), projectPathString, false/*not a package*/, access); > } > } > break; >@@ -187,20 +202,22 @@ > containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath; > containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); > IResource rootResource = root.getResource(); >+ String projectPath = root.getJavaProject().getPath().toString(); > if (rootResource != null && rootResource.isAccessible()) { > String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount()); >- add(null, relativePath, containerPathToString, false/*not a package*/, null); >+ add(projectPath, relativePath, containerPathToString, false/*not a package*/, null); > } else { >- add(null, "", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$ >+ add(projectPath, "", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$ > } > break; > case IJavaElement.PACKAGE_FRAGMENT: > root = (IPackageFragmentRoot)element.getParent(); >+ projectPath = root.getJavaProject().getPath().toString(); > if (root.isArchive()) { > String relativePath = Util.concatWith(((PackageFragment) element).names, '/'); > containerPath = root.getPath(); > containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); >- add(null, relativePath, containerPathToString, true/*package*/, null); >+ add(projectPath, relativePath, containerPathToString, true/*package*/, null); > } else { > IResource resource = element.getResource(); > if (resource != null) { >@@ -212,7 +229,7 @@ > } > containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); > String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount()); >- add(null, relativePath, containerPathToString, true/*package*/, null); >+ add(projectPath, relativePath, containerPathToString, true/*package*/, null); > } > } > break; >@@ -225,6 +242,7 @@ > this.elements.add(element); > } > root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); >+ projectPath = root.getJavaProject().getPath().toString(); > String relativePath; > if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { > containerPath = root.getParent().getPath(); >@@ -234,7 +252,7 @@ > relativePath = getPath(element, true/*relative path*/).toString(); > } > containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); >- add(null, relativePath, containerPathToString, false/*not a package*/, null); >+ add(projectPath, relativePath, containerPathToString, false/*not a package*/, null); > } > > if (containerPath != null) >@@ -259,14 +277,11 @@ > index = 0; > } > } >- int idx = -1; >- if (projectPath != null && !containerPath.startsWith(projectPath)) { >+ int idx = this.projectPaths.indexOf(projectPath); >+ if (idx == -1) { >+ // store project in separated list to minimize memory footprint >+ this.projectPaths.add(projectPath); > idx = this.projectPaths.indexOf(projectPath); >- if (idx == -1) { >- // store project in separated list to minimize memory footprint >- this.projectPaths.add(projectPath); >- idx = this.projectPaths.indexOf(projectPath); >- } > } > this.projectIndexes[index] = idx; > this.relativePaths[index] = relativePath; >@@ -546,10 +561,11 @@ > * @param resourcePathString path of the resource > * @return the project path of the resource > */ >-public String projectPathFor(String resourcePathString) { >+public IPackageFragmentRoot packageFragmentRoot(String resourcePathString) { > int index = -1; > int separatorIndex = resourcePathString.indexOf(JAR_FILE_ENTRY_SEPARATOR); >- if (separatorIndex != -1) { >+ boolean isJarFile = separatorIndex != -1; >+ if (isJarFile) { > // internal or external jar (case 3, 4, or 5) > String jarPath = resourcePathString.substring(0, separatorIndex); > String relativePath = resourcePathString.substring(separatorIndex+1); >@@ -560,8 +576,16 @@ > } > if (index >= 0) { > int idx = projectIndexes[index]; >- if (idx != -1) { >- return (String) this.projectPaths.get(idx); >+ String projectPath = idx == -1 ? null : (String) this.projectPaths.get(idx); >+ if (projectPath != null) { >+ IJavaProject project =JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject(projectPath)); >+ if (isJarFile) { >+ return project.getPackageFragmentRoot(this.containerPaths[index]); >+ } >+ Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(this.containerPaths[index]+'/'+this.relativePaths[index]), false); >+ if (target instanceof IResource) { >+ return project.getPackageFragmentRoot((IResource)target); >+ } > } > } > return null; >Index: search/org/eclipse/jdt/internal/core/search/ExternalTypeNameMatch.java >=================================================================== >RCS file: search/org/eclipse/jdt/internal/core/search/ExternalTypeNameMatch.java >diff -N search/org/eclipse/jdt/internal/core/search/ExternalTypeNameMatch.java >--- search/org/eclipse/jdt/internal/core/search/ExternalTypeNameMatch.java 3 Oct 2006 11:32:05 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,56 +0,0 @@ >-/******************************************************************************* >- * 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.core.resources.IProject; >-import org.eclipse.core.resources.ResourcesPlugin; >-import org.eclipse.jdt.core.IJavaProject; >-import org.eclipse.jdt.core.IPackageFragmentRoot; >-import org.eclipse.jdt.core.JavaCore; >-import org.eclipse.jdt.core.search.IJavaSearchScope; >-import org.eclipse.jdt.core.search.TypeNameMatch; >- >-/** >- * Specific match collected while searching for all type names >- * when type belongs to an external resource. >- * >- * @since 3.3 >- */ >-public class ExternalTypeNameMatch extends TypeNameMatch { >- private String projectPath; >- private IPackageFragmentRoot root; >- >-public ExternalTypeNameMatch(int modifiers, char[] packageName, char[] typeName, char[][] enclosingTypeNames, String path, String project) { >- super(modifiers, packageName, typeName, enclosingTypeNames, path); >- this.projectPath = project; >-} >- >-/* (non-Javadoc) >- * @see org.eclipse.jdt.core.search.TypeNameMatch#getProject() >- */ >-protected IProject getProject() { >- return ResourcesPlugin.getWorkspace().getRoot().getProject(this.projectPath); >-} >- >-/* (non-Javadoc) >- * @see org.eclipse.jdt.core.search.TypeNameMatch#getPackageFragmentRoot() >- */ >-protected IPackageFragmentRoot getPackageFragmentRoot() { >- if (this.root == null) { >- int separatorIndex = getPath().indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR); >- String jarPath = getPath().substring(0, separatorIndex); >- IJavaProject javaProject = JavaCore.create(getProject()); >- if (javaProject == null) return null; // cannot initialize without a project >- this.root = javaProject.getPackageFragmentRoot(jarPath); >- } >- return root; >-} >-} >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.1 >diff -u -r1.1 TypeNameMatchRequestorWrapper.java >--- search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java 3 Oct 2006 11:32:05 -0000 1.1 >+++ search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java 6 Oct 2006 16:25:28 -0000 >@@ -10,12 +10,21 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.core.search; > >+import org.eclipse.core.runtime.Path; >+import org.eclipse.jdt.core.IClassFile; > import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IPackageFragment; >+import org.eclipse.jdt.core.IPackageFragmentRoot; >+import org.eclipse.jdt.core.IType; >+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; >+import org.eclipse.jdt.internal.core.PackageFragmentRoot; >+import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject; > > /** > * Wrapper used to link {@link IRestrictedAccessTypeRequestor} with {@link TypeNameRequestor}. >@@ -41,14 +50,24 @@ > * org.eclipse.core.runtime.IProgressMonitor monitor) }. > */ > public class TypeNameMatchRequestorWrapper implements IRestrictedAccessTypeRequestor { >- private TypeNameMatchRequestor requestor; >+ TypeNameMatchRequestor requestor; > private IJavaSearchScope scope; // scope is needed to retrieve project path for external resource >- private ICompilationUnit[] workingCopies; // working copies in which types may be found >+// private HandleFactory handleFactory; > >-public TypeNameMatchRequestorWrapper(TypeNameMatchRequestor requestor, IJavaSearchScope scope, ICompilationUnit[] workingCopies) { >+ /** >+ * Cache package fragment root information to optimize speed performance. >+ */ >+ private String lastPkgFragmentRootPath; >+ private IPackageFragmentRoot lastPkgFragmentRoot; >+ >+ /** >+ * Cache package handles to optimize memory. >+ */ >+ private HashtableOfArrayToObject packageHandles; >+ >+public TypeNameMatchRequestorWrapper(TypeNameMatchRequestor requestor, IJavaSearchScope scope) { > this.requestor = requestor; > this.scope = scope; >- this.workingCopies = workingCopies; > } > > /* (non-Javadoc) >@@ -56,24 +75,126 @@ > */ > 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.scope instanceof JavaSearchScope) { >- String projectPath = ((JavaSearchScope)this.scope).projectPathFor(path); >- if (projectPath == null) { >- if (this.workingCopies == null) { >- // Internal resource, project path won't be store as it can be computed from path >- TypeNameMatch match = new TypeNameMatch(modifiers, packageName, simpleTypeName, enclosingTypeNames, path); >- this.requestor.acceptTypeNameMatch(match); >- } else { >- // Internal working copy, project path won't be store as it can be computed from path >- WorkingCopiesTypeNameMatch match = new WorkingCopiesTypeNameMatch(modifiers, packageName, simpleTypeName, enclosingTypeNames, path, this.workingCopies); >- this.requestor.acceptTypeNameMatch(match); >- } >- } else { >- // External resource, store specific project path >- ExternalTypeNameMatch match = new ExternalTypeNameMatch(modifiers, packageName, simpleTypeName, enclosingTypeNames, path, projectPath); >- this.requestor.acceptTypeNameMatch(match); >+// 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)); > } >+ } catch (JavaModelException e) { >+ // skip > } > } > } >+private IType createTypeFromJar(String resourcePath, int separatorIndex) throws JavaModelException { >+ // path to a class file inside a jar >+ // Optimization: cache package fragment root handle and package handles >+ if (this.lastPkgFragmentRootPath == null >+ || this.lastPkgFragmentRootPath.length() > resourcePath.length() >+ || !resourcePath.startsWith(this.lastPkgFragmentRootPath)) { >+ String jarPath= resourcePath.substring(0, separatorIndex); >+ IPackageFragmentRoot root= ((JavaSearchScope)scope).packageFragmentRoot(resourcePath); >+ if (root == null) return null; >+ this.lastPkgFragmentRootPath= jarPath; >+ this.lastPkgFragmentRoot= root; >+ this.packageHandles= new HashtableOfArrayToObject(5); >+ } >+ // create handle >+ String classFilePath= resourcePath.substring(separatorIndex + 1); >+ String[] simpleNames = new Path(classFilePath).segments(); >+ String[] pkgName; >+ int length = simpleNames.length-1; >+ if (length > 0) { >+ pkgName = new String[length]; >+ System.arraycopy(simpleNames, 0, pkgName, 0, length); >+ } else { >+ pkgName = CharOperation.NO_STRINGS; >+ } >+ IPackageFragment pkgFragment= (IPackageFragment) this.packageHandles.get(pkgName); >+ if (pkgFragment == null) { >+ pkgFragment= ((PackageFragmentRoot) this.lastPkgFragmentRoot).getPackageFragment(pkgName); >+ this.packageHandles.put(pkgName, pkgFragment); >+ } >+ return pkgFragment.getClassFile(simpleNames[length]).getType(); >+} >+private IType createTypeFromPath(String resourcePath, String simpleTypeName, char[][] enclosingTypeNames) throws JavaModelException { >+ // path to a file in a directory >+ // Optimization: cache package fragment root handle and package handles >+ int rootPathLength = -1; >+ if (this.lastPkgFragmentRootPath == null >+ || !(resourcePath.startsWith(this.lastPkgFragmentRootPath) >+ && (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0 >+ && resourcePath.charAt(rootPathLength) == '/')) { >+ IPackageFragmentRoot root= ((JavaSearchScope)scope).packageFragmentRoot(resourcePath); >+ if (root == null) return null; >+ this.lastPkgFragmentRoot = root; >+ this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.getPath().toString(); >+ this.packageHandles = new HashtableOfArrayToObject(5); >+ } >+ // create handle >+ resourcePath = resourcePath.substring(this.lastPkgFragmentRootPath.length() + 1); >+ String[] simpleNames = new Path(resourcePath).segments(); >+ String[] pkgName; >+ int length = simpleNames.length-1; >+ if (length > 0) { >+ pkgName = new String[length]; >+ System.arraycopy(simpleNames, 0, pkgName, 0, length); >+ } else { >+ pkgName = CharOperation.NO_STRINGS; >+ } >+ IPackageFragment pkgFragment= (IPackageFragment) this.packageHandles.get(pkgName); >+ if (pkgFragment == null) { >+ pkgFragment= ((PackageFragmentRoot) this.lastPkgFragmentRoot).getPackageFragment(pkgName); >+ this.packageHandles.put(pkgName, pkgFragment); >+ } >+ String simpleName= simpleNames[length]; >+ if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(simpleName)) { >+ ICompilationUnit unit= pkgFragment.getCompilationUnit(simpleName); >+ int etnLength = enclosingTypeNames == null ? 0 : enclosingTypeNames.length; >+ IType type = (etnLength == 0) ? unit.getType(simpleTypeName) : unit.getType(new String(enclosingTypeNames[0])); >+ if (etnLength > 0) { >+ for (int i=1; i<etnLength; i++) { >+ type = type.getType(new String(enclosingTypeNames[i])); >+ } >+ type = type.getType(simpleTypeName); >+ } >+ return type; >+ } else { >+ IClassFile classFile= pkgFragment.getClassFile(simpleName); >+ return classFile.getType(); >+ } >+} > } >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.1 >diff -u -r1.1 TypeNameMatch.java >--- search/org/eclipse/jdt/core/search/TypeNameMatch.java 3 Oct 2006 11:32:05 -0000 1.1 >+++ search/org/eclipse/jdt/core/search/TypeNameMatch.java 6 Oct 2006 16:25:27 -0000 >@@ -10,141 +10,116 @@ > *******************************************************************************/ > package org.eclipse.jdt.core.search; > >-import org.eclipse.core.resources.IProject; >-import org.eclipse.core.resources.ResourcesPlugin; >-import org.eclipse.core.runtime.Path; >-import org.eclipse.jdt.core.ICompilationUnit; >-import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.IPackageFragmentRoot; > import org.eclipse.jdt.core.IType; >-import org.eclipse.jdt.core.JavaCore; > import org.eclipse.jdt.core.JavaModelException; >-import org.eclipse.jdt.core.compiler.CharOperation; > > /** >- * 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 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 >+ * <p> >+ * User can get type from this match using {@link #getType()} method. >+ * </p> > * <p> >- * User can get type from this match using {@link #resolvedType()} method. >- * </p><p> > * This class is not intended to be instantiated or subclassed by clients. > * </p> >+ * > * @see TypeNameMatchRequestor > * > * @since 3.3 > */ > public class TypeNameMatch { > >-//private IType type; >-private int modifiers; >-private char[] packageName; >-private char[] simpleTypeName; >-private char[][] enclosingTypeNames; >-private String path; >-//private boolean initialized; >+private IType type; >+ >+private int modifiers = -1; // store modifiers to avoid java model population > > /** > * Creates a new type name match. > */ >-public TypeNameMatch(int modifiers, char[] packageName, char[] typeName, char[][] enclosingTypeNames, String path) { >- this.modifiers = modifiers; >- this.packageName = packageName; >- this.simpleTypeName = typeName; >- this.enclosingTypeNames = enclosingTypeNames; >- this.path = path; >+public TypeNameMatch(IType type) { >+ this.type = type; > } > >-/** >- * Returns the enclosing type names (if any) of the type. >- * >- * @return the enclosing type names (if any) of the type >- */ >-public final char[][] getEnclosingTypeNames() { >- return enclosingTypeNames; >+public TypeNameMatch(IType type, int modifiers) { >+ this(type); >+ this.modifiers = modifiers; > } > > /** >- * Fully qualified name of type (e.g. package name + '.' enclosing type names + '.' simple name) >+ * Returns the java model type corresponding to fully qualified type name (based >+ * on package, enclosing types and simple name). > * >- * @return Fully qualified type name of the type >+ * @return the java model type >+ * @throws JavaModelException >+ * happens when type stored information are not valid > */ >-public final char[] getFullyQualifiedName() { >- return CharOperation.concat(this.packageName, getTypeContainerName(), '.'); >+public IType getType() throws JavaModelException { >+ return this.type; > } > >-/** >- * Returns the modifiers of the type. >+/* >+ * (non-Javadoc) > * >- * @return the type modifiers >+ * @see java.lang.Object#toString() > */ >-public final int getModifiers() { >- return modifiers; >+public String toString() { >+ return this.type.toString(); > } > >-/* >- * Specific package fragment root while resolving type >- */ >-protected IPackageFragmentRoot getPackageFragmentRoot() { >- return null; >+public IPackageFragmentRoot getPackageFragmentRoot() { >+ return (IPackageFragmentRoot) this.type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); > } > > /** >- * Returns the package name of the type. >+ * Fully qualified name of type (e.g. package name + '.' enclosing type names + >+ * '.' simple name) > * >- * @return the package name >+ * @return Fully qualified type name of the type > */ >-public final char[] getPackageName() { >- return packageName; >+public String getFullyQualifiedName() { >+ return this.type.getFullyQualifiedName('.'); > } > > /** >- * Returns the full path of the resource. >- * This path may include the jar file path following by '|' separator >- * if the type is a binary included in a jar. >+ * Fully qualified name of type (e.g. package name + '.' enclosing type names + >+ * '.' simple name) > * >- * @return the full path of the resource >+ * @return Fully qualified type name of the type > */ >-public final String getPath() { >- return path; >+public String getTypeQualifiedName() { >+ return this.type.getTypeQualifiedName('.'); > } > >-/* >- * Project used to resolve type >+/** >+ * Returns the modifiers of the type. >+ * >+ * @return the type modifiers > */ >-protected IProject getProject() { >- return ResourcesPlugin.getWorkspace().getRoot().getProject(new Path(this.path).segment(0)); >+public int getModifiers() { >+ return this.modifiers; > } > > /** >- * Returns the name of the type. >+ * Returns the package name of the type. > * >- * @return the type name >+ * @return the package name > */ >-public final char[] getSimpleTypeName() { >- return simpleTypeName; >+public String getPackageName() { >+ return this.type.getPackageFragment().getElementName(); > } > > /** >- * Returns the java model type corresponding to fully qualified type name >- * (based on package, enclosing types and simple name). >+ * Returns the name of the type. > * >- * @return the java model type >- * @throws JavaModelException happens when type stored information are not valid >+ * @return the type name > */ >-public IType resolvedType() throws JavaModelException { >- IJavaProject javaProject = JavaCore.create(getProject()); >- if (javaProject == null) return null; // cannot initialize without a project >- return javaProject.findType(new String(packageName), new String(getTypeContainerName()), getPackageFragmentRoot(), getWorkingCopies(), null); >+public String getSimpleTypeName() { >+ return this.type.getElementName(); > } > > /** >@@ -152,21 +127,12 @@ > * > * @return Name of the type container > */ >-public final char[] getTypeContainerName() { >- return this.enclosingTypeNames == null ? this.simpleTypeName : CharOperation.concatWith(this.enclosingTypeNames, this.simpleTypeName, '.'); >-} >- >-/* >- * Working copies to look in while resolving type >- */ >-protected ICompilationUnit[] getWorkingCopies() { >- return null; >-} >- >-/* (non-Javadoc) >- * @see java.lang.Object#toString() >- */ >-public String toString() { >- return new String(getFullyQualifiedName()); >+public String getTypeContainerName() { >+ IType outerType = this.type.getDeclaringType(); >+ if (outerType != null) { >+ return outerType.getFullyQualifiedName('.'); >+ } else { >+ return this.type.getPackageFragment().getElementName(); >+ } > } > } >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.132 >diff -u -r1.132 SearchEngine.java >--- search/org/eclipse/jdt/core/search/SearchEngine.java 3 Oct 2006 11:32:36 -0000 1.132 >+++ search/org/eclipse/jdt/core/search/SearchEngine.java 6 Oct 2006 16:25:27 -0000 >@@ -765,7 +765,7 @@ > int waitingPolicy, > IProgressMonitor progressMonitor) throws JavaModelException { > >- TypeNameMatchRequestorWrapper requestorWrapper = new TypeNameMatchRequestorWrapper(nameMatchRequestor, scope, this.basicEngine.getWorkingCopies()); >+ TypeNameMatchRequestorWrapper requestorWrapper = new TypeNameMatchRequestorWrapper(nameMatchRequestor, scope); > this.basicEngine.searchAllTypeNames(packageName, packageMatchRule, typeName, typeMatchRule, searchFor, scope, requestorWrapper, waitingPolicy, progressMonitor); > } > >Index: model/org/eclipse/jdt/internal/core/JavaProject.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v >retrieving revision 1.373 >diff -u -r1.373 JavaProject.java >--- model/org/eclipse/jdt/internal/core/JavaProject.java 3 Oct 2006 11:32:05 -0000 1.373 >+++ model/org/eclipse/jdt/internal/core/JavaProject.java 6 Oct 2006 16:25:25 -0000 >@@ -1218,15 +1218,14 @@ > /* > * Internal findType with instanciated name lookup > */ >- IType findType(String packageName, String typeQualifiedName, IPackageFragmentRoot root, NameLookup lookup, boolean considerSecondaryTypes, IProgressMonitor progressMonitor) throws JavaModelException { >+ IType findType(String packageName, String typeQualifiedName, NameLookup lookup, boolean considerSecondaryTypes, IProgressMonitor progressMonitor) throws JavaModelException { > NameLookup.Answer answer = lookup.findType( > typeQualifiedName, > packageName, >- root, > false, > NameLookup.ACCEPT_ALL, >- considerSecondaryTypes, // wait for indexes (in case we need to consider secondary types) >- true, >+ considerSecondaryTypes, >+ true, // wait for indexes (in case we need to consider secondary types) > false/*don't check restrictions*/, > progressMonitor); > return answer == null ? null : answer.type; >@@ -1239,9 +1238,8 @@ > return findType( > packageName, > typeQualifiedName, >- null, >- lookup, // do not consider secondary types >- false, >+ lookup, >+ false, // do not consider secondary types > null); > } > >@@ -1253,23 +1251,8 @@ > return findType( > packageName, > typeQualifiedName, >- null, >- lookup, // consider secondary types >- true, >- progressMonitor); >- } >- >- /** >- * @see IJavaProject#findType(String, String, IPackageFragmentRoot, ICompilationUnit[], IProgressMonitor) >- */ >- public IType findType(String packageName, String typeQualifiedName, IPackageFragmentRoot root, ICompilationUnit[] workingCopies, IProgressMonitor progressMonitor) throws JavaModelException { >- NameLookup lookup = newNameLookup(workingCopies); >- return findType( >- packageName, >- typeQualifiedName, >- root, >- lookup, // consider secondary types >- true, >+ lookup, >+ true, // consider secondary types > progressMonitor); > } > >Index: model/org/eclipse/jdt/internal/core/NameLookup.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java,v >retrieving revision 1.111 >diff -u -r1.111 NameLookup.java >--- model/org/eclipse/jdt/internal/core/NameLookup.java 3 Oct 2006 11:32:05 -0000 1.111 >+++ model/org/eclipse/jdt/internal/core/NameLookup.java 6 Oct 2006 16:25:26 -0000 >@@ -571,7 +571,6 @@ > public Answer findType(String typeName, String packageName, boolean partialMatch, int acceptFlags, boolean checkRestrictions) { > return findType(typeName, > packageName, >- null, > partialMatch, > acceptFlags, > true/* consider secondary types */, >@@ -586,11 +585,10 @@ > public Answer findType( > String typeName, > String packageName, >- IPackageFragmentRoot root, > boolean partialMatch, > int acceptFlags, > boolean considerSecondaryTypes, >- boolean waitForIndexes, >+ boolean waitForIndexes, > boolean checkRestrictions, > IProgressMonitor monitor) { > if (packageName == null || packageName.length() == 0) { >@@ -612,10 +610,6 @@ > IJavaProject javaProject = null; > Answer suggestedAnswer = null; > for (int i= 0; i < length; i++) { >- if (root != null && !packages[i].getParent().equals(root)) { >- // filter package which are not in same root >- continue; >- } > type = findType(typeName, packages[i], partialMatch, acceptFlags); > if (type != null) { > AccessRestriction accessRestriction = null; >@@ -770,7 +764,7 @@ > packageName= name.substring(0, index); > className= name.substring(index + 1); > } >- return findType(className, packageName, null, partialMatch, acceptFlags, considerSecondaryTypes, waitForIndexes, checkRestrictions, monitor); >+ return findType(className, packageName, partialMatch, acceptFlags, considerSecondaryTypes, waitForIndexes, checkRestrictions, monitor); > } > > private IType getMemberType(IType type, String name, int dot) { >Index: model/org/eclipse/jdt/core/IJavaProject.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaProject.java,v >retrieving revision 1.88 >diff -u -r1.88 IJavaProject.java >--- model/org/eclipse/jdt/core/IJavaProject.java 3 Oct 2006 11:32:05 -0000 1.88 >+++ model/org/eclipse/jdt/core/IJavaProject.java 6 Oct 2006 16:25:20 -0000 >@@ -344,34 +344,6 @@ > * @since 3.2 > */ > IType findType(String packageName, String typeQualifiedName, WorkingCopyOwner owner, IProgressMonitor progressMonitor) throws JavaModelException; >- /** >- * Returns the first type found following this project's classpath >- * with the given package name and type qualified name >- * or <code>null</code> if none is found. >- * The package name is a dot-separated name. >- * The type qualified name is also a dot-separated name. For example, >- * a class B defined as a member type of a class A should have the >- * type qualified name "A.B". >- * The returned type may be a part of one of the given compilation units. >- * If a package fragment root is specified, then the returned type, if any, >- * will belong to a package fragment which parent is the given package fragment root. >- * >- * @param packageName the given package name >- * @param typeQualifiedName the given type qualified name >- * @param root Package fragment root which must include the search type. >- * May be <code>null</code>. >- * @param units Compilation units returned may be a part of. >- * May be <code>null</code>. >- * @param progressMonitor the progress monitor to report progress to, >- * or <code>null</code> if no progress monitor is provided >- * @exception JavaModelException if this project does not exist or if an >- * exception occurs while accessing its corresponding resource >- * @return the first type found following this project's classpath >- * with the given fully qualified name or <code>null</code> if none is found >- * @see IType#getFullyQualifiedName(char) >- * @since 3.3 >- */ >- IType findType(String packageName, String typeQualifiedName, IPackageFragmentRoot root, ICompilationUnit[] units, IProgressMonitor progressMonitor) throws JavaModelException; > > /** > * Returns all of the existing package fragment roots that exist >Index: model/org/eclipse/jdt/core/JavaCore.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java,v >retrieving revision 1.553 >diff -u -r1.553 JavaCore.java >--- model/org/eclipse/jdt/core/JavaCore.java 3 Oct 2006 15:18:46 -0000 1.553 >+++ model/org/eclipse/jdt/core/JavaCore.java 6 Oct 2006 16:25:23 -0000 >@@ -1322,31 +1322,6 @@ > return JavaModelManager.create(file, null/*unknown java project*/); > } > /** >- * Returns the Java element corresponding to the given file, its project being the given >- * project. >- * Returns <code>null</code> if unable to associate the given file >- * with a Java element. >- * >- * <p>The file must be one of:<ul> >- * <li>a file with one of the {@link JavaCore#getJavaLikeExtensions() >- * Java-like extensions} - the element returned is the corresponding <code>ICompilationUnit</code></li> >- * <li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li> >- * <li>a <code>.jar</code> file - the element returned is the corresponding <code>IPackageFragmentRoot</code></li> >- * </ul> >- * <p> >- * Creating a Java element has the side effect of creating and opening all of the >- * element's parents if they are not yet open. >- * >- * @param file the given file >- * @return the Java element corresponding to the given file, or >- * <code>null</code> if unable to associate the given file >- * with a Java element >- * @since 3.3 >- */ >- public static IJavaElement create(IFile file, IJavaProject project) { >- return JavaModelManager.create(file, project); >- } >- /** > * Returns the package fragment or package fragment root corresponding to the given folder, or > * <code>null</code> if unable to associate the given folder with a Java element. > * <p> >@@ -1408,6 +1383,34 @@ > return JavaModelManager.create(resource, null/*unknown java project*/); > } > /** >+ * Returns the Java element corresponding to the given file, its project being the given >+ * project. Returns <code>null</code> if unable to associate the given resource >+ * with a Java element. >+ *<p> >+ * The resource must be one of:<ul> >+ * <li>a project - the element returned is the corresponding <code>IJavaProject</code></li> >+ * <li>a file with one of the {@link JavaCore#getJavaLikeExtensions() >+ * Java-like extensions} - the element returned is the corresponding <code>ICompilationUnit</code></li> >+ * <li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li> >+ * <li>a <code>.jar</code> file - the element returned is the corresponding <code>IPackageFragmentRoot</code></li> >+ * <li>a folder - the element returned is the corresponding <code>IPackageFragmentRoot</code> >+ * or <code>IPackageFragment</code></li> >+ * <li>the workspace root resource - the element returned is the <code>IJavaModel</code></li> >+ * </ul> >+ * <p> >+ * Creating a Java element has the side effect of creating and opening all of the >+ * element's parents if they are not yet open. >+ * >+ * @param resource the given resource >+ * @return the Java element corresponding to the given file, or >+ * <code>null</code> if unable to associate the given file >+ * with a Java element >+ * @since 3.3 >+ */ >+ public static IJavaElement create(IResource resource, IJavaProject project) { >+ return JavaModelManager.create(resource, project); >+ } >+ /** > * Returns the Java model. > * > * @param root the given root >Index: buildnotes_jdt-core.html >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/buildnotes_jdt-core.html,v >retrieving revision 1.5442 >diff -u -r1.5442 buildnotes_jdt-core.html >--- buildnotes_jdt-core.html 5 Oct 2006 19:15:43 -0000 1.5442 >+++ buildnotes_jdt-core.html 6 Oct 2006 16:25:20 -0000 >@@ -52,6 +52,19 @@ > <h2>What's new in this drop</h2> > <ul> > <li>Raw type reference are now reported by default. See bug <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=159456">159456</a>.</li> >+<li>API of <code>TypeNameMatch</code> has been changed to improve memory consumption performance. >+It now creates IType handle while accepting the type information from indexes and stores their modifiers >+to avoid java element opening while getting this piece of information.<br> >+Note that there's no Java Model initialization nor populating while creating handles...<br> >+Note also that previously added API method on IJavaProject has been removed: >+<pre> >+IType findType(String packageName, >+ String typeQualifiedName, >+ IPackageFragmentRoot root, >+ ICompilationUnit[] units, >+ IProgressMonitor progressMonitor) throws JavaModelException; >+</pre> >+</li> > </ul> > > <h3>Problem Reports Fixed</h3> >@@ -138,44 +151,6 @@ > This should avoid to have too many similar <code>searchAllTypeNames</code> available methods... > </li> > <li> >-Added new <code>IJavaProject</code> API method to let clients finding types in a project with additional working copies >-and in a specific package fragment root: >-<pre> >-/** >- * Returns the first type found following this project's classpath >- * with the given package name and type qualified name >- * or <code>null</code> if none is found. >- * The package name is a dot-separated name. >- * The type qualified name is also a dot-separated name. For example, >- * a class B defined as a member type of a class A should have the >- * type qualified name "A.B". >- * The returned type may be a part of one of the given compilation units. >- * If a package fragment root is specified, then the returned type, if any, >- * will belong to a package fragment which parent is the given package fragment root. >- * >- * @param packageName the given package name >- * @param typeQualifiedName the given type qualified name >- * @param root Package fragment root which must include the search type. >- * May be <code>null</code>. >- * @param units Compilation units returned may be a part of. >- * May be <code>null</code>. >- * @param progressMonitor the progress monitor to report progress to, >- * or <code>null</code> if no progress monitor is provided >- * @exception JavaModelException if this project does not exist or if an >- * exception occurs while accessing its corresponding resource >- * @return the first type found following this project's classpath >- * with the given fully qualified name or <code>null</code> if none is found >- * @see IType#getFullyQualifiedName(char) >- * @since 3.3 >- */ >-IType findType(String packageName, >- String typeQualifiedName, >- IPackageFragmentRoot root, >- ICompilationUnit[] units, >- IProgressMonitor progressMonitor) throws JavaModelException; >-</pre> >-</li> >-<li> > Added new <code>JavaCore</code> API method to create a java element from an <code>IFile</code> > using a specific project: > <pre>
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 148380
:
50710
|
50713
|
50714
|
51323
| 51563