? java/nbproject/private Index: utilities/jumpto/manifest.mf =================================================================== RCS file: /cvs/utilities/jumpto/manifest.mf,v retrieving revision 1.5 diff -B -b -u -r1.5 manifest.mf --- utilities/jumpto/manifest.mf 9 Nov 2007 17:59:19 -0000 1.5 +++ utilities/jumpto/manifest.mf 16 Jan 2008 13:20:06 -0000 @@ -2,5 +2,5 @@ OpenIDE-Module: org.netbeans.modules.jumpto/1 OpenIDE-Module-Layer: org/netbeans/modules/jumpto/resources/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jumpto/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 1.4 +OpenIDE-Module-Specification-Version: 1.5 AutoUpdate-Show-In-Client: false Index: utilities/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java =================================================================== RCS file: /cvs/utilities/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java,v retrieving revision 1.13 diff -B -b -u -r1.13 GoToTypeAction.java --- utilities/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java 12 Oct 2007 07:57:55 -0000 1.13 +++ utilities/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java 16 Jan 2008 13:20:06 -0000 @@ -412,27 +412,21 @@ private List getTypeNames(String text) { // TODO: Search twice, first for current project, then for all projects List items; - if (typeProviders.size() == 1) { - items = (List) typeProviders.iterator().next().getTypeNames(null, text, nameKind); - } else { // Multiple providers: merge results items = new ArrayList(128); + String[] message = new String[1]; + TypeProvider.Context context = TypeProviderAccessor.DEFAULT.createContext(null, text, nameKind); + TypeProvider.Result result = TypeProviderAccessor.DEFAULT.createResult(items, message); for (TypeProvider provider : typeProviders) { if (isCanceled) { return null; } - List list = provider.getTypeNames(null, text, nameKind); - if (list != null) { - items.addAll(list); + provider.computeTypeNames(context, result); } - } - - } - if ( !isCanceled ) { //time = System.currentTimeMillis(); Collections.sort(items, new TypeComparator()); - + if (message[0] != null) System.err.println(message[0]); //sort += System.currentTimeMillis() - time; //LOGGER.fine("PERF - " + " GSS: " + gss + " GSB " + gsb + " CP: " + cp + " SFB: " + sfb + " GTN: " + gtn + " ADD: " + add + " SORT: " + sort ); return items; Index: utilities/jumpto/src/org/netbeans/modules/jumpto/type/TypeProviderAccessor.java =================================================================== RCS file: utilities/jumpto/src/org/netbeans/modules/jumpto/type/TypeProviderAccessor.java diff -N utilities/jumpto/src/org/netbeans/modules/jumpto/type/TypeProviderAccessor.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ utilities/jumpto/src/org/netbeans/modules/jumpto/type/TypeProviderAccessor.java 16 Jan 2008 13:20:06 -0000 @@ -0,0 +1,67 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ +package org.netbeans.modules.jumpto.type; + +import java.util.List; +import org.netbeans.api.project.Project; +import org.netbeans.spi.jumpto.type.SearchType; +import org.netbeans.spi.jumpto.type.TypeDescriptor; +import static org.netbeans.spi.jumpto.type.TypeProvider.*; + +/** + * Accessor class. + * + * @author Pavel Flaska + */ +public abstract class TypeProviderAccessor { + + public static TypeProviderAccessor DEFAULT; + + static { + try { + Class.forName(Context.class.getName(), true, Context.class.getClassLoader()); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + protected abstract Context createContext(Project p, String text, SearchType t); + + protected abstract Result createResult(List result, String[] message); +} Index: utilities/jumpto/src/org/netbeans/spi/jumpto/type/TypeProvider.java =================================================================== RCS file: /cvs/utilities/jumpto/src/org/netbeans/spi/jumpto/type/TypeProvider.java,v retrieving revision 1.3 diff -B -b -u -r1.3 TypeProvider.java --- utilities/jumpto/src/org/netbeans/spi/jumpto/type/TypeProvider.java 26 Sep 2007 21:05:42 -0000 1.3 +++ utilities/jumpto/src/org/netbeans/spi/jumpto/type/TypeProvider.java 16 Jan 2008 13:20:06 -0000 @@ -42,8 +42,8 @@ package org.netbeans.spi.jumpto.type; import java.util.List; -import org.netbeans.spi.jumpto.type.TypeDescriptor; import org.netbeans.api.project.Project; +import org.netbeans.modules.jumpto.type.TypeProviderAccessor; /** * A Type Provider participates in the Goto Type dialog by providing TypeDescriptors, @@ -77,7 +77,7 @@ String getDisplayName(); /** - * Provide a list of TypeDescriptors that match the given search text for the given + * Compute a list of TypeDescriptors that match the given search text for the given * search type. This might be a slow operation, and the infrastructure may end * up calling {@link #cancel} on the same type provider during the operation, in which * case the method can return incomplete results. If there is a "current project", @@ -92,13 +92,10 @@ * result. There is an explicit {@link #cleanup} call that the Go To Type dialog * will make at the end of the dialog interaction, which can be used to clean up the cache. * - * @param project If not null, limit the type search to the given project. - * @param text The text to be used for the search; e.g. when type=SearchType.PREFIX, - * text is the prefix that all returned types should start with. - * @param type A type of search to be performed, such as prefix, regexp or camel case. - * @return A collection of TypeDescriptors that match the given search criteria + * @param context search context containg search text and type, optionally project + * @param result filled with type descriptors and optional message */ - List getTypeNames(Project project, String text, SearchType type); + void computeTypeNames(Context context, Result result); /** * Cancel the current operation, if possible. This might be called if the user @@ -116,4 +113,108 @@ * search is simply a narrower search, it can just filter the previous result. */ void cleanup(); + + + /** + * Represents search context. + * Contains search type (such as prefix, regexp), search text and + * optionally project where to search. + * + * @since 1.5 + */ + public static final class Context extends Object { + private final Project project; + private final String text; + private final SearchType type; + + static { + TypeProviderAccessor.DEFAULT = new TypeProviderAccessor() { + @Override + protected Context createContext(Project p, String text, SearchType t) { + return new Context(p, text, t); + } + + @Override + protected Result createResult(List result, String[] message) { + return new Result(result, message); + } + }; + } + + Context(Project project, String text, SearchType type) { + this.project = project; + this.text = text; + this.type = type; + } + + /** + * Return project representing scope of search, if null, the search is not + * limited. + * + * @return project If not null, the type search is limited to the given project. + */ + public Project getProject() { return project; } + + /** + * Return the text used for search. + * + * @return The text used for the search; e.g. when getSearchType() == SearchType.PREFIX, + * text is the prefix that all returned types should start with. + */ + public String getText() { return text; } + + /** + * Return the type of search. + * + * @return Type of search performed, such as prefix, regexp or camel case. + */ + public SearchType getSearchType() { return type; } + } + + /** + * Represents a collection of TypeDescriptors that match + * the given search criteria. Moreover, it can contain message + * for the user, such as an incomplete search result. + * + * @since 1.5 + */ + public static final class Result extends Object { + + private List result; + private String[] message; + + Result(List result, String[] message) { + this.result = result; + this.message = message; + } + + /** + * Optional message. It can inform the user about result, e.g. + * that result can be incomplete etc. + * + * @param msg message + */ + public void setMessage(String msg) { + message[0] = msg; + } + + /** + * Adds result descriptor. + * + * @param typeDescriptor type descriptor to be added to result + */ + public void addResult(TypeDescriptor typeDescriptor) { + result.add(typeDescriptor); + } + + /** + * Adds list of result descriptors. + * + * @param typeDescriptor type descriptor to be added to result + */ + public void addResult(List typeDescriptor) { + result.addAll(typeDescriptor); + } + } + } Index: ruby/gsf/src/org/netbeans/modules/gsf/GsfTypeProvider.java =================================================================== RCS file: /cvs/ruby/gsf/src/org/netbeans/modules/gsf/GsfTypeProvider.java,v retrieving revision 1.4 diff -B -b -u -r1.4 GsfTypeProvider.java --- ruby/gsf/src/org/netbeans/modules/gsf/GsfTypeProvider.java 30 Oct 2007 14:41:35 -0000 1.4 +++ ruby/gsf/src/org/netbeans/modules/gsf/GsfTypeProvider.java 16 Jan 2008 13:20:06 -0000 @@ -46,7 +46,6 @@ import java.util.Collections; import java.util.EnumSet; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.logging.Logger; import javax.swing.Icon; @@ -204,7 +203,9 @@ //@Override - public List getTypeNames(Project project, String text, SearchType nameKind) { + public void computeTypeNames(Context context, Result res) { + String text = context.getText(); + SearchType nameKind = context.getSearchType(); long time; @@ -227,7 +228,7 @@ LOGGER.fine("GoToTypeAction.getTypeNames created ClasspathInfo for source: " + FileUtil.getFileDisplayName(roots[i])+"\n"); // if ( isCanceled ) { if ( isCancelled ) { - return null; + return; } else { sources.add( new CacheItem( roots[i], ci, false ) ); @@ -268,7 +269,7 @@ cache = sources; } else { - return null; + return; } } @@ -312,7 +313,7 @@ //Set> names = ci.classpathInfo.getClassIndex().getDeclaredTypes(textForQuery, indexNameKind, EnumSet.of( ci.isBinary ? ClassIndex.SearchScope.DEPENDENCIES : ClassIndex.SearchScope.SOURCE )); // if ( isCanceled ) { if ( isCancelled ) { - return null; + return; } gtn += System.currentTimeMillis() - time; @@ -329,7 +330,7 @@ // } // if ( isCanceled ) { if ( isCancelled ) { - return null; + return; } } add += System.currentTimeMillis() - time; @@ -341,10 +342,10 @@ // Collections.sort(types); sort += System.currentTimeMillis() - time; LOGGER.fine("PERF - " + " GSS: " + gss + " GSB " + gsb + " CP: " + cp + " SFB: " + sfb + " GTN: " + gtn + " ADD: " + add + " SORT: " + sort ); - return types; + res.addResult(types); } else { - return null; + return; } } Index: cnd/gotodeclaration/src/org/netbeans/modules/cnd/gotodeclaration/type/CppTypeProvider.java =================================================================== RCS file: /cvs/cnd/gotodeclaration/src/org/netbeans/modules/cnd/gotodeclaration/type/CppTypeProvider.java,v retrieving revision 1.7 diff -B -b -u -r1.7 CppTypeProvider.java --- cnd/gotodeclaration/src/org/netbeans/modules/cnd/gotodeclaration/type/CppTypeProvider.java 26 Dec 2007 19:24:49 -0000 1.7 +++ cnd/gotodeclaration/src/org/netbeans/modules/cnd/gotodeclaration/type/CppTypeProvider.java 16 Jan 2008 13:20:08 -0000 @@ -61,7 +61,11 @@ return NbBundle.getMessage(CppTypeProvider.class, "TYPE_PROVIDER_DISPLAY_NAME"); // NOI18N } - public List getTypeNames(Project project, String text, SearchType type) { +// public List getTypeNames(Project project, String text, SearchType type) { + public void computeTypeNames(Context context, Result res) { + Project project = context.getProject(); + String text = context.getText(); + SearchType type = context.getSearchType(); if( TRACE ) System.err.printf("CppTypeProvider.getTypeNames(%s, %s, %s)\n", project, text, type); @@ -69,7 +73,7 @@ NameMatcher comparator = NameMatcherFactory.createNameMatcher(text, type); if( comparator == null ) { - return Collections.emptyList(); + return; } if( project == null ) { @@ -88,7 +92,7 @@ processProjectLibs(csmProject, result, comparator, processedLibs); } } - return new ArrayList(result); + res.addResult(new ArrayList(result)); } } else { @@ -98,11 +102,8 @@ if( PROCESS_LIBRARIES ) { processProjectLibs(csmProject, result, comparator, new HashSet()); } - return new ArrayList(result); + res.addResult(new ArrayList(result)); } - - - return Collections.emptyList(); } public void cancel() { Index: java/sourceui/src/org/netbeans/modules/java/source/ui/JavaTypeProvider.java =================================================================== RCS file: /cvs/java/sourceui/src/org/netbeans/modules/java/source/ui/JavaTypeProvider.java,v retrieving revision 1.10 diff -B -b -u -r1.10 JavaTypeProvider.java --- java/sourceui/src/org/netbeans/modules/java/source/ui/JavaTypeProvider.java 15 Jan 2008 11:44:43 -0000 1.10 +++ java/sourceui/src/org/netbeans/modules/java/source/ui/JavaTypeProvider.java 16 Jan 2008 13:20:11 -0000 @@ -46,10 +46,8 @@ import org.netbeans.api.java.classpath.GlobalPathRegistryEvent; import org.netbeans.api.java.source.ClasspathInfo; import org.netbeans.spi.java.classpath.support.ClassPathSupport; -import java.util.ArrayList; import java.util.EnumSet; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.logging.Logger; import javax.lang.model.element.TypeElement; @@ -63,6 +61,7 @@ import org.netbeans.api.java.source.CompilationController; import org.netbeans.api.java.source.ElementHandle; import org.netbeans.api.java.source.JavaSource; +import org.netbeans.api.java.source.SourceUtils; import org.netbeans.api.java.source.Task; import org.netbeans.api.java.source.ui.TypeElementFinder; import org.netbeans.api.project.FileOwnerQuery; @@ -73,7 +72,6 @@ import org.netbeans.modules.java.source.usages.RepositoryUpdater; import org.netbeans.spi.java.classpath.support.ClassPathSupport; import org.netbeans.spi.jumpto.type.SearchType; -import org.netbeans.spi.jumpto.type.TypeDescriptor; import org.netbeans.spi.jumpto.type.TypeProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileStateInvalidException; @@ -91,6 +89,7 @@ private final TypeElementFinder.Customizer customizer; private ClasspathInfo cpInfo; private GlobalPathRegistryListener pathListener; + private boolean cpChanged = false; public String name() { return "java"; // NOI18N @@ -116,11 +115,19 @@ pathListener = new GlobalPathRegistryListener() { public void pathsAdded(GlobalPathRegistryEvent event) { - cache = null; cpInfo = null; + if (cache != null) { + cache = null; + cpChanged = true; + } + cpInfo = null; } public void pathsRemoved(GlobalPathRegistryEvent event) { - cache = null; cpInfo = null; + if (cache != null) { + cache = null; + cpChanged = true; + } + cpInfo = null; } }; GlobalPathRegistry.getDefault().addGlobalPathRegistryListener(pathListener); @@ -148,9 +155,13 @@ // } // } - public List getTypeNames(Project project, String text, SearchType searchType) { + public void computeTypeNames(Context context, Result res) { + String text = context.getText(); + SearchType searchType = context.getSearchType(); + boolean hasBinaryOpen = Lookup.getDefault().lookup(BinaryElementOpen.class) != null; final ClassIndex.NameKind nameKind; + switch (searchType) { case EXACT_NAME: nameKind = ClassIndex.NameKind.SIMPLE_NAME; break; case CASE_INSENSITIVE_EXACT_NAME: nameKind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP; break; @@ -167,6 +178,14 @@ long cp, gss, gsb, sfb, gtn, add, sort; cp = gss = gsb = sfb = gtn = add = sort = 0; + // if scan is running set the message + if (cpChanged || SourceUtils.isScanInProgress()) { + res.setMessage("Result could be incomplete!"); + } else { + res.setMessage(null); + } + cpChanged = false; + if (cache == null) { Set sources = null; @@ -183,7 +202,7 @@ time = System.currentTimeMillis(); ClasspathInfo ci = ClasspathInfo.create( EMPTY_CLASSPATH, EMPTY_CLASSPATH, ClassPathSupport.createClassPath(root)); //create(roots[i]); if ( isCanceled ) { - return null; + return; } else { sources.add( new CacheItem( roots[i], ci, false ) ); @@ -202,7 +221,7 @@ for (int i = 0; i < roots.length; i++ ) { try { if ( isCanceled ) { - return null; + return; } time = System.currentTimeMillis(); if (!hasBinaryOpen) { @@ -223,7 +242,7 @@ } finally { if ( isCanceled ) { - return null; + return; } } } @@ -239,7 +258,7 @@ time = System.currentTimeMillis(); ClasspathInfo ci = ClasspathInfo.create(ClassPathSupport.createClassPath(bootRoots[i]), EMPTY_CLASSPATH, EMPTY_CLASSPATH); if ( isCanceled ) { - return null; + return; } else { sources.add( new CacheItem( bootRoots[i], ci, true ) ); @@ -252,7 +271,7 @@ time = System.currentTimeMillis(); ClasspathInfo ci = ClasspathInfo.create(EMPTY_CLASSPATH, ClassPathSupport.createClassPath(compileRoots[i]), EMPTY_CLASSPATH); if ( isCanceled ) { - return null; + return; } else { sources.add( new CacheItem( compileRoots[i], ci, true ) ); @@ -265,7 +284,7 @@ time = System.currentTimeMillis(); ClasspathInfo ci = ClasspathInfo.create(EMPTY_CLASSPATH, EMPTY_CLASSPATH, ClassPathSupport.createClassPath(sourceRoots[i])); if ( isCanceled ) { - return null; + return; } else { sources.add( new CacheItem( sourceRoots[i], ci, false ) ); @@ -279,13 +298,11 @@ cache = sources; } else { - return null; + return; } } - ArrayList types = new ArrayList(cache.size() * 20); - for(final CacheItem ci : cache) { time = System.currentTimeMillis(); @@ -306,6 +323,7 @@ if (customizer != null) { names = customizer.query(ci.classpathInfo, textForQuery, nameKind, EnumSet.of(ci.isBinary ? ClassIndex.SearchScope.DEPENDENCIES : ClassIndex.SearchScope.SOURCE)); } else { + @SuppressWarnings("unchecked") final Set>[] n = new Set[1]; JavaSource source = JavaSource.create(ci.classpathInfo, new FileObject[0]); try { @@ -322,7 +340,7 @@ } if ( isCanceled ) { - return null; + return; } gtn += System.currentTimeMillis() - time; @@ -334,10 +352,10 @@ // Removed because of bad performance To reenable see diff between 1.15 and 1.16 // if (defEntry.includes(convertToSourceName(name.getBinaryName()))) { JavaTypeDescription td = new JavaTypeDescription(ci, name ); - types.add(td); + res.addResult(td); // } if ( isCanceled ) { - return null; + return; } } add += System.currentTimeMillis() - time; @@ -349,10 +367,10 @@ // Collections.sort(types); sort += System.currentTimeMillis() - time; LOGGER.fine("PERF - " + " GSS: " + gss + " GSB " + gsb + " CP: " + cp + " SFB: " + sfb + " GTN: " + gtn + " ADD: " + add + " SORT: " + sort ); - return types; + return; } else { - return null; + return; } }