1 /* 2 * The contents of this file are subject to the terms of the Common Development 3 * and Distribution License (the License). You may not use this file except in 4 * compliance with the License. 5 * 6 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html 7 * or http://www.netbeans.org/cddl.txt. 8 * 9 * When distributing Covered Code, include this CDDL Header Notice in each file 10 * and include the License file at http://www.netbeans.org/cddl.txt. 11 * If applicable, add the following below the CDDL Header, with the fields 12 * enclosed by brackets [] replaced by your own identifying information: 13 * "Portions Copyrighted [year] [name of copyright owner]" 14 * 15 * The Original Software is NetBeans. The Initial Developer of the Original 16 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun 17 * Microsystems, Inc. All Rights Reserved. 18 */ 19 package org.netbeans.api.java.queries; 20 21 import org.netbeans.spi.java.queries.AccessibilityQueryImplementation; 22 import org.openide.util.Lookup; 23 import org.openide.filesystems.FileObject; 24 25 26 /** 27 * Indicates whether a Java package should be considered publicly accessible. 28 * <div class="nonnormative"> 29 * <p>Suggested uses:</p> 30 * <ol> 31 * <li>Visually marking public and private packages as such.</li> 32 * <li>Editor code completion could refuse to include private packages from 33 * other compilation units.</li> 34 * <li>Javadoc editing tools (the suggestions provider and/or AutoComment) could 35 * treat missing or incomplete Javadoc in private packages as a minor error, or 36 * not an error.</li> 37 * </ol> 38 * <p>If the Java Project module is enabled, you may register an implementation 39 * to the lookup for a project rather than the default lookup.</p> 40 * </div> 41 * @see AccessibilityQueryImplementation 42 * @author Jesse Glick 43 * @since org.netbeans.api.java/1 1.4 44 */ 45 public class AccessibilityQuery { 46 47 private static final Lookup.Result<? extends AccessibilityQueryImplementation> implementations = 48 Lookup.getDefault().lookupResult(AccessibilityQueryImplementation.class); 49 50 private AccessibilityQuery() {} 51 52 /** 53 * Check whether a given Java source package should be considered publicly 54 * accessible for use by other compilation units. 55 * If not, then even public classes in the package should be treated as 56 * effectively private by the IDE (though the Java compiler will not forbid 57 * you to access them). 58 * @param pkg a Java source package (must have a corresponding 59 * {@link org.netbeans.api.java.classpath.ClassPath#SOURCE} root) 60 * @return true if the package is definitely intended for public access from 61 * other compilation units, false if it is definitely not, or null if 62 * this information is not known 63 */ 64 public static Boolean isPubliclyAccessible(FileObject pkg) { 65 if (!pkg.isFolder()) { 66 throw new IllegalArgumentException("Not a folder: " + pkg); // NOI18N 67 } 68 for ( AccessibilityQueryImplementation aqi : implementations.allInstances()) { 69 Boolean b = aqi.isPubliclyAccessible(pkg); 70 if (b != null) { 71 return b; 72 } 73 } 74 return null; 75 } 76 77 } 78