001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.gsfpath.api.queries;
042:
043: import org.netbeans.modules.gsfpath.spi.queries.AccessibilityQueryImplementation;
044: import org.openide.util.Lookup;
045: import org.openide.filesystems.FileObject;
046:
047: /**
048: * Indicates whether a Java package should be considered publicly accessible.
049: * <div class="nonnormative">
050: * <p>Suggested uses:</p>
051: * <ol>
052: * <li>Visually marking public and private packages as such.</li>
053: * <li>Editor code completion could refuse to include private packages from
054: * other compilation units.</li>
055: * <li>Javadoc editing tools (the suggestions provider and/or AutoComment) could
056: * treat missing or incomplete Javadoc in private packages as a minor error, or
057: * not an error.</li>
058: * </ol>
059: * <p>If the Java Project module is enabled, you may register an implementation
060: * to the lookup for a project rather than the default lookup.</p>
061: * </div>
062: * @see AccessibilityQueryImplementation
063: * @author Jesse Glick
064: * @since org.netbeans.modules.gsfpath.api/1 1.4
065: */
066: public class AccessibilityQuery {
067:
068: private static final Lookup.Result<? extends AccessibilityQueryImplementation> implementations = Lookup
069: .getDefault().lookupResult(
070: AccessibilityQueryImplementation.class);
071:
072: private AccessibilityQuery() {
073: }
074:
075: /**
076: * Check whether a given Java source package should be considered publicly
077: * accessible for use by other compilation units.
078: * If not, then even public classes in the package should be treated as
079: * effectively private by the IDE (though the Java compiler will not forbid
080: * you to access them).
081: * @param pkg a Java source package (must have a corresponding
082: * {@link org.netbeans.modules.gsfpath.api.classpath.ClassPath#SOURCE} root)
083: * @return true if the package is definitely intended for public access from
084: * other compilation units, false if it is definitely not, or null if
085: * this information is not known
086: */
087: public static Boolean isPubliclyAccessible(FileObject pkg) {
088: if (!pkg.isFolder()) {
089: throw new IllegalArgumentException("Not a folder: " + pkg); // NOI18N
090: }
091: for (AccessibilityQueryImplementation aqi : implementations
092: .allInstances()) {
093: Boolean b = aqi.isPubliclyAccessible(pkg);
094: if (b != null) {
095: return b;
096: }
097: }
098: return null;
099: }
100:
101: }
|