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 321 Details for
Bug 9240
Search finds deleted classes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
AllTypesCache.java
AllTypesCache.java (text/plain), 5.35 KB, created by
Martin Aeschlimann
on 2002-02-07 10:25:24 EST
(
hide
)
Description:
AllTypesCache.java
Filename:
MIME Type:
Creator:
Martin Aeschlimann
Created:
2002-02-07 10:25:24 EST
Size:
5.35 KB
patch
obsolete
>/* > * (c) Copyright IBM Corp. 2000, 2001. > * All Rights Reserved. > */ >package org.eclipse.jdt.internal.corext.util; > >import java.util.ArrayList; >import java.util.Collection; >import java.util.Iterator; > >import org.eclipse.core.resources.ResourcesPlugin; >import org.eclipse.core.runtime.IProgressMonitor; > >import org.eclipse.jdt.core.ElementChangedEvent; >import org.eclipse.jdt.core.ICompilationUnit; >import org.eclipse.jdt.core.IElementChangedListener; >import org.eclipse.jdt.core.IJavaElement; >import org.eclipse.jdt.core.IJavaElementDelta; >import org.eclipse.jdt.core.JavaCore; >import org.eclipse.jdt.core.JavaModelException; >import org.eclipse.jdt.core.search.IJavaSearchConstants; >import org.eclipse.jdt.core.search.IJavaSearchScope; >import org.eclipse.jdt.core.search.SearchEngine; > >import org.eclipse.jdt.internal.core.search.JavaWorkspaceScope; >import org.eclipse.jdt.internal.ui.util.TypeInfo; >import org.eclipse.jdt.internal.ui.util.TypeInfoRequestor; > >/** > * Manages a search cache for types in the workspace. Instead of returning objects of type <code>IType</code> > * the methods of this class returns a list of the lightweight objects <code>TypeInfo</code>. > */ >public class AllTypesCache { > > private static ArrayList fgTypeCache= null; > private static int fgNumberOfCacheFlushes= 0; > > /** > * Returns all types in the given scope. > * @param kind IJavaSearchConstants.CLASS, IJavaSearchConstants.INTERFACE > * or IJavaSearchConstants.TYPE > * @param typesFound The resulting <code>TypeInfo</code> elements are added to this collection > */ > public static synchronized void getTypes(IJavaSearchScope scope, int kind, IProgressMonitor monitor, Collection typesFound) throws JavaModelException { > > boolean isWorkspaceScope= (scope instanceof JavaWorkspaceScope); // XXX: use of internal class: bug 9179 > > if (fgTypeCache == null) { > if (!isWorkspaceScope) { > // don't build up the cache, perform a bare search > doSearchTypes(scope, kind, monitor, typesFound); > return; > } > ArrayList searchResult= new ArrayList(400); > doSearchTypes(scope, IJavaSearchConstants.TYPE, monitor, searchResult); > if (monitor != null && monitor.isCanceled()) { > return; > } > monitor= null; // prevents duplicated invocation of monitor.done > fgTypeCache= searchResult; > JavaCore.addElementChangedListener(new TypeCacheDeltaListener()); > } > > boolean isBoth= (kind == IJavaSearchConstants.TYPE); > boolean isInterface= (kind == IJavaSearchConstants.INTERFACE); > > for (Iterator iter= fgTypeCache.iterator(); iter.hasNext();) { > TypeInfo info= (TypeInfo) iter.next(); > if (isWorkspaceScope || info.isEnclosed(scope)) { > if (isBoth || (isInterface == info.isInterface())) { > typesFound.add(info); > } > } > } > if (monitor != null) { > monitor.done(); > } > > } > > > private static void doSearchTypes(IJavaSearchScope scope, int style, IProgressMonitor monitor, Collection typesFound) throws JavaModelException { > new SearchEngine().searchAllTypeNames(ResourcesPlugin.getWorkspace(), > null, > null, > IJavaSearchConstants.PATTERN_MATCH, > IJavaSearchConstants.CASE_INSENSITIVE, > style, > scope, > new TypeInfoRequestor(typesFound), > IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, > monitor); > } > > private static class TypeCacheDeltaListener implements IElementChangedListener { > > /* > * @see IElementChangedListener#elementChanged > */ > public void elementChanged(ElementChangedEvent event) { > boolean needsFlushing= processDelta(event.getDelta()); > if (needsFlushing) { > fgTypeCache= null; > fgNumberOfCacheFlushes++; > JavaCore.removeElementChangedListener(this); // it's ok to remove listener while delta processing > } > } > > /* > * returns true if the cache needs to be flushed > */ > private boolean processDelta(IJavaElementDelta delta) { > IJavaElement elem= delta.getElement(); > boolean isAddedOrRemoved= (delta.getKind() != IJavaElementDelta.CHANGED) > || (delta.getFlags() & (IJavaElementDelta.F_ADDED_TO_CLASSPATH | IJavaElementDelta.F_REMOVED_FROM_CLASSPATH)) != 0; > > switch (elem.getElementType()) { > case IJavaElement.JAVA_MODEL: > case IJavaElement.JAVA_PROJECT: > case IJavaElement.PACKAGE_FRAGMENT_ROOT: > case IJavaElement.PACKAGE_FRAGMENT: > case IJavaElement.CLASS_FILE: > case IJavaElement.TYPE: // type children can be inner classes > if (isAddedOrRemoved) { > return true; > } > return processChildrenDelta(delta); > case IJavaElement.COMPILATION_UNIT: // content change means refresh from local > if (((ICompilationUnit) elem).isWorkingCopy()) { > return false; > } > if (isAddedOrRemoved || (delta.getFlags() & IJavaElementDelta.F_CONTENT) != 0) { > return true; > } > return processChildrenDelta(delta); > default: > // fields, methods, imports ect > return false; > } > } > > private boolean processChildrenDelta(IJavaElementDelta delta) { > IJavaElementDelta[] children= delta.getAffectedChildren(); > for (int i= 0; i < children.length; i++) { > if (processDelta(children[i])) { > return true; > } > } > return false; > } > } > > > /** > * Gets the number of times the cache was flushed. Used for testing. > * @return Returns a int > */ > public static int getNumberOfCacheFlushes() { > return fgNumberOfCacheFlushes; > } > >}
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 Raw
Actions:
View
Attachments on
bug 9240
:
320
| 321