# This patch file was generated by NetBeans IDE # This patch can be applied using context Tools: Apply Diff Patch action on respective folder. # It uses platform neutral UTF-8 encoding. # Above lines and this line are ignored by the patching process. Index: java/sourceui/src/org/netbeans/api/java/source/ui/Bundle.properties --- java/sourceui/src/org/netbeans/api/java/source/ui/Bundle.properties Base (1.3) +++ java/sourceui/src/org/netbeans/api/java/source/ui/Bundle.properties Locally Modified (Based On 1.3) @@ -31,3 +31,7 @@ LBL_CancelAction=Cancel {0} MSG_WaitScan=Please wait, classpath scanning in progress... + +DLG_FindType=Find Type +AN_FindType=Find Type Dialog +AD_FindType=Opens Dialog, which permits for quick searching of Types Index: java/sourceui/src/org/netbeans/api/java/source/ui/TypeElementFinder.java --- java/sourceui/src/org/netbeans/api/java/source/ui/TypeElementFinder.java No Base Revision +++ java/sourceui/src/org/netbeans/api/java/source/ui/TypeElementFinder.java Locally New @@ -0,0 +1,99 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.api.java.source.ui; + +import java.util.Set; +import javax.lang.model.element.TypeElement; +import org.netbeans.api.java.source.ClassIndex; +import org.netbeans.api.java.source.ClasspathInfo; +import org.netbeans.api.java.source.ElementHandle; +import org.netbeans.api.jumpto.type.TypeBrowser; +import org.netbeans.modules.java.source.ui.JavaTypeDescription; +import org.netbeans.modules.java.source.ui.JavaTypeProvider; +import org.netbeans.spi.jumpto.type.TypeDescriptor; +import org.openide.util.NbBundle; + +/** + * Support for browsing of the Java types. Opens search dialog for the type name + * with possibility to filter possible results. + * + * @author Martin Adamek + */ +public final class TypeElementFinder { + + /** + * Searches for classes implementing/extending given superClass (in modal dialog). + * + * @param superClass handle of the super class + * @return found type or null if dialog was canceled + */ + public static ElementHandle find(ClasspathInfo cpInfo, final Customizer customizer) { + + // create filter only if client wants to customize the result + TypeBrowser.Filter typeBrowserFilter = null; + if (customizer != null) { + typeBrowserFilter = new TypeBrowser.Filter() { + public boolean accept(TypeDescriptor typeDescriptor) { + JavaTypeDescription javaTypeDesc = toJavaTypeDescription(typeDescriptor); + if (customizer != null && javaTypeDesc != null) { + return customizer.accept(javaTypeDesc.getHandle()); + } + return true; + } + }; + } + + TypeDescriptor typeDescriptor = TypeBrowser.browse( + NbBundle.getMessage(TypeElementFinder.class, "DLG_FindType"), + typeBrowserFilter, + new JavaTypeProvider(cpInfo, customizer == null ? null : customizer) + ); + JavaTypeDescription javaTypeDesc = toJavaTypeDescription(typeDescriptor); + + return javaTypeDesc == null ? null : javaTypeDesc.getHandle(); + } + + /** + * Customization of search scope and results + */ + public static interface Customizer { + + /** + * Set the scope of the search on particular classpath + */ + Set> query(ClasspathInfo classpathInfo, String textForQuery, ClassIndex.NameKind nameKind, Set searchScopes); + + /** + * Filter results directly in dialog + */ + boolean accept(ElementHandle typeHandle); + + } + + // private + + private static JavaTypeDescription toJavaTypeDescription(TypeDescriptor typeDescriptor) { + if (typeDescriptor instanceof JavaTypeDescription) { + return (JavaTypeDescription) typeDescriptor; + } + return null; + } + +} Index: java/sourceui/src/org/netbeans/modules/java/source/ui/JavaTypeDescription.java --- java/sourceui/src/org/netbeans/modules/java/source/ui/JavaTypeDescription.java Base (1.2) +++ java/sourceui/src/org/netbeans/modules/java/source/ui/JavaTypeDescription.java Locally Modified (Based On 1.2) @@ -145,6 +145,10 @@ return cacheItem.getProjectIcon(); } + public ElementHandle getHandle() { + return handle; + } + private void init() { final String typeName = this.handle.getBinaryName(); int lastDot = typeName.lastIndexOf('.'); // NOI18N Index: java/sourceui/src/org/netbeans/modules/java/source/ui/JavaTypeProvider.java --- java/sourceui/src/org/netbeans/modules/java/source/ui/JavaTypeProvider.java Base (1.2) +++ java/sourceui/src/org/netbeans/modules/java/source/ui/JavaTypeProvider.java Locally Modified (Based On 1.2) @@ -36,6 +36,7 @@ import org.netbeans.api.java.source.ClassIndex; import org.netbeans.api.java.source.ClasspathInfo; import org.netbeans.api.java.source.ElementHandle; +import org.netbeans.api.java.source.ui.TypeElementFinder; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectInformation; @@ -56,6 +57,8 @@ private static final ClassPath EMPTY_CLASSPATH = ClassPathSupport.createClassPath( new FileObject[0] ); private Set cache; private volatile boolean isCanceled = false; + private final TypeElementFinder.Customizer customizer; + private final ClasspathInfo cpInfo; public String name() { return "java"; // NOI18N @@ -75,8 +78,15 @@ } public JavaTypeProvider() { + this(null, null); } + // TODO: create some factory methods + public JavaTypeProvider(ClasspathInfo cpInfo, TypeElementFinder.Customizer customizer) { + this.cpInfo = cpInfo; + this.customizer = customizer; + } + // // This is essentially the code from OpenDeclAction // // TODO: Was OpenDeclAction used for anything else? // public void gotoType(TypeDescriptor type) { @@ -112,13 +122,16 @@ cp = gss = gsb = sfb = gtn = add = sort = 0; if (cache == null) { + Set sources = null; + + if (cpInfo == null) { // Sources time = System.currentTimeMillis(); ClassPath scp = RepositoryUpdater.getDefault().getScannedSources(); FileObject roots[] = scp.getRoots(); gss += System.currentTimeMillis() - time; FileObject root[] = new FileObject[1]; - Set sources = new HashSet( roots.length ); + sources = new HashSet( roots.length ); for (int i = 0; i < roots.length; i++ ) { root[0] = roots[i]; time = System.currentTimeMillis(); @@ -166,6 +179,54 @@ } } } + } else { // user provided classpath + + FileObject[] bootRoots = cpInfo.getClassPath(ClasspathInfo.PathKind.BOOT).getRoots(); + FileObject[] compileRoots = cpInfo.getClassPath(ClasspathInfo.PathKind.COMPILE).getRoots(); + FileObject[] sourceRoots = cpInfo.getClassPath(ClasspathInfo.PathKind.SOURCE).getRoots(); + sources = new HashSet(bootRoots.length + compileRoots.length + sourceRoots.length); + + // bootPath + for (int i = 0; i < bootRoots.length; i++ ) { + time = System.currentTimeMillis(); + ClasspathInfo ci = ClasspathInfo.create(ClassPathSupport.createClassPath(bootRoots[i]), EMPTY_CLASSPATH, EMPTY_CLASSPATH); + if ( isCanceled ) { + return null; + } + else { + sources.add( new CacheItem( bootRoots[i], ci, true ) ); + } + cp += System.currentTimeMillis() - time; + } + + // classPath + for (int i = 0; i < compileRoots.length; i++ ) { + time = System.currentTimeMillis(); + ClasspathInfo ci = ClasspathInfo.create(EMPTY_CLASSPATH, ClassPathSupport.createClassPath(compileRoots[i]), EMPTY_CLASSPATH); + if ( isCanceled ) { + return null; + } + else { + sources.add( new CacheItem( compileRoots[i], ci, true ) ); + } + cp += System.currentTimeMillis() - time; + } + + // sourcePath + for (int i = 0; i < sourceRoots.length; i++ ) { + time = System.currentTimeMillis(); + ClasspathInfo ci = ClasspathInfo.create(EMPTY_CLASSPATH, EMPTY_CLASSPATH, ClassPathSupport.createClassPath(sourceRoots[i])); + if ( isCanceled ) { + return null; + } + else { + sources.add( new CacheItem( sourceRoots[i], ci, false ) ); + } + cp += System.currentTimeMillis() - time; + } + + } + if ( !isCanceled ) { cache = sources; } @@ -191,7 +252,14 @@ default: textForQuery = text; } - Set> names = ci.classpathInfo.getClassIndex().getDeclaredTypes(textForQuery, nameKind, EnumSet.of( ci.isBinary ? ClassIndex.SearchScope.DEPENDENCIES : ClassIndex.SearchScope.SOURCE )); + + Set> names = null; + if (customizer != null) { + names = customizer.query(ci.classpathInfo, textForQuery, nameKind, EnumSet.of(ci.isBinary ? ClassIndex.SearchScope.DEPENDENCIES : ClassIndex.SearchScope.SOURCE)); + } else { + names = ci.classpathInfo.getClassIndex().getDeclaredTypes(textForQuery, nameKind, EnumSet.of( ci.isBinary ? ClassIndex.SearchScope.DEPENDENCIES : ClassIndex.SearchScope.SOURCE )); + } + if ( isCanceled ) { return null; }