# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /Users/samuel/Documents/Java/NetBeans/main-golden/java.editor/src # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: org/netbeans/modules/editor/java/ExcludeCompletion.java --- org/netbeans/modules/editor/java/ExcludeCompletion.java Base (BASE) +++ org/netbeans/modules/editor/java/ExcludeCompletion.java Locally New @@ -0,0 +1,142 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 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): + * + * Samuel Halliday + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ +package org.netbeans.modules.editor.java; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +/** + * A whitelist/blacklist of excluded classes and packages for the Java completer. + * Requested in RFE #125060. + * + * @author Samuel Halliday + */ +final class ExcludeCompletion { + + private final Collection exclude = new ArrayList(); + private final Collection include = new ArrayList(); + private final ReadWriteLock lock = new ReentrantReadWriteLock(); + + /** */ + public ExcludeCompletion() { + } + + /** + * @param fqn Fully Qualified Name + * @return + */ + public boolean isExcluded(final CharSequence fqn) { + //#122334: do not propose imports from the default package + if (fqn == null || fqn.length() == 0) { + return true; + } + + String s = fqn.toString(); + lock.readLock().lock(); + try { + if (!include.isEmpty()) { + for (String entry : include) { + if (entry.length() > fqn.length()) { + if (entry.startsWith(s)) { + return false; + } + } else if (s.startsWith(entry)) { + return false; + } + } + } + + if (!exclude.isEmpty()) { + for (String entry : exclude) { + if (entry.endsWith(".") && fqn.equals(entry.substring(0, entry.length() - 1))) { // NOI18N + // exclude packages names (no trailing fullstop) + return true; + } + if (entry.length() > fqn.length()) { + // fqn not long enough to filter yet + continue; + } + if (s.startsWith(entry)) { + return true; + } + } + } + + return false; + } finally { + lock.readLock().unlock(); + } + } + + /** + * @param blacklist comma separated list of fqns + */ + public void updateBlacklist(String blacklist) { + update(exclude, blacklist); + } + + /** + * @param whitelist comma separated list of fqns + */ + public void updateWhitelist(String whitelist) { + update(include, whitelist); + } + + private void update(Collection existing, String updated) { + lock.writeLock().lock(); + try { + existing.clear(); + if (updated == null || updated.length() == 0) { + return; + } + String[] entries = updated.split(","); //NOI18N + for (String entry : entries) { + if (entry != null && entry.length() != 0) { + existing.add(entry); + } + } + } finally { + lock.writeLock().unlock(); + } + } +} Index: org/netbeans/modules/editor/java/JavaCompletionProvider.java --- org/netbeans/modules/editor/java/JavaCompletionProvider.java Base (BASE) +++ org/netbeans/modules/editor/java/JavaCompletionProvider.java Locally Modified (Based On LOCAL) @@ -2606,15 +2606,18 @@ isOfKindAndType(asMemberOf(e, t, types), e, kinds, baseType, scope, trees, types) && tu.isAccessible(scope, e, t); case METHOD: - return startsWith(env, e.getSimpleName().toString(), prefix) && + String sn = e.getSimpleName().toString(); + return startsWith(env, sn, prefix) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e)) && isOfKindAndType(((ExecutableType)asMemberOf(e, t, types)).getReturnType(), e, kinds, baseType, scope, trees, types) && (isSuperCall && e.getModifiers().contains(PROTECTED) || tu.isAccessible(scope, e, isSuperCall && enclType != null ? enclType : t)) && - (!isStatic || e.getModifiers().contains(STATIC)); + (!isStatic || e.getModifiers().contains(STATIC)) && + !Utilities.isExcluded(Utilities.getElementName(e.getEnclosingElement(), true) + "." + sn); //NOI18N case CLASS: case ENUM: case INTERFACE: case ANNOTATION_TYPE: + System.err.println("FQN: " + Utilities.getElementName(e, true)); return startsWith(env, e.getSimpleName().toString(), prefix) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e)) && isOfKindAndType(e.asType(), e, kinds, baseType, scope, trees, types) && @@ -2730,7 +2733,7 @@ if (fqnPrefix == null) fqnPrefix = EMPTY; for (String pkgName : env.getController().getClasspathInfo().getClassIndex().getPackageNames(fqnPrefix, true,EnumSet.allOf(ClassIndex.SearchScope.class))) - if (pkgName.length() > 0) + if (!Utilities.isExcluded(pkgName)) results.add(JavaCompletionItem.createPackageItem(pkgName, anchorOffset, inPkgStmt)); } Index: org/netbeans/modules/editor/java/LazyTypeCompletionItem.java --- org/netbeans/modules/editor/java/LazyTypeCompletionItem.java Base (BASE) +++ org/netbeans/modules/editor/java/LazyTypeCompletionItem.java Locally Modified (Based On LOCAL) @@ -117,7 +117,7 @@ TypeElement e = handle.resolve(controller); Elements elements = controller.getElements(); if (e != null && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e)) && controller.getTrees().isAccessible(scope, e)) { - if (isOfKind(e, kinds) && (!isInDefaultPackage(e) || isInDefaultPackage(scope.getEnclosingClass()))) + if (isOfKind(e, kinds) && (!isInDefaultPackage(e) || isInDefaultPackage(scope.getEnclosingClass())) && !Utilities.isExcluded(e.getQualifiedName())) delegate = JavaCompletionItem.createTypeItem(e, (DeclaredType)e.asType(), substitutionOffset, true, controller.getElements().isDeprecated(e), insideNew, false); } } Index: org/netbeans/modules/editor/java/Utilities.java --- org/netbeans/modules/editor/java/Utilities.java Base (BASE) +++ org/netbeans/modules/editor/java/Utilities.java Locally Modified (Based On LOCAL) @@ -113,25 +113,34 @@ showDeprecatedMembers = preferences.getBoolean(SimpleValueNames.SHOW_DEPRECATED_MEMBERS, true); } if (settingName == null || CodeCompletionPanel.GUESS_METHOD_ARGUMENTS.equals(settingName)) { - guessMethodArguments = preferences.getBoolean(CodeCompletionPanel.GUESS_METHOD_ARGUMENTS, true); + guessMethodArguments = preferences.getBoolean(CodeCompletionPanel.GUESS_METHOD_ARGUMENTS, CodeCompletionPanel.GUESS_METHOD_ARGUMENTS_DEFAULT); } if (settingName == null || CodeCompletionPanel.JAVA_AUTO_POPUP_ON_IDENTIFIER_PART.equals(settingName)) { - autoPopupOnJavaIdentifierPart = preferences.getBoolean(CodeCompletionPanel.JAVA_AUTO_POPUP_ON_IDENTIFIER_PART, false); + autoPopupOnJavaIdentifierPart = preferences.getBoolean(CodeCompletionPanel.JAVA_AUTO_POPUP_ON_IDENTIFIER_PART, CodeCompletionPanel.JAVA_AUTO_POPUP_ON_IDENTIFIER_PART_DEFAULT); } if (settingName == null || CodeCompletionPanel.JAVA_AUTO_COMPLETION_TRIGGERS.equals(settingName)) { - javaCompletionAutoPopupTriggers = preferences.get(CodeCompletionPanel.JAVA_AUTO_COMPLETION_TRIGGERS, "."); //NOI18N + javaCompletionAutoPopupTriggers = preferences.get(CodeCompletionPanel.JAVA_AUTO_COMPLETION_TRIGGERS, CodeCompletionPanel.JAVA_AUTO_COMPLETION_TRIGGERS_DEFAULT); } if (settingName == null || CodeCompletionPanel.JAVA_COMPLETION_SELECTORS.equals(settingName)) { - javaCompletionSelectors = preferences.get(CodeCompletionPanel.JAVA_COMPLETION_SELECTORS, ".,;:([+-="); //NOI18N + javaCompletionSelectors = preferences.get(CodeCompletionPanel.JAVA_COMPLETION_SELECTORS, CodeCompletionPanel.JAVA_COMPLETION_SELECTORS_DEFAULT); } if (settingName == null || CodeCompletionPanel.JAVADOC_AUTO_COMPLETION_TRIGGERS.equals(settingName)) { - javadocCompletionAutoPopupTriggers = preferences.get(CodeCompletionPanel.JAVADOC_AUTO_COMPLETION_TRIGGERS, ".#@"); //NOI18N + javadocCompletionAutoPopupTriggers = preferences.get(CodeCompletionPanel.JAVADOC_AUTO_COMPLETION_TRIGGERS, CodeCompletionPanel.JAVADOC_AUTO_COMPLETION_TRIGGERS_DEFAULT); } + if (settingName == null || CodeCompletionPanel.JAVA_COMPLETION_BLACKLIST.equals(settingName)) { + String blacklist = preferences.get(CodeCompletionPanel.JAVA_COMPLETION_BLACKLIST, CodeCompletionPanel.JAVA_COMPLETION_BLACKLIST_DEFAULT); + excluder.updateBlacklist(blacklist); } + if (settingName == null || CodeCompletionPanel.JAVA_COMPLETION_WHITELIST.equals(settingName)) { + String whitelist = preferences.get(CodeCompletionPanel.JAVA_COMPLETION_WHITELIST, CodeCompletionPanel.JAVA_COMPLETION_WHITELIST_DEFAULT); + excluder.updateWhitelist(whitelist); + } + } }; private static String cachedPrefix = null; private static Pattern cachedPattern = null; + private static volatile ExcludeCompletion excluder = null; public static boolean startsWith(String theString, String prefix) { if (theString == null || theString.length() == 0 || ERROR.equals(theString)) @@ -215,9 +224,19 @@ return javadocCompletionAutoPopupTriggers; } + /** + * @param fqn Fully Qualified Name + * @return + */ + public static boolean isExcluded(CharSequence fqn){ + lazyInit(); + return excluder.isExcluded(fqn); + } + private static void lazyInit() { if (!inited) { inited = true; + excluder = new ExcludeCompletion(); preferences = MimeLookup.getLookup(JavaKit.JAVA_MIME_TYPE).lookup(Preferences.class); preferences.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, preferencesTracker, preferences)); preferencesTracker.preferenceChange(null); @@ -787,5 +806,4 @@ return found; } - } Index: org/netbeans/modules/java/editor/imports/ComputeImports.java --- org/netbeans/modules/java/editor/imports/ComputeImports.java Base (BASE) +++ org/netbeans/modules/java/editor/imports/ComputeImports.java Locally Modified (Based On LOCAL) @@ -72,6 +72,7 @@ import org.netbeans.api.java.source.ClassIndex.NameKind; import org.netbeans.api.java.source.ElementHandle; import org.netbeans.api.java.source.support.CancellableTreePathScanner; +import org.netbeans.modules.editor.java.Utilities; import org.netbeans.modules.java.editor.javadoc.JavadocImports; import org.openide.util.Union2; @@ -145,8 +146,8 @@ continue; } - //#122334: do not propose imports from the default package: - if (info.getElements().getPackageOf(te).getQualifiedName().length() != 0) { + CharSequence fqn = info.getElements().getPackageOf(te).getQualifiedName(); + if (!Utilities.isExcluded(fqn)){ classes.add(te); } } Index: org/netbeans/modules/java/editor/javadoc/JavadocCompletionQuery.java --- org/netbeans/modules/java/editor/javadoc/JavadocCompletionQuery.java Base (BASE) +++ org/netbeans/modules/java/editor/javadoc/JavadocCompletionQuery.java Locally Modified (Based On LOCAL) @@ -603,7 +603,7 @@ } for (String pkgName : jdctx.javac.getClasspathInfo().getClassIndex().getPackageNames(pkgPrefix, true, EnumSet.allOf(ClassIndex.SearchScope.class))) - if (pkgName.length() > 0) + if (!Utilities.isExcluded(pkgName)) items.add(JavaCompletionItem.createPackageItem(pkgName, substitutionOffset, false)); }